Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif '402 Client Error: Payment Required' in str(e):
log.error('Paid subscription required for this channel.')
log.info('If paid subscription exist, use --zattoo-purge'
'-credentials to start a new session.')
elif '403 Client Error' in str(e):
log.debug('Force session reset for watch_url')
self.reset_session()
else:
log.error(str(e))
return
data = self.session.http.json(res)
log.debug('Found data for {0}'.format(stream_type))
if data['success'] and stream_type in ['hls', 'hls5']:
for url in data['stream']['watch_urls']:
for s in HLSStream.parse_variant_playlist(
self.session, url['url']).items():
yield s
elif data['success'] and stream_type == 'dash':
for url in data['stream']['watch_urls']:
for s in DASHStream.parse_manifest(
self.session, url['url']).items():
yield s
http_url = _rtmp_re.search(res.text).group(1)
http_url = http_url.replace("http:", "https:")
yield "live", HTTPStream(self.session, http_url)
if 'pull-rtmp' in http_url:
url = http_url.replace("https:", "rtmp:").replace(".flv", "")
stream = RTMPStream(self.session, {
"rtmp": url,
"live": True
})
yield "live", stream
if 'wansu-' in http_url:
url = http_url.replace(".flv", "/playlist.m3u8")
for stream in HLSStream.parse_variant_playlist(self.session, url).items():
yield stream
else:
url = http_url.replace("live-hdl", "live-hls").replace(".flv", ".m3u8")
yield "live", HLSStream(self.session, url)
# the media.stream_data field is required, no stream data is returned otherwise
info = api.get_info(media_id, fields=["media.stream_data"], schema=_media_schema)
except CrunchyrollAPIError as err:
raise PluginError(u"Media lookup error: {0}".format(err.msg))
if not info:
return
streams = {}
# The adaptive quality stream sometimes a subset of all the other streams listed, ultra is no included
has_adaptive = any([s[u"quality"] == u"adaptive" for s in info[u"streams"]])
if has_adaptive:
self.logger.debug(u"Loading streams from adaptive playlist")
for stream in filter(lambda x: x[u"quality"] == u"adaptive", info[u"streams"]):
for q, s in HLSStream.parse_variant_playlist(self.session, stream[u"url"]).items():
# rename the bitrates to low, mid, or high. ultra doesn't seem to appear in the adaptive streams
name = STREAM_NAMES.get(q, q)
streams[name] = s
# If there is no adaptive quality stream then parse each individual result
for stream in info[u"streams"]:
if stream[u"quality"] != u"adaptive":
# the video_encode_id indicates that the stream is not a variant playlist
if u"video_encode_id" in stream:
streams[stream[u"quality"]] = HLSStream(self.session, stream[u"url"])
else:
# otherwise the stream url is actually a list of stream qualities
for q, s in HLSStream.parse_variant_playlist(self.session, stream[u"url"]).items():
# rename the bitrates to low, mid, or high. ultra doesn't seem to appear in the adaptive streams
name = STREAM_NAMES.get(q, q)
streams[name] = s
def _get_streams(self):
api_urls = self.session.http.get(self.url, schema=self.channel_id_schema)
for api_url in api_urls:
log.debug("API URL: {0}".format(api_url))
for source in self.session.http.get(api_url, schema=self.stream_schema):
log.debug("Stream source: {0} ({1})".format(source['src'], source.get("type", "n/a")))
if "type" not in source or source["type"] == "application/vnd.apple.mpegurl":
for s in HLSStream.parse_variant_playlist(self.session, source["src"]).items():
yield s
elif source["type"] == "application/dash+xml":
for s in DASHStream.parse_manifest(self.session, source["src"]).items():
yield s
def _get_streams(self):
headers = {
"User-Agent": useragents.FIREFOX,
"Referer": self.url
}
stream_url = self.stream_schema.validate(self.session.http.get(self.url).text)
if stream_url:
stream_url = list(set(stream_url))
for url in stream_url:
self.logger.debug("URL={0}".format(url))
for s in HLSStream.parse_variant_playlist(self.session, url, headers=headers).items():
yield s
"""Plugin for swedish news paper Aftonbladet's streaming service."""
import re
from streamlink.plugin import Plugin
from streamlink.plugin.api import validate
from streamlink.stream import HDSStream, HLSStream
PLAYLIST_URL_FORMAT = "http://{address}/{path}/{filename}"
STREAM_TYPES = {
"hds": HDSStream.parse_manifest,
"hls": HLSStream.parse_variant_playlist
}
STREAM_FORMATS = ("m3u8", "f4m")
VIDEO_INFO_URL = "http://aftonbladet-play-static-ext.cdn.drvideo.aptoma.no/actions/video"
METADATA_URL = "http://aftonbladet-play-metadata.cdn.drvideo.aptoma.no/video/{0}.json"
_embed_re = re.compile(r"
def _get_hls_streams(self, info):
return HLSStream.parse_variant_playlist(self.session, info["_stream"]).items()
index = int(match.group('video_index'))
if not playlist:
return
videos = self._video_schema.validate(playlist[index])
for video in videos:
video_url = video['file']
# Ignore non-supported MSS streams
if 'isml/Manifest' in video_url:
continue
try:
if '.m3u8' in video_url:
for stream in HLSStream.parse_variant_playlist(self.session, video_url).items():
yield stream
elif '.mp4' in video_url:
match = self._mp4_bitrate_re.match(video_url)
if match is not None:
bitrate = '%sk' % match.group('bitrate')
else:
bitrate = 'vod'
yield bitrate, HTTPStream(self.session, video_url)
except IOError as err:
if '403 Client Error' in str(err):
self.logger.error('Failed to access stream, may be due to geo-restriction')
raise
def _get_streams(self):
# get the HLS json from the same sub domain as the main url, defaulting to www
sdomain = _url_re.match(self.url).group(1) or "www"
res = self.session.http.get(API_URL.format(sdomain))
stream_url = self.session.http.json(res)['main']['wstrm']
return HLSStream.parse_variant_playlist(self.session, stream_url)
if not stream_source_info:
return
performer = stream_source_info['performerData']['username']
print (colored("\n => Performer => {} <=", "yellow", "on_blue")).format(performer)
urlnoproto = stream_source_info['localData']['videoServerUrl']
urlnoproto = update_scheme('https://', urlnoproto)
hls_url = '{0}/hls/stream_{1}/playlist.m3u8'.format(urlnoproto, performer)
ls_url = re.sub('https', 'hlsvariant://https', hls_url)
server = re.sub('https://', '', urlnoproto)
print (colored("\n => Server => {} <=", "yellow", "on_blue")).format(server)
if hls_url:
try:
for s in HLSStream.parse_variant_playlist(self.session, hls_url, headers=headers).items():
while True:
try:
print
mode = int(raw_input(colored(" => Mode => YTDL-TS(5) YTDL-FLV(4) LS(3) FFMPEG(2) FFPLAY(1) RTMP(0) => ", "yellow", "on_blue")))
break
except ValueError:
print(colored("\n => Input must be a number <=", "yellow", "on_red"))
if mode == 0:
mod = 'RTMP'
if mode == 1:
mod = 'FFPLAY'
if mode == 2:
mod = 'FFMPEG'
if mode == 3:
mod = 'LS'
if mode == 4: