本文整理汇总了Python中streamlink.stream.HDSStream.parse_manifest方法的典型用法代码示例。如果您正苦于以下问题:Python HDSStream.parse_manifest方法的具体用法?Python HDSStream.parse_manifest怎么用?Python HDSStream.parse_manifest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类streamlink.stream.HDSStream
的用法示例。
在下文中一共展示了HDSStream.parse_manifest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_streams(self):
match = self._url_re.match(self.url)
channel = match.group('channel')
res = self.session.http.get(self.FORMATS_URL.format(channel))
streams = self.session.http.json(res, schema=self._formats_schema)['streams']
if streams == []:
self.logger.error('Channel may be geo-restricted, not directly provided by PlayTV or not freely available')
return
for language in streams:
for protocol, bitrates in list(streams[language].items()):
# - Ignore non-supported protocols (RTSP, DASH)
# - Ignore deprecated Flash (RTMPE/HDS) streams (PlayTV doesn't provide anymore a Flash player)
if protocol in ['rtsp', 'flash', 'dash', 'hds']:
continue
for bitrate in bitrates['bitrates']:
if bitrate['value'] == 0:
continue
api_url = self.API_URL.format(channel, protocol, language, bitrate['value'])
res = self.session.http.get(api_url)
video_url = self.session.http.json(res, schema=self._api_schema)['url']
bs = '{0}k'.format(bitrate['value'])
if protocol == 'hls':
for _, stream in HLSStream.parse_variant_playlist(self.session, video_url).items():
yield bs, stream
elif protocol == 'hds':
for _, stream in HDSStream.parse_manifest(self.session, video_url).items():
yield bs, stream
示例2: _get_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_streams(self):
match = _url_re.match(self.url)
video_id = match.group("video_id")
res = http.get(ASSET_URL.format(video_id))
assets = http.xml(res, schema=_asset_schema)
streams = {}
for asset in assets:
base = asset["base"]
url = asset["url"]
if urlparse(url).path.endswith(".f4m"):
streams.update(
HDSStream.parse_manifest(self.session, url, pvswf=SWF_URL)
)
elif base.startswith("rtmp"):
name = "{0}k".format(asset["bitrate"])
params = {
"rtmp": asset["base"],
"playpath": url,
"live": True
}
streams[name] = RTMPStream(self.session, params)
return streams
示例3: _get_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_streams(self):
# Discover root
match = _url_re.search(self.url)
root = match.group(1)
# Download main URL
res = http.get(self.url)
# Find playlist
match = _playlist_re.search(res.text)
playlist_url = root + match.group(1) + "d"
# Download playlist
res = http.get(playlist_url)
# Find manifest
match = _manifest_re.search(res.text)
manifest_url = match.group(1)
# Find SWF
match = _swf_re.search(res.text)
swf_url = match.group(1)
streams = {}
streams.update(
HDSStream.parse_manifest(self.session, manifest_url, pvswf=swf_url)
)
return streams
示例4: _get_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_streams(self):
url, params = parse_url_params(self.url)
urlnoproto = self._url_re.match(url).group(2)
urlnoproto = update_scheme("http://", urlnoproto)
return HDSStream.parse_manifest(self.session, urlnoproto, **params)
示例5: _get_vod_stream
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_vod_stream(self):
vod_url = self.url
if vod_url.endswith('/'):
vod_url = vod_url[:-1]
json_url = '{0}.securevideo.json'.format(vod_url)
res = http.get(json_url)
match = _json_re.search(res.text)
if not match:
return
data = parse_json(match.group(1))
res = http.get(API_VOD.format(data['clientid'], data['mzid']))
data = http.json(res, schema=_stream_schema)
for d in data['targetUrls']:
if d['type'] == 'HDS':
hds_url = d['url']
for s in HDSStream.parse_manifest(self.session, hds_url).items():
yield s
if d['type'] == 'HLS':
hls_url = d['url']
for s in HLSStream.parse_variant_playlist(self.session, hls_url).items():
yield s
示例6: mediaselector
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def mediaselector(self, vpid):
urls = defaultdict(set)
for platform in self.platforms:
url = self.api_url.format(vpid=vpid, vpid_hash=self._hash_vpid(vpid),
platform=platform)
log.debug("Info API request: {0}", url)
medias = self.session.http.get(url, schema=self.mediaselector_schema)
for media in medias:
for connection in media["connection"]:
urls[connection.get("transferFormat")].add(connection["href"])
for stream_type, urls in urls.items():
log.debug("{0} {1} streams", len(urls), stream_type)
for url in list(urls):
try:
if stream_type == "hds":
for s in HDSStream.parse_manifest(self.session,
url).items():
yield s
if stream_type == "hls":
for s in HLSStream.parse_variant_playlist(self.session,
url).items():
yield s
if stream_type == "dash":
for s in DASHStream.parse_manifest(self.session,
url).items():
yield s
log.debug(" OK: {0}", url)
except:
log.debug(" FAIL: {0}", url)
示例7: _get_vod_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [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
示例8: _get_live_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_live_streams(self, params, swf_url):
for key, quality in QUALITY_MAP.items():
key_url = "{0}URL".format(key)
url = params.get(key_url)
if not url:
continue
try:
res = http.get(url, exception=IOError)
except IOError:
continue
if quality == "hds":
streams = HDSStream.parse_manifest(self.session, res.url)
for name, stream in streams.items():
if key == "source":
name += "+"
yield name, stream
elif res.text.startswith("rtmp"):
match = _rtmp_re.match(res.text)
if not match:
continue
stream = RTMPStream(self.session, {
"rtmp": match.group("host"),
"app": match.group("app"),
"playpath": match.group("playpath"),
"swfVfy": swf_url,
"live": True
})
yield quality, stream
示例9: _get_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_streams(self):
res = self.session.http.get(self.url)
match = _player_js.search(res.text)
if match:
player_js = match.group(0)
self.logger.info("Found player js {0}", player_js)
else:
self.logger.info("Didn't find player js. Probably this page doesn't contain a video")
return
res = self.session.http.get(player_js)
jsonp_start = res.text.find('(') + 1
jsonp_end = res.text.rfind(')')
if jsonp_start <= 0 or jsonp_end <= 0:
self.logger.info("Couldn't extract json metadata from player.js: {0}", player_js)
return
json_s = res.text[jsonp_start:jsonp_end]
stream_metadata = json.loads(json_s)
hds_url = stream_metadata['mediaResource']['dflt']['videoURL']
hds_url = update_scheme(self.url, hds_url)
return HDSStream.parse_manifest(self.session, hds_url).items()
示例10: _get_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_streams(self):
# Get video ID and channel from URL
match = self._url_re.match(self.url)
video_id = match.group('video_id')
if video_id is None:
# Retrieve URL page and search for video ID
res = http.get(self.url)
match = self._video_id_re.search(res.text)
if match is None:
return
video_id = match.group('video_id')
res = http.get(self.API_URL.format(video_id))
videos = http.json(res, schema=self._api_schema)
parsed = []
headers = {'User-Agent': self._user_agent}
# Some videos may be also available on Dailymotion (especially on CNews)
if videos['ID_DM'] != '':
for stream in self.session.streams('https://www.dailymotion.com/video/' + videos['ID_DM']).items():
yield stream
for quality, video_url in list(videos['MEDIA']['VIDEOS'].items()):
# Ignore empty URLs
if video_url == '':
continue
# Ignore duplicate video URLs
if video_url in parsed:
continue
parsed.append(video_url)
try:
# HDS streams don't seem to work for live videos
if '.f4m' in video_url and 'LIVE' not in videos['TYPE']:
for stream in HDSStream.parse_manifest(self.session,
video_url,
params={'hdcore': self.HDCORE_VERSION},
headers=headers).items():
yield stream
elif '.m3u8' in video_url:
for stream in HLSStream.parse_variant_playlist(self.session,
video_url,
headers=headers).items():
yield stream
elif '.mp4' in video_url:
# Get bitrate from video filename
match = self._mp4_bitrate_re.match(video_url)
if match is not None:
bitrate = match.group('bitrate')
else:
bitrate = quality
yield bitrate, HTTPStream(self.session,
video_url,
params={'secret': self.SECRET},
headers=headers)
except IOError as err:
if '403 Client Error' in str(err):
self.logger.error('Failed to access stream, may be due to geo-restriction')
示例11: _get_smil_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_smil_streams(self, info):
res = http.get(info["_stream"])
smil = http.xml(res, "SMIL config", schema=_smil_schema)
for video in smil["videos"]:
url = "{0}/{1}{2}".format(smil["base"], video, HDCORE_PARAMETER)
streams = HDSStream.parse_manifest(self.session, url, pvswf=SWF_URL, is_akamai=smil["cdn"] == "akamai")
for stream in streams.items():
yield stream
示例12: _get_hds_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_hds_streams(self, channel):
channel = self.hds_channel_remap.get(channel, "{0}live".format(channel))
manifest_url = http.get(self.api_url.format(channel),
params={"getURL": 1},
headers={"User-Agent": useragents.FIREFOX}).text
for s in HDSStream.parse_manifest(self.session,
manifest_url,
pvswf=self.swf_url,
headers={"User-Agent": useragents.FIREFOX}).items():
yield s
示例13: _get_smil_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_smil_streams(self, info):
res = http.get(info["_stream"])
smil = http.xml(res, "SMIL config", schema=_smil_schema)
for video in smil["videos"]:
url = "{0}/{1}{2}".format(smil["base"], video, HDCORE_PARAMETER)
streams = HDSStream.parse_manifest(self.session, url, pvswf=SWF_URL)
# TODO: Replace with "yield from" when dropping Python 2.
for stream in streams.items():
yield stream
示例14: mediaselector
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def mediaselector(self, vpid):
for platform in self.platforms:
url = self.api_url.format(vpid=vpid, vpid_hash=self._hash_vpid(vpid), platform=platform)
self.logger.debug("Info API request: {0}", url)
stream_urls = http.get(url, schema=self.mediaselector_schema)
for media in stream_urls:
for connection in media["connection"]:
if connection.get("transferFormat") == "hds":
for s in HDSStream.parse_manifest(self.session, connection["href"]).items():
yield s
if connection.get("transferFormat") == "hls":
for s in HLSStream.parse_variant_playlist(self.session, connection["href"]).items():
yield s
示例15: _get_streams
# 需要导入模块: from streamlink.stream import HDSStream [as 别名]
# 或者: from streamlink.stream.HDSStream import parse_manifest [as 别名]
def _get_streams(self):
res = http.get(API_URL)
data = http.json(res, schema=_schema)
streams = {}
for livestreams in data["live-streams"]:
for stream in livestreams["streams"]:
url = stream["streamUrl"]
for name, stream in HDSStream.parse_manifest(self.session, url).items():
if name.endswith("k"):
streams[name] = stream
return streams