本文整理汇总了Python中streamlink.stream.HLSStream.parse_variant_playlist方法的典型用法代码示例。如果您正苦于以下问题:Python HLSStream.parse_variant_playlist方法的具体用法?Python HLSStream.parse_variant_playlist怎么用?Python HLSStream.parse_variant_playlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类streamlink.stream.HLSStream
的用法示例。
在下文中一共展示了HLSStream.parse_variant_playlist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
stream_type = self._url_re.match(self.url).group("type")
hls_re = re.compile(r"""["'](?P<url>[^"']+\.m3u8[^"']*?)["']""")
headers = {
"Origin": "https://www.metube.id",
"User-Agent": useragents.FIREFOX
}
res = self.session.http.get(self.url)
match = hls_re.search(res.text)
if not match:
return
stream_url = match.group("url")
if stream_type == "live":
return HLSStream.parse_variant_playlist(self.session, stream_url,
headers=headers)
else:
streams = {}
for quality, stream in HLSStream.parse_variant_playlist(
self.session,
stream_url,
headers=headers).items():
name = self._VOD_STREAM_NAMES.get(quality, quality)
streams[name] = stream
return streams
示例2: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
api = self._create_api()
match = _url_re.match(self.url)
media_id = int(match.group("media_id"))
try:
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
# The adaptive quality stream contains a superset of all the other streams listeed
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"]):
return HLSStream.parse_variant_playlist(self.session, stream["url"])
else:
streams = {}
# If there is no adaptive quality stream then parse each individual result
for stream in info[u"streams"]:
# 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
streams.update(HLSStream.parse_variant_playlist(self.session, stream[u"url"]))
return streams
示例3: _get_hls_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_hls_streams(self, type="live"):
self._authenticate()
if self._check_for_host() and self.options.get("disable_hosting"):
self.logger.info("hosting was disabled by command line option")
return {}
else:
self.logger.info("switching to {}", self.channel)
sig, token = self._access_token(type)
if type == "live":
url = self.usher.channel(self.channel, sig=sig, token=token)
elif type == "video":
url = self.usher.video(self.video_id, nauthsig=sig, nauth=token)
try:
streams = HLSStream.parse_variant_playlist(self.session, url)
except IOError as err:
err = str(err)
if "404 Client Error" in err or "Failed to parse playlist" in err:
return
else:
raise PluginError(err)
try:
token = parse_json(token, schema=_token_schema)
for name in token["restricted_bitrates"]:
if name not in streams:
self.logger.warning("The quality '{0}' is not available "
"since it requires a subscription.",
name)
except PluginError:
pass
return streams
示例4: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
match = _url_re.match(self.url)
res = http.get(STREAM_INFO_URL,
params=match.groupdict(),
acceptable_status=STATUS_UNAVAILABLE)
if res.status_code in STATUS_UNAVAILABLE:
return
data = http.json(res, schema=_stream_schema)
if data.get("hls_url"):
hls_url = data["hls_url"]
hls_name = "live"
elif data.get("replay_url"):
self.logger.info("Live Stream ended, using replay instead")
hls_url = data["replay_url"]
hls_name = "replay"
else:
raise NoStreamsError(self.url)
streams = HLSStream.parse_variant_playlist(self.session, hls_url)
if not streams:
return {hls_name: HLSStream(self.session, hls_url)}
else:
return streams
示例5: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
match = _url_re.match(self.url)
channel = match.group("channel")
self.session.http.headers.update({'User-Agent': useragents.CHROME})
payload = '{"liveStreamID": "%s"}' % (channel)
res = self.session.http.post(API_URL, data=payload)
status = _status_re.search(res.text)
if not status:
self.logger.info("Stream currently unavailable.")
return
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)
示例6: _get_vod_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_vod_streams(self, params):
manifest_url = params.get("autoURL")
if not manifest_url:
return
res = http.get(manifest_url)
if res.headers.get("Content-Type") == "application/f4m+xml":
streams = HDSStream.parse_manifest(self.session, res.url)
# TODO: Replace with "yield from" when dropping Python 2.
for __ in streams.items():
yield __
elif res.headers.get("Content-Type") == "application/vnd.apple.mpegurl":
streams = HLSStream.parse_variant_playlist(self.session, res.url)
# TODO: Replace with "yield from" when dropping Python 2.
for __ in streams.items():
yield __
else:
manifest = http.json(res, schema=_vod_manifest_schema)
for params in manifest["alternates"]:
name = "{0}p".format(params["height"])
stream = self._create_flv_playlist(params["template"])
yield name, stream
failovers = params.get("failover", [])
for failover in failovers:
stream = self._create_flv_playlist(failover)
yield name, stream
示例7: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
if _stream_url_re.match(self.url):
mode = MODE_STREAM
else:
mode = MODE_VOD
res = http.get(self.url)
match = _json_re.search(res.text)
if match:
data = json.loads(_json_re.search(res.text).group('json').replace('"', '"'))
else:
raise PluginError("Could not extract JSON metadata")
streams = {}
try:
if mode == MODE_STREAM:
sources = data['playlist']['videos'][0]['sources']
elif mode == MODE_VOD:
sources = data['selected_video']['sources']
except (KeyError, IndexError):
raise PluginError("Could not extract sources")
for source in sources:
try:
if source['delivery'] != 'hls':
continue
url = source['src'].replace(r'\/', '/')
except KeyError:
continue
stream = HLSStream.parse_variant_playlist(self.session, url)
# work around broken HTTP connection persistence by acquiring a new connection
http.close()
streams.update(stream)
return streams
示例8: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
user = self.login(self.options.get("email"), self.options.get("password"))
if user:
self.logger.debug("Logged in to Schoolism as {0}", user)
res = http.get(self.url, headers={"User-Agent": useragents.SAFARI_8})
lesson_playlist = self.playlist_schema.validate(res.text)
part = self.options.get("part")
self.logger.info("Attempting to play lesson Part {0}", part)
found = False
# make request to key-time api, to get key specific headers
res = http.get(self.key_time_url, headers={"User-Agent": useragents.SAFARI_8})
for i, video in enumerate(lesson_playlist, 1):
if video["sources"] and i == part:
found = True
for source in video["sources"]:
for s in HLSStream.parse_variant_playlist(self.session,
source["src"],
headers={"User-Agent": useragents.SAFARI_8,
"Referer": self.url}).items():
yield s
if not found:
self.logger.error("Could not find lesson Part {0}", part)
示例9: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
match = _url_re.match(self.url)
channel = match.group("channel")
channel = channel.replace("_", "-")
playlist_url = PLAYLIST_URL.format(channel)
return HLSStream.parse_variant_playlist(self.session, playlist_url, check_streams=True)
示例10: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
channel = self.url_re.match(self.url).group(1)
res = http.get(self.api_url.format(channel))
data = http.json(res, schema=self.api_schema)
return HLSStream.parse_variant_playlist(self.session, data["channel_stream_url"])
示例11: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
# get the HLS xml 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.xml(res, schema=_schema)
return HLSStream.parse_variant_playlist(self.session, stream_url)
示例12: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
if self.is_live:
self.logger.debug("Loading live stream for {0}...", self.channel)
res = self.session.http.get(self.live_api_url, data={"r": random.randint(1, 100000)})
live_data = self.session.http.json(res)
# all the streams are equal for each type, so pick a random one
hls_streams = live_data.get("hls")
if hls_streams:
url = random.choice(hls_streams)
url = url + '&' + urlencode(self.hls_session()) # TODO: use update_qsd
for s in HLSStream.parse_variant_playlist(self.session, url, name_fmt="{pixels}_{bitrate}").items():
yield s
mpd_streams = live_data.get("mpd")
if mpd_streams:
url = random.choice(mpd_streams)
for s in DASHStream.parse_manifest(self.session, url).items():
yield s
elif self.channel == "1tv":
self.logger.debug("Attempting to find VOD stream...", self.channel)
vod_data = self.vod_data()
if vod_data:
self.logger.info(u"Found VOD: {0}".format(vod_data[0]['title']))
for stream in vod_data[0]['mbr']:
yield stream['name'], HTTPStream(self.session, update_scheme(self.url, stream['src']))
示例13: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
mdata = self._get_movie_data()
if mdata:
log.debug("Found video: {0} ({1})".format(mdata["title"], mdata["id"]))
if mdata["media"]["url"]:
for s in HLSStream.parse_variant_playlist(self.session, mdata["media"]["url"]).items():
yield s
elif self.get_option("email") and self.get_option("password"):
if self.login(self.get_option("email"), self.get_option("password")):
details = self._get_details(mdata["id"])
if details:
for item in details["items"]:
for s in HLSStream.parse_variant_playlist(self.session, item["media"]["url"]).items():
yield s
else:
log.error("You must login to access this stream")
示例14: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
if self.get_option("email") and self.get_option("password"):
if not self.authenticate(self.get_option("email"), self.get_option("password")):
self.logger.warning("Failed to login as {0}".format(self.get_option("email")))
# find the list of channels from the html in the page
self.url = self.url.replace("https", "http") # https redirects to http
res = http.get(self.url)
if "enter your postcode" in res.text:
self.logger.info("Setting your postcode to: {0}. "
"This can be changed in the settings on tvplayer.com", self.dummy_postcode)
res = http.post(self.update_url,
data=dict(postcode=self.dummy_postcode),
params=dict(return_url=self.url))
stream_attrs = self._get_stream_attrs(res)
if stream_attrs:
stream_data = self._get_stream_data(**stream_attrs)
if stream_data:
if stream_data.get("drmToken"):
self.logger.error("This stream is protected by DRM can cannot be played")
return
else:
return HLSStream.parse_variant_playlist(self.session, stream_data["stream"])
else:
if "need to login" in res.text:
self.logger.error(
"You need to login using --tvplayer-email/--tvplayer-password to view this stream")
示例15: _get_streams
# 需要导入模块: from streamlink.stream import HLSStream [as 别名]
# 或者: from streamlink.stream.HLSStream import parse_variant_playlist [as 别名]
def _get_streams(self):
res = self.session.http.get(self.url, headers={'User-Agent': useragents.CHROME})
video_search = res.text
video_search = video_search[video_search.index('{"top":{"view":"PlayerContainer","model":{'):]
video_search = video_search[: video_search.index('}]}}') + 4] + "}"
video_url_found_hls = ""
video_url_found_http = ""
json_video_search = parse_json(video_search)
json_video_search_sources = json_video_search["top"]["model"]["videos"][0]["sources"]
self.logger.debug('Video ID found: {0}', json_video_search["top"]["model"]["id"])
for current_video_source in json_video_search_sources:
if "HLS" in current_video_source["type"]:
video_url_found_hls = "http://telefe.com" + current_video_source["url"]
self.logger.debug("HLS content available")
if "HTTP" in current_video_source["type"]:
video_url_found_http = "http://telefe.com" + current_video_source["url"]
self.logger.debug("HTTP content available")
self.session.http.headers = {'Referer': self.url,
'User-Agent': useragents.CHROME,
'X-Requested-With': 'ShockwaveFlash/25.0.0.148'}
if video_url_found_hls:
hls_streams = HLSStream.parse_variant_playlist(self.session, video_url_found_hls)
for s in hls_streams.items():
yield s
if video_url_found_http:
yield "http", HTTPStream(self.session, video_url_found_http)