1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-20 01:42:50 +01:00

[ie] we have the utils: join_nonempty edition

Authored by: bashonly
This commit is contained in:
bashonly 2024-06-12 00:59:22 -05:00
parent 4141f9d4a9
commit 892af107ee
No known key found for this signature in database
GPG Key ID: 783F096F253D15B0
15 changed files with 39 additions and 36 deletions

View File

@ -4,6 +4,7 @@
from ..utils import (
extract_attributes,
int_or_none,
join_nonempty,
parse_iso8601,
try_get,
)
@ -136,7 +137,7 @@ def _real_extract(self, url):
else:
vbr = int_or_none(s.get('bitrate'))
formats.append({
'format_id': f'{stream_type}-{vbr}' if vbr else stream_type,
'format_id': join_nonempty(stream_type, vbr),
'vbr': vbr,
'width': int_or_none(s.get('width')),
'height': int_or_none(s.get('height')),

View File

@ -18,6 +18,7 @@
fix_xml_ampersands,
float_or_none,
int_or_none,
join_nonempty,
js_to_json,
mimetype2ext,
parse_iso8601,
@ -538,12 +539,7 @@ def _parse_brightcove_metadata(self, json_data, video_id, headers={}):
})
def build_format_id(kind):
format_id = kind
if tbr:
format_id += f'-{int(tbr)}k'
if height:
format_id += f'-{height}p'
return format_id
return join_nonempty(kind, tbr and f'{int(tbr)}k', height and f'{height}p')
if src or streaming_src:
f.update({

View File

@ -2,6 +2,7 @@
from ..utils import (
determine_protocol,
int_or_none,
join_nonempty,
try_get,
unescapeHTML,
)
@ -52,7 +53,7 @@ def _real_extract(self, url):
is_hls = container == 'M2TS'
protocol = 'm3u8_native' if is_hls else determine_protocol({'url': rendition_url})
formats.append({
'format_id': ('hls' if is_hls else protocol) + (f'-{tbr}' if tbr else ''),
'format_id': join_nonempty('hls' if is_hls else protocol, tbr),
'url': rendition_url,
'width': int_or_none(rendition.get('frameWidth')),
'height': int_or_none(rendition.get('frameHeight')),

View File

@ -1,6 +1,11 @@
from .common import InfoExtractor
from ..networking import Request
from ..utils import float_or_none, int_or_none, parse_iso8601
from ..utils import (
float_or_none,
int_or_none,
join_nonempty,
parse_iso8601,
)
class EitbIE(InfoExtractor):
@ -37,12 +42,9 @@ def _real_extract(self, url):
if not video_url:
continue
tbr = float_or_none(rendition.get('ENCODING_RATE'), 1000)
format_id = 'http'
if tbr:
format_id += f'-{int(tbr)}'
formats.append({
'url': rendition['PMD_URL'],
'format_id': format_id,
'format_id': join_nonempty('http', int_or_none(tbr)),
'width': int_or_none(rendition.get('FRAME_WIDTH')),
'height': int_or_none(rendition.get('FRAME_HEIGHT')),
'tbr': tbr,

View File

@ -5,6 +5,7 @@
ExtractorError,
determine_ext,
int_or_none,
join_nonempty,
parse_age_limit,
remove_end,
remove_start,
@ -287,7 +288,7 @@ def _real_extract(self, url):
if mobj:
height = int(mobj.group(2))
f.update({
'format_id': (f'{format_id}-' if format_id else '') + f'{height}P',
'format_id': join_nonempty(format_id, f'{height}P'),
'width': int(mobj.group(1)),
'height': height,
})

View File

@ -3,6 +3,7 @@
from .common import InfoExtractor
from ..utils import (
int_or_none,
join_nonempty,
parse_duration,
urljoin,
xpath_element,
@ -69,7 +70,7 @@ def _extract_info(self, url, display_id):
height = format_info.get('height')
fmt = {
'url': path,
'format_id': 'http{}'.format(f'-{height}p' if height else ''),
'format_id': join_nonempty('http'. height and f'{height}p'),
'width': format_info.get('width'),
'height': height,
}

View File

@ -16,6 +16,7 @@
determine_ext,
float_or_none,
int_or_none,
join_nonempty,
mimetype2ext,
parse_age_limit,
parse_duration,
@ -498,10 +499,8 @@ def _real_extract(self, url):
m3u8_id=format_id, fatal=False))
continue
tbr = int_or_none(va.get('bitrate'), 1000)
if tbr:
format_id += f'-{tbr}'
formats.append({
'format_id': format_id,
'format_id': join_nonempty(format_id, tbr),
'url': public_url,
'width': int_or_none(va.get('width')),
'height': int_or_none(va.get('height')),

View File

@ -2,6 +2,7 @@
from ..utils import (
determine_ext,
int_or_none,
join_nonempty,
parse_duration,
parse_iso8601,
)
@ -41,7 +42,7 @@ def _real_extract(self, url):
else:
height = int_or_none(playback.get('height'))
formats.append({
'format_id': playback.get('name', 'http' + (f'-{height}p' if height else '')),
'format_id': playback.get('name') or join_nonempty('http', height and f'{height}p'),
'url': playback_url,
'width': int_or_none(playback.get('width')),
'height': height,

View File

@ -1,5 +1,5 @@
from .common import InfoExtractor
from ..utils import int_or_none
from ..utils import int_or_none, join_nonempty
class PerformGroupIE(InfoExtractor):
@ -50,11 +50,8 @@ def _real_extract(self, url):
if not c_url:
continue
tbr = int_or_none(c.get('bitrate'), 1000)
format_id = 'http'
if tbr:
format_id += f'-{tbr}'
formats.append({
'format_id': format_id,
'format_id': join_nonempty('http', tbr),
'url': c_url,
'tbr': tbr,
'width': int_or_none(c.get('width')),

View File

@ -7,6 +7,7 @@
determine_ext,
float_or_none,
int_or_none,
join_nonempty,
merge_dicts,
unified_strdate,
)
@ -147,13 +148,13 @@ def fix_bitrate(bitrate):
'page_url': 'http://www.prosieben.de',
'tbr': tbr,
'ext': 'flv',
'format_id': 'rtmp{}'.format(f'-{tbr}' if tbr else ''),
'format_id': join_nonempty('rtmp', tbr),
})
else:
formats.append({
'url': source_url,
'tbr': tbr,
'format_id': 'http{}'.format(f'-{tbr}' if tbr else ''),
'format_id': join_nonempty('http', tbr),
})
return {

View File

@ -14,6 +14,7 @@
float_or_none,
format_field,
int_or_none,
join_nonempty,
make_archive_id,
remove_end,
str_or_none,
@ -107,7 +108,7 @@ def _extract_variant_formats(self, variant, video_id):
tbr = int_or_none(dict_get(variant, ('bitrate', 'bit_rate')), 1000) or None
f = {
'url': variant_url,
'format_id': 'http' + (f'-{tbr}' if tbr else ''),
'format_id': join_nonempty('http', tbr),
'tbr': tbr,
}
self._search_dimensions_in_video_url(f, variant_url)

View File

@ -5,6 +5,7 @@
from ..utils import (
ExtractorError,
int_or_none,
join_nonempty,
parse_age_limit,
traverse_obj,
)
@ -120,7 +121,7 @@ def _real_extract(self, url):
'height', default=None))
formats.append({
'url': video_asset_url,
'format_id': 'http{}'.format(f'-{bitrate}' if bitrate else ''),
'format_id': join_nonempty('http', bitrate),
'tbr': bitrate,
'height': height,
'vcodec': video_asset.get('codec'),

View File

@ -2,6 +2,7 @@
from ..utils import (
float_or_none,
int_or_none,
join_nonempty,
unified_strdate,
)
@ -76,7 +77,7 @@ def _real_extract(self, url):
tbr = int_or_none(v.get('bitrate'))
formats.append({
'url': mp4_url,
'format_id': 'http' + (f'-{tbr}' if tbr else ''),
'format_id': join_nonempty('http', tbr),
'tbr': tbr,
'width': int_or_none(v.get('width')),
'height': int_or_none(v.get('height')),

View File

@ -8,6 +8,7 @@
ExtractorError,
clean_html,
int_or_none,
join_nonempty,
mimetype2ext,
parse_iso8601,
traverse_obj,
@ -213,7 +214,7 @@ def _extract_yahoo_video(self, video_id, country):
tbr = int_or_none(s.get('bitrate'))
formats.append({
'url': s_url,
'format_id': fmt + (f'-{tbr}' if tbr else ''),
'format_id': join_nonempty(fmt, tbr),
'width': int_or_none(s.get('width')),
'height': int_or_none(s.get('height')),
'tbr': tbr,
@ -371,12 +372,13 @@ def _extract_formats(self, json_data, content_id):
url, content_id, 'mp4', 'm3u8_native',
m3u8_id='hls', fatal=False))
else:
bitrate = int_or_none(vid.get('bitrate'))
formats.append({
'url': url,
'format_id': f'http-{vid.get("bitrate")}',
'format_id': join_nonempty('http', bitrate),
'height': int_or_none(vid.get('height')),
'width': int_or_none(vid.get('width')),
'tbr': int_or_none(vid.get('bitrate')),
'tbr': bitrate,
})
self._remove_duplicate_formats(formats)

View File

@ -5,6 +5,7 @@
determine_ext,
float_or_none,
int_or_none,
join_nonempty,
mimetype2ext,
try_get,
urljoin,
@ -116,12 +117,9 @@ def call_api(action):
else:
size = video.get('size') or {}
height = int_or_none(size.get('height'))
format_id = 'hls'
if height:
format_id += f'-{height}p'
formats.append({
'ext': 'mp4',
'format_id': format_id,
'format_id': join_nonempty('hls', height and f'{height}p'),
'height': height,
'protocol': 'm3u8_native',
'url': format_url,