mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-11-13 21:15:15 +00:00
@@ -6,15 +6,15 @@ from ..utils import (
|
|||||||
OnDemandPagedList,
|
OnDemandPagedList,
|
||||||
clean_html,
|
clean_html,
|
||||||
determine_ext,
|
determine_ext,
|
||||||
|
float_or_none,
|
||||||
format_field,
|
format_field,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
join_nonempty,
|
join_nonempty,
|
||||||
parse_codecs,
|
|
||||||
parse_iso8601,
|
parse_iso8601,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
urljoin,
|
urljoin,
|
||||||
)
|
)
|
||||||
from ..utils.traversal import traverse_obj
|
from ..utils.traversal import require, traverse_obj
|
||||||
|
|
||||||
|
|
||||||
class FloatplaneBaseIE(InfoExtractor):
|
class FloatplaneBaseIE(InfoExtractor):
|
||||||
@@ -50,37 +50,31 @@ class FloatplaneBaseIE(InfoExtractor):
|
|||||||
media_id = media['id']
|
media_id = media['id']
|
||||||
media_typ = media.get('type') or 'video'
|
media_typ = media.get('type') or 'video'
|
||||||
|
|
||||||
metadata = self._download_json(
|
|
||||||
f'{self._BASE_URL}/api/v3/content/{media_typ}', media_id, query={'id': media_id},
|
|
||||||
note=f'Downloading {media_typ} metadata', impersonate=self._IMPERSONATE_TARGET)
|
|
||||||
|
|
||||||
stream = self._download_json(
|
stream = self._download_json(
|
||||||
f'{self._BASE_URL}/api/v2/cdn/delivery', media_id, query={
|
f'{self._BASE_URL}/api/v3/delivery/info', media_id,
|
||||||
'type': 'vod' if media_typ == 'video' else 'aod',
|
query={'scenario': 'onDemand', 'entityId': media_id},
|
||||||
'guid': metadata['guid'],
|
note=f'Downloading {media_typ} stream data',
|
||||||
}, note=f'Downloading {media_typ} stream data',
|
|
||||||
impersonate=self._IMPERSONATE_TARGET)
|
impersonate=self._IMPERSONATE_TARGET)
|
||||||
|
|
||||||
path_template = traverse_obj(stream, ('resource', 'uri', {str}))
|
metadata = self._download_json(
|
||||||
|
f'{self._BASE_URL}/api/v3/content/{media_typ}', media_id,
|
||||||
|
f'Downloading {media_typ} metadata', query={'id': media_id},
|
||||||
|
fatal=False, impersonate=self._IMPERSONATE_TARGET)
|
||||||
|
|
||||||
def format_path(params):
|
cdn_base_url = traverse_obj(stream, (
|
||||||
path = path_template
|
'groups', 0, 'origins', ..., 'url', {url_or_none}, any, {require('cdn base url')}))
|
||||||
for i, val in (params or {}).items():
|
|
||||||
path = path.replace(f'{{qualityLevelParams.{i}}}', val)
|
|
||||||
return path
|
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for quality in traverse_obj(stream, ('resource', 'data', 'qualityLevels', ...)):
|
for variant in traverse_obj(stream, ('groups', 0, 'variants', lambda _, v: v['url'])):
|
||||||
url = urljoin(stream['cdn'], format_path(traverse_obj(
|
format_url = urljoin(cdn_base_url, variant['url'])
|
||||||
stream, ('resource', 'data', 'qualityLevelParams', quality['name'], {dict}))))
|
format_id = traverse_obj(variant, ('name', {str}))
|
||||||
format_id = traverse_obj(quality, ('name', {str}))
|
|
||||||
hls_aes = {}
|
hls_aes = {}
|
||||||
m3u8_data = None
|
m3u8_data = None
|
||||||
|
|
||||||
# If we need impersonation for the API, then we need it for HLS keys too: extract in advance
|
# If we need impersonation for the API, then we need it for HLS keys too: extract in advance
|
||||||
if self._IMPERSONATE_TARGET is not None:
|
if self._IMPERSONATE_TARGET is not None:
|
||||||
m3u8_data = self._download_webpage(
|
m3u8_data = self._download_webpage(
|
||||||
url, media_id, fatal=False, impersonate=self._IMPERSONATE_TARGET, headers=self._HEADERS,
|
format_url, media_id, fatal=False, impersonate=self._IMPERSONATE_TARGET, headers=self._HEADERS,
|
||||||
note=join_nonempty('Downloading', format_id, 'm3u8 information', delim=' '),
|
note=join_nonempty('Downloading', format_id, 'm3u8 information', delim=' '),
|
||||||
errnote=join_nonempty('Failed to download', format_id, 'm3u8 information', delim=' '))
|
errnote=join_nonempty('Failed to download', format_id, 'm3u8 information', delim=' '))
|
||||||
if not m3u8_data:
|
if not m3u8_data:
|
||||||
@@ -98,14 +92,19 @@ class FloatplaneBaseIE(InfoExtractor):
|
|||||||
hls_aes['key'] = urlh.read().hex()
|
hls_aes['key'] = urlh.read().hex()
|
||||||
|
|
||||||
formats.append({
|
formats.append({
|
||||||
**traverse_obj(quality, {
|
**traverse_obj(variant, {
|
||||||
'format_note': ('label', {str}),
|
'format_note': ('label', {str}),
|
||||||
'width': ('width', {int}),
|
'width': ('meta', 'video', 'width', {int_or_none}),
|
||||||
'height': ('height', {int}),
|
'height': ('meta', 'video', 'height', {int_or_none}),
|
||||||
|
'vcodec': ('meta', 'video', 'codec', {str}),
|
||||||
|
'acodec': ('meta', 'audio', 'codec', {str}),
|
||||||
|
'vbr': ('meta', 'video', 'bitrate', 'average', {int_or_none(scale=1000)}),
|
||||||
|
'abr': ('meta', 'audio', 'bitrate', 'average', {int_or_none(scale=1000)}),
|
||||||
|
'audio_channels': ('meta', 'audio', 'channelCount', {int_or_none}),
|
||||||
|
'fps': ('meta', 'video', 'fps', {float_or_none}),
|
||||||
}),
|
}),
|
||||||
**parse_codecs(quality.get('codecs')),
|
'url': format_url,
|
||||||
'url': url,
|
'ext': determine_ext(format_url.partition('/chunk.m3u8')[0], 'mp4'),
|
||||||
'ext': determine_ext(url.partition('/chunk.m3u8')[0], 'mp4'),
|
|
||||||
'format_id': format_id,
|
'format_id': format_id,
|
||||||
'hls_media_playlist_data': m3u8_data,
|
'hls_media_playlist_data': m3u8_data,
|
||||||
'hls_aes': hls_aes or None,
|
'hls_aes': hls_aes or None,
|
||||||
|
|||||||
Reference in New Issue
Block a user