[cleanup] Misc fixes
Closes https://github.com/yt-dlp/yt-dlp/pull/3213, Closes https://github.com/yt-dlp/yt-dlp/pull/3117 Related: https://github.com/yt-dlp/yt-dlp/issues/3146#issuecomment-1077323114, https://github.com/yt-dlp/yt-dlp/pull/3277#discussion_r841019671,a825ffbffa (commitcomment-68538986), https://github.com/yt-dlp/yt-dlp/issues/2360,5fa3c9a88f (r70393519),5fa3c9a88f (r70393254)
This commit is contained in:
@@ -517,7 +517,7 @@ class YoutubeDL(object):
|
||||
|
||||
_format_fields = {
|
||||
# NB: Keep in sync with the docstring of extractor/common.py
|
||||
'url', 'manifest_url', 'ext', 'format', 'format_id', 'format_note',
|
||||
'url', 'manifest_url', 'manifest_stream_number', 'ext', 'format', 'format_id', 'format_note',
|
||||
'width', 'height', 'resolution', 'dynamic_range', 'tbr', 'abr', 'acodec', 'asr',
|
||||
'vbr', 'fps', 'vcodec', 'container', 'filesize', 'filesize_approx',
|
||||
'player_url', 'protocol', 'fragment_base_url', 'fragments', 'is_from_start',
|
||||
@@ -938,7 +938,7 @@ class YoutubeDL(object):
|
||||
|
||||
def deprecation_warning(self, message):
|
||||
if self.params.get('logger') is not None:
|
||||
self.params['logger'].warning('DeprecationWarning: {message}')
|
||||
self.params['logger'].warning(f'DeprecationWarning: {message}')
|
||||
else:
|
||||
self.to_stderr(f'{self._format_err("DeprecationWarning:", self.Styles.ERROR)} {message}', True)
|
||||
|
||||
@@ -2478,8 +2478,9 @@ class YoutubeDL(object):
|
||||
if info_dict.get('is_live') and formats:
|
||||
formats = [f for f in formats if bool(f.get('is_from_start')) == get_from_start]
|
||||
if get_from_start and not formats:
|
||||
self.raise_no_formats(info_dict, msg='--live-from-start is passed, but there are no formats that can be downloaded from the start. '
|
||||
'If you want to download from the current time, pass --no-live-from-start')
|
||||
self.raise_no_formats(info_dict, msg=(
|
||||
'--live-from-start is passed, but there are no formats that can be downloaded from the start. '
|
||||
'If you want to download from the current time, use --no-live-from-start'))
|
||||
|
||||
if not formats:
|
||||
self.raise_no_formats(info_dict)
|
||||
|
||||
@@ -379,7 +379,7 @@ def validate_options(opts):
|
||||
'To let yt-dlp download and merge the best available formats, simply do not pass any format selection',
|
||||
'If you know what you are doing and want only the best pre-merged format, use "-f b" instead to suppress this warning')))
|
||||
|
||||
# --(post-processor/downloader)-args without name
|
||||
# --(postprocessor/downloader)-args without name
|
||||
def report_args_compat(name, value, key1, key2=None):
|
||||
if key1 in value and key2 not in value:
|
||||
warnings.append(f'{name} arguments given without specifying name. The arguments will be given to all {name}s')
|
||||
|
||||
@@ -21,6 +21,7 @@ from .compat import (
|
||||
compat_cookiejar_Cookie,
|
||||
)
|
||||
from .utils import (
|
||||
error_to_str,
|
||||
expand_path,
|
||||
Popen,
|
||||
YoutubeDLCookieJar,
|
||||
@@ -721,7 +722,7 @@ def _get_kwallet_network_wallet(logger):
|
||||
network_wallet = stdout.decode('utf-8').strip()
|
||||
logger.debug('NetworkWallet = "{}"'.format(network_wallet))
|
||||
return network_wallet
|
||||
except BaseException as e:
|
||||
except Exception as e:
|
||||
logger.warning('exception while obtaining NetworkWallet: {}'.format(e))
|
||||
return default_wallet
|
||||
|
||||
@@ -766,8 +767,8 @@ def _get_kwallet_password(browser_keyring_name, logger):
|
||||
if stdout[-1:] == b'\n':
|
||||
stdout = stdout[:-1]
|
||||
return stdout
|
||||
except BaseException as e:
|
||||
logger.warning(f'exception running kwallet-query: {type(e).__name__}({e})')
|
||||
except Exception as e:
|
||||
logger.warning(f'exception running kwallet-query: {error_to_str(e)}')
|
||||
return b''
|
||||
|
||||
|
||||
@@ -823,8 +824,8 @@ def _get_mac_keyring_password(browser_keyring_name, logger):
|
||||
if stdout[-1:] == b'\n':
|
||||
stdout = stdout[:-1]
|
||||
return stdout
|
||||
except BaseException as e:
|
||||
logger.warning(f'exception running find-generic-password: {type(e).__name__}({e})')
|
||||
except Exception as e:
|
||||
logger.warning(f'exception running find-generic-password: {error_to_str(e)}')
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -403,7 +403,7 @@ class FragmentFD(FileDownloader):
|
||||
pass
|
||||
|
||||
if compat_os_name == 'nt':
|
||||
def bindoj_result(future):
|
||||
def future_result(future):
|
||||
while True:
|
||||
try:
|
||||
return future.result(0.1)
|
||||
@@ -412,7 +412,7 @@ class FragmentFD(FileDownloader):
|
||||
except concurrent.futures.TimeoutError:
|
||||
continue
|
||||
else:
|
||||
def bindoj_result(future):
|
||||
def future_result(future):
|
||||
return future.result()
|
||||
|
||||
def interrupt_trigger_iter(fg):
|
||||
@@ -430,7 +430,7 @@ class FragmentFD(FileDownloader):
|
||||
result = True
|
||||
for tpe, job in spins:
|
||||
try:
|
||||
result = result and bindoj_result(job)
|
||||
result = result and future_result(job)
|
||||
except KeyboardInterrupt:
|
||||
interrupt_trigger[0] = False
|
||||
finally:
|
||||
@@ -494,16 +494,14 @@ class FragmentFD(FileDownloader):
|
||||
self.report_error('Giving up after %s fragment retries' % fragment_retries)
|
||||
|
||||
def append_fragment(frag_content, frag_index, ctx):
|
||||
if not frag_content:
|
||||
if not is_fatal(frag_index - 1):
|
||||
self.report_skip_fragment(frag_index, 'fragment not found')
|
||||
return True
|
||||
else:
|
||||
ctx['dest_stream'].close()
|
||||
self.report_error(
|
||||
'fragment %s not found, unable to continue' % frag_index)
|
||||
return False
|
||||
self._append_fragment(ctx, pack_func(frag_content, frag_index))
|
||||
if frag_content:
|
||||
self._append_fragment(ctx, pack_func(frag_content, frag_index))
|
||||
elif not is_fatal(frag_index - 1):
|
||||
self.report_skip_fragment(frag_index, 'fragment not found')
|
||||
else:
|
||||
ctx['dest_stream'].close()
|
||||
self.report_error(f'fragment {frag_index} not found, unable to continue')
|
||||
return False
|
||||
return True
|
||||
|
||||
decrypt_fragment = self.decrypter(info_dict)
|
||||
|
||||
@@ -7,7 +7,6 @@ import random
|
||||
|
||||
from .common import FileDownloader
|
||||
from ..compat import (
|
||||
compat_str,
|
||||
compat_urllib_error,
|
||||
compat_http_client
|
||||
)
|
||||
@@ -58,8 +57,6 @@ class HttpFD(FileDownloader):
|
||||
ctx.resume_len = 0
|
||||
ctx.block_size = self.params.get('buffersize', 1024)
|
||||
ctx.start_time = time.time()
|
||||
ctx.chunk_size = None
|
||||
throttle_start = None
|
||||
|
||||
# parse given Range
|
||||
req_start, req_end, _ = parse_http_range(headers.get('Range'))
|
||||
@@ -85,12 +82,6 @@ class HttpFD(FileDownloader):
|
||||
class NextFragment(Exception):
|
||||
pass
|
||||
|
||||
def set_range(req, start, end):
|
||||
range_header = 'bytes=%d-' % start
|
||||
if end:
|
||||
range_header += compat_str(end)
|
||||
req.add_header('Range', range_header)
|
||||
|
||||
def establish_connection():
|
||||
ctx.chunk_size = (random.randint(int(chunk_size * 0.95), chunk_size)
|
||||
if not is_test and chunk_size else chunk_size)
|
||||
@@ -131,7 +122,7 @@ class HttpFD(FileDownloader):
|
||||
request = sanitized_Request(url, request_data, headers)
|
||||
has_range = range_start is not None
|
||||
if has_range:
|
||||
set_range(request, range_start, range_end)
|
||||
request.add_header('Range', f'bytes={int(range_start)}-{int_or_none(range_end) or ""}')
|
||||
# Establish connection
|
||||
try:
|
||||
ctx.data = self.ydl.urlopen(request)
|
||||
@@ -214,7 +205,6 @@ class HttpFD(FileDownloader):
|
||||
raise RetryDownload(err)
|
||||
|
||||
def download():
|
||||
nonlocal throttle_start
|
||||
data_len = ctx.data.info().get('Content-length', None)
|
||||
|
||||
# Range HTTP header may be ignored/unsupported by a webserver
|
||||
@@ -329,14 +319,14 @@ class HttpFD(FileDownloader):
|
||||
if speed and speed < (self.params.get('throttledratelimit') or 0):
|
||||
# The speed must stay below the limit for 3 seconds
|
||||
# This prevents raising error when the speed temporarily goes down
|
||||
if throttle_start is None:
|
||||
throttle_start = now
|
||||
elif now - throttle_start > 3:
|
||||
if ctx.throttle_start is None:
|
||||
ctx.throttle_start = now
|
||||
elif now - ctx.throttle_start > 3:
|
||||
if ctx.stream is not None and ctx.tmpfilename != '-':
|
||||
ctx.stream.close()
|
||||
raise ThrottledDownload()
|
||||
elif speed:
|
||||
throttle_start = None
|
||||
ctx.throttle_start = None
|
||||
|
||||
if not is_test and ctx.chunk_size and ctx.content_len is not None and byte_counter < ctx.content_len:
|
||||
ctx.resume_len = byte_counter
|
||||
|
||||
@@ -926,9 +926,9 @@ class BiliIntlIE(BiliIntlBaseIE):
|
||||
if season_id and not video_data:
|
||||
# Non-Bstation layout, read through episode list
|
||||
season_json = self._call_api(f'/web/v2/ogv/play/episodes?season_id={season_id}&platform=web', video_id)
|
||||
video_data = next(
|
||||
episode for episode in traverse_obj(season_json, ('sections', ..., 'episodes', ...), expected_type=dict)
|
||||
if str(episode.get('episode_id')) == ep_id)
|
||||
video_data = traverse_obj(season_json,
|
||||
('sections', ..., 'episodes', lambda _, v: str(v['episode_id']) == ep_id),
|
||||
expected_type=dict, get_all=False)
|
||||
return self._extract_video_info(video_data, ep_id=ep_id, aid=aid)
|
||||
|
||||
|
||||
|
||||
@@ -245,10 +245,6 @@ class VrtNUIE(GigyaBaseIE):
|
||||
'upload_date': '20200727',
|
||||
},
|
||||
'skip': 'This video is only available for registered users',
|
||||
'params': {
|
||||
'username': '<snip>',
|
||||
'password': '<snip>',
|
||||
},
|
||||
'expected_warnings': ['is not a supported codec'],
|
||||
}, {
|
||||
# Only available via new API endpoint
|
||||
@@ -264,10 +260,6 @@ class VrtNUIE(GigyaBaseIE):
|
||||
'episode_number': 5,
|
||||
},
|
||||
'skip': 'This video is only available for registered users',
|
||||
'params': {
|
||||
'username': '<snip>',
|
||||
'password': '<snip>',
|
||||
},
|
||||
'expected_warnings': ['Unable to download asset JSON', 'is not a supported codec', 'Unknown MIME type'],
|
||||
}]
|
||||
_NETRC_MACHINE = 'vrtnu'
|
||||
|
||||
@@ -139,6 +139,8 @@ class InfoExtractor(object):
|
||||
for HDS - URL of the F4M manifest,
|
||||
for DASH - URL of the MPD manifest,
|
||||
for MSS - URL of the ISM manifest.
|
||||
* manifest_stream_number (For internal use only)
|
||||
The index of the stream in the manifest file
|
||||
* ext Will be calculated from URL if missing
|
||||
* format A human-readable description of the format
|
||||
("mp4 container with h264/opus").
|
||||
@@ -215,7 +217,7 @@ class InfoExtractor(object):
|
||||
(HTTP or RTMP) download. Boolean.
|
||||
* has_drm The format has DRM and cannot be downloaded. Boolean
|
||||
* downloader_options A dictionary of downloader options as
|
||||
described in FileDownloader
|
||||
described in FileDownloader (For internal use only)
|
||||
RTMP formats can also have the additional fields: page_url,
|
||||
app, play_path, tc_url, flash_version, rtmp_live, rtmp_conn,
|
||||
rtmp_protocol, rtmp_real_time
|
||||
@@ -3684,9 +3686,9 @@ class InfoExtractor(object):
|
||||
def _merge_subtitle_items(subtitle_list1, subtitle_list2):
|
||||
""" Merge subtitle items for one language. Items with duplicated URLs/data
|
||||
will be dropped. """
|
||||
list1_data = set([item.get('url') or item['data'] for item in subtitle_list1])
|
||||
list1_data = set((item.get('url'), item.get('data')) for item in subtitle_list1)
|
||||
ret = list(subtitle_list1)
|
||||
ret.extend([item for item in subtitle_list2 if (item.get('url') or item['data']) not in list1_data])
|
||||
ret.extend(item for item in subtitle_list2 if (item.get('url'), item.get('data')) not in list1_data)
|
||||
return ret
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -123,7 +123,7 @@ class DropoutIE(InfoExtractor):
|
||||
self._login(display_id)
|
||||
webpage = self._download_webpage(url, display_id, note='Downloading video webpage')
|
||||
finally:
|
||||
self._download_webpage('https://www.dropout.tv/logout', display_id, note='Logging out')
|
||||
self._download_webpage('https://www.dropout.tv/logout', display_id, note='Logging out', fatal=False)
|
||||
|
||||
embed_url = self._search_regex(r'embed_url:\s*["\'](.+?)["\']', webpage, 'embed url')
|
||||
thumbnail = self._og_search_thumbnail(webpage)
|
||||
@@ -139,7 +139,7 @@ class DropoutIE(InfoExtractor):
|
||||
'_type': 'url_transparent',
|
||||
'ie_key': VHXEmbedIE.ie_key(),
|
||||
'url': embed_url,
|
||||
'id': self._search_regex(r'embed.vhx.tv/videos/(.+?)\?', embed_url, 'id'),
|
||||
'id': self._search_regex(r'embed\.vhx\.tv/videos/(.+?)\?', embed_url, 'id'),
|
||||
'display_id': display_id,
|
||||
'title': title,
|
||||
'description': self._html_search_meta('description', webpage, fatal=False),
|
||||
|
||||
@@ -397,8 +397,10 @@ class FacebookIE(InfoExtractor):
|
||||
r'handleWithCustomApplyEach\(\s*ScheduledApplyEach\s*,\s*(\{.+?\})\s*\);', webpage)]
|
||||
post = traverse_obj(post_data, (
|
||||
..., 'require', ..., ..., ..., '__bbox', 'result', 'data'), expected_type=dict) or []
|
||||
media = [m for m in traverse_obj(post, (..., 'attachments', ..., 'media'), expected_type=dict) or []
|
||||
if str(m.get('id')) == video_id and m.get('__typename') == 'Video']
|
||||
media = traverse_obj(
|
||||
post,
|
||||
(..., 'attachments', ..., 'media', lambda _, m: str(m['id']) == video_id and m['__typename'] == 'Video'),
|
||||
expected_type=dict)
|
||||
title = get_first(media, ('title', 'text'))
|
||||
description = get_first(media, ('creation_story', 'comet_sections', 'message', 'story', 'message', 'text'))
|
||||
uploader_data = get_first(media, 'owner') or get_first(post, ('node', 'actors', ...)) or {}
|
||||
|
||||
@@ -2523,7 +2523,7 @@ class GenericIE(InfoExtractor):
|
||||
'title': 'Riku ja Tunna lähtevät peurajahtiin tv:stä tutun biologin kanssa – metsästysreissu huipentuu kasvissyöjän painajaiseen!',
|
||||
'thumbnail': r're:^https?://.+\.jpg$',
|
||||
'duration': 108,
|
||||
'series' : 'Madventures Suomi',
|
||||
'series': 'Madventures Suomi',
|
||||
'description': 'md5:aa55b44bd06a1e337a6f1d0b46507381',
|
||||
'categories': ['Matkailu', 'Elämäntyyli'],
|
||||
'age_limit': 0,
|
||||
@@ -3886,8 +3886,8 @@ class GenericIE(InfoExtractor):
|
||||
if RtmpIE.suitable(vurl):
|
||||
return True
|
||||
vpath = compat_urlparse.urlparse(vurl).path
|
||||
vext = determine_ext(vpath)
|
||||
return '.' in vpath and vext not in ('swf', 'png', 'jpg', 'srt', 'sbv', 'sub', 'vtt', 'ttml', 'js', 'xml')
|
||||
vext = determine_ext(vpath, None)
|
||||
return vext not in (None, 'swf', 'png', 'jpg', 'srt', 'sbv', 'sub', 'vtt', 'ttml', 'js', 'xml')
|
||||
|
||||
def filter_video(urls):
|
||||
return list(filter(check_video, urls))
|
||||
|
||||
@@ -194,7 +194,7 @@ class LimelightBaseIE(InfoExtractor):
|
||||
cc_url = cc.get('webvttFileUrl')
|
||||
if not cc_url:
|
||||
continue
|
||||
lang = cc.get('languageCode') or self._search_regex(r'/[a-z]{2}\.vtt', cc_url, 'lang', default='en')
|
||||
lang = cc.get('languageCode') or self._search_regex(r'/([a-z]{2})\.vtt', cc_url, 'lang', default='en')
|
||||
subtitles.setdefault(lang, []).append({
|
||||
'url': cc_url,
|
||||
})
|
||||
|
||||
@@ -469,7 +469,7 @@ class NiconicoIE(InfoExtractor):
|
||||
comment_user_key = traverse_obj(api_data, ('comment', 'keys', 'userKey'))
|
||||
user_id_str = session_api_data.get('serviceUserId')
|
||||
|
||||
thread_ids = [x for x in traverse_obj(api_data, ('comment', 'threads')) or [] if x['isActive']]
|
||||
thread_ids = traverse_obj(api_data, ('comment', 'threads', lambda _, v: v['isActive']))
|
||||
raw_danmaku = self._extract_all_comments(video_id, thread_ids, user_id_str, comment_user_key)
|
||||
if not raw_danmaku:
|
||||
self.report_warning(f'Failed to get comments. {bug_reports_message()}')
|
||||
|
||||
@@ -264,7 +264,7 @@ class TikTokBaseIE(InfoExtractor):
|
||||
return {
|
||||
'id': aweme_id,
|
||||
'title': aweme_detail.get('desc'),
|
||||
'description': aweme_detail['desc'],
|
||||
'description': aweme_detail.get('desc'),
|
||||
'view_count': int_or_none(stats_info.get('play_count')),
|
||||
'like_count': int_or_none(stats_info.get('digg_count')),
|
||||
'repost_count': int_or_none(stats_info.get('share_count')),
|
||||
@@ -387,6 +387,9 @@ class TikTokIE(TikTokBaseIE):
|
||||
'like_count': int,
|
||||
'repost_count': int,
|
||||
'comment_count': int,
|
||||
'artist': 'Ysrbeats',
|
||||
'album': 'Lehanga',
|
||||
'track': 'Lehanga',
|
||||
}
|
||||
}, {
|
||||
'url': 'https://www.tiktok.com/@patroxofficial/video/6742501081818877190?langCountry=en',
|
||||
@@ -410,6 +413,8 @@ class TikTokIE(TikTokBaseIE):
|
||||
'like_count': int,
|
||||
'repost_count': int,
|
||||
'comment_count': int,
|
||||
'artist': 'Evan Todd, Jessica Keenan Wynn, Alice Lee, Barrett Wilbert Weed & Jon Eidson',
|
||||
'track': 'Big Fun',
|
||||
}
|
||||
}, {
|
||||
# Banned audio, only available on the app
|
||||
@@ -463,7 +468,7 @@ class TikTokIE(TikTokBaseIE):
|
||||
'info_dict': {
|
||||
'id': '7059698374567611694',
|
||||
'ext': 'mp4',
|
||||
'title': 'N/A',
|
||||
'title': 'tiktok video #7059698374567611694',
|
||||
'description': '',
|
||||
'uploader': 'pokemonlife22',
|
||||
'creator': 'Pokemon',
|
||||
@@ -480,7 +485,7 @@ class TikTokIE(TikTokBaseIE):
|
||||
'repost_count': int,
|
||||
'comment_count': int,
|
||||
},
|
||||
'expected_warnings': ['Video not available']
|
||||
'expected_warnings': ['Video not available', 'Creating a generic title']
|
||||
}, {
|
||||
# Auto-captions available
|
||||
'url': 'https://www.tiktok.com/@hankgreen1/video/7047596209028074758',
|
||||
|
||||
@@ -163,7 +163,6 @@ class YandexVideoPreviewIE(InfoExtractor):
|
||||
'thumbnail': 'https://i.mycdn.me/videoPreview?id=544866765315&type=37&idx=13&tkn=TY5qjLYZHxpmcnK8U2LgzYkgmaU&fn=external_8',
|
||||
'uploader_id': '481054701571',
|
||||
'title': 'LOFT - summer, summer, summer HD',
|
||||
'manifest_stream_number': 0,
|
||||
'uploader': 'АРТЁМ КУДРОВ',
|
||||
},
|
||||
}, { # youtube
|
||||
|
||||
@@ -837,17 +837,20 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
|
||||
uploader = self._get_text(renderer, 'ownerText', 'shortBylineText')
|
||||
channel_id = traverse_obj(
|
||||
renderer, ('shortBylineText', 'runs', ..., 'navigationEndpoint', 'browseEndpoint', 'browseId'), expected_type=str, get_all=False)
|
||||
renderer, ('shortBylineText', 'runs', ..., 'navigationEndpoint', 'browseEndpoint', 'browseId'),
|
||||
expected_type=str, get_all=False)
|
||||
timestamp, time_text = self._extract_time_text(renderer, 'publishedTimeText')
|
||||
scheduled_timestamp = str_to_int(traverse_obj(renderer, ('upcomingEventData', 'startTime'), get_all=False))
|
||||
overlay_style = traverse_obj(
|
||||
renderer, ('thumbnailOverlays', ..., 'thumbnailOverlayTimeStatusRenderer', 'style'), get_all=False, expected_type=str)
|
||||
renderer, ('thumbnailOverlays', ..., 'thumbnailOverlayTimeStatusRenderer', 'style'),
|
||||
get_all=False, expected_type=str)
|
||||
badges = self._extract_badges(renderer)
|
||||
thumbnails = self._extract_thumbnails(renderer, 'thumbnail')
|
||||
navigation_url = urljoin('https://www.youtube.com/', traverse_obj(
|
||||
renderer, ('navigationEndpoint', 'commandMetadata', 'webCommandMetadata', 'url'), expected_type=str))
|
||||
renderer, ('navigationEndpoint', 'commandMetadata', 'webCommandMetadata', 'url'),
|
||||
expected_type=str)) or ''
|
||||
url = f'https://www.youtube.com/watch?v={video_id}'
|
||||
if overlay_style == 'SHORTS' or (navigation_url and '/shorts/' in navigation_url):
|
||||
if overlay_style == 'SHORTS' or '/shorts/' in navigation_url:
|
||||
url = f'https://www.youtube.com/shorts/{video_id}'
|
||||
|
||||
return {
|
||||
@@ -862,7 +865,9 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
'uploader': uploader,
|
||||
'channel_id': channel_id,
|
||||
'thumbnails': thumbnails,
|
||||
'upload_date': strftime_or_none(timestamp, '%Y%m%d') if self._configuration_arg('approximate_date', ie_key='youtubetab') else None,
|
||||
'upload_date': (strftime_or_none(timestamp, '%Y%m%d')
|
||||
if self._configuration_arg('approximate_date', ie_key='youtubetab')
|
||||
else None),
|
||||
'live_status': ('is_upcoming' if scheduled_timestamp is not None
|
||||
else 'was_live' if 'streamed' in time_text.lower()
|
||||
else 'is_live' if overlay_style is not None and overlay_style == 'LIVE' or 'live now' in badges
|
||||
|
||||
@@ -163,6 +163,8 @@ def create_parser():
|
||||
values = [process(value)] if delim is None else list(map(process, value.split(delim)[::-1]))
|
||||
while values:
|
||||
actual_val = val = values.pop()
|
||||
if not val:
|
||||
raise optparse.OptionValueError(f'Invalid {option.metavar} for {opt_str}: {value}')
|
||||
if val == 'all':
|
||||
current.update(allowed_values)
|
||||
elif val == '-all':
|
||||
@@ -1311,7 +1313,7 @@ def create_parser():
|
||||
'--audio-format', metavar='FORMAT', dest='audioformat', default='best',
|
||||
help=(
|
||||
'Specify audio format to convert the audio to when -x is used. Currently supported formats are: '
|
||||
'best (default) or one of %s' % '|'.join(FFmpegExtractAudioPP.SUPPORTED_EXTS)))
|
||||
'best (default) or one of %s' % ', '.join(FFmpegExtractAudioPP.SUPPORTED_EXTS)))
|
||||
postproc.add_option(
|
||||
'--audio-quality', metavar='QUALITY',
|
||||
dest='audioquality', default='5',
|
||||
@@ -1323,7 +1325,7 @@ def create_parser():
|
||||
'Remux the video into another container if necessary (currently supported: %s). '
|
||||
'If target container does not support the video/audio codec, remuxing will fail. '
|
||||
'You can specify multiple rules; Eg. "aac>m4a/mov>mp4/mkv" will remux aac to m4a, mov to mp4 '
|
||||
'and anything else to mkv.' % '|'.join(FFmpegVideoRemuxerPP.SUPPORTED_EXTS)))
|
||||
'and anything else to mkv.' % ', '.join(FFmpegVideoRemuxerPP.SUPPORTED_EXTS)))
|
||||
postproc.add_option(
|
||||
'--recode-video',
|
||||
metavar='FORMAT', dest='recodevideo', default=None,
|
||||
@@ -1438,7 +1440,7 @@ def create_parser():
|
||||
'"multi_video" (default; only when the videos form a single show). '
|
||||
'All the video files must have same codecs and number of streams to be concatable. '
|
||||
'The "pl_video:" prefix can be used with "--paths" and "--output" to '
|
||||
'set the output filename for the split files. See "OUTPUT TEMPLATE" for details'))
|
||||
'set the output filename for the concatenated files. See "OUTPUT TEMPLATE" for details'))
|
||||
postproc.add_option(
|
||||
'--fixup',
|
||||
metavar='POLICY', dest='fixup', default=None,
|
||||
@@ -1486,20 +1488,20 @@ def create_parser():
|
||||
help=optparse.SUPPRESS_HELP)
|
||||
postproc.add_option(
|
||||
'--no-exec-before-download',
|
||||
action='store_const', dest='exec_before_dl_cmd', const=[],
|
||||
action='store_const', dest='exec_before_dl_cmd', const=None,
|
||||
help=optparse.SUPPRESS_HELP)
|
||||
postproc.add_option(
|
||||
'--convert-subs', '--convert-sub', '--convert-subtitles',
|
||||
metavar='FORMAT', dest='convertsubtitles', default=None,
|
||||
help=(
|
||||
'Convert the subtitles to another format (currently supported: %s) '
|
||||
'(Alias: --convert-subtitles)' % '|'.join(FFmpegSubtitlesConvertorPP.SUPPORTED_EXTS)))
|
||||
'(Alias: --convert-subtitles)' % ', '.join(FFmpegSubtitlesConvertorPP.SUPPORTED_EXTS)))
|
||||
postproc.add_option(
|
||||
'--convert-thumbnails',
|
||||
metavar='FORMAT', dest='convertthumbnails', default=None,
|
||||
help=(
|
||||
'Convert the thumbnails to another format '
|
||||
'(currently supported: %s) ' % '|'.join(FFmpegThumbnailsConvertorPP.SUPPORTED_EXTS)))
|
||||
'(currently supported: %s) ' % ', '.join(FFmpegThumbnailsConvertorPP.SUPPORTED_EXTS)))
|
||||
postproc.add_option(
|
||||
'--split-chapters', '--split-tracks',
|
||||
dest='split_chapters', action='store_true', default=False,
|
||||
|
||||
@@ -500,6 +500,9 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
|
||||
temp_path = new_path = prefix + sep + extension
|
||||
|
||||
if new_path == path:
|
||||
if acodec == 'copy':
|
||||
self.to_screen(f'File is already in target format {self._preferredcodec}, skipping')
|
||||
return [], information
|
||||
orig_path = prepend_extension(path, 'orig')
|
||||
temp_path = prepend_extension(path, 'temp')
|
||||
if (self._nopostoverwrites and os.path.exists(encodeFilename(new_path))
|
||||
@@ -1122,6 +1125,11 @@ class FFmpegConcatPP(FFmpegPostProcessor):
|
||||
self._only_multi_video = only_multi_video
|
||||
super().__init__(downloader)
|
||||
|
||||
def _get_codecs(self, file):
|
||||
codecs = traverse_obj(self.get_metadata_object(file), ('streams', ..., 'codec_name'))
|
||||
self.write_debug(f'Codecs = {", ".join(codecs)}')
|
||||
return tuple(codecs)
|
||||
|
||||
def concat_files(self, in_files, out_file):
|
||||
if not self._downloader._ensure_dir_exists(out_file):
|
||||
return
|
||||
@@ -1131,8 +1139,7 @@ class FFmpegConcatPP(FFmpegPostProcessor):
|
||||
os.replace(in_files[0], out_file)
|
||||
return []
|
||||
|
||||
codecs = [traverse_obj(self.get_metadata_object(file), ('streams', ..., 'codec_name')) for file in in_files]
|
||||
if len(set(map(tuple, codecs))) > 1:
|
||||
if len(set(map(self._get_codecs, in_files))) > 1:
|
||||
raise PostProcessingError(
|
||||
'The files have different streams/codecs and cannot be concatenated. '
|
||||
'Either select different formats or --recode-video them to a common format')
|
||||
@@ -1146,7 +1153,7 @@ class FFmpegConcatPP(FFmpegPostProcessor):
|
||||
entries = info.get('entries') or []
|
||||
if not any(entries) or (self._only_multi_video and info['_type'] != 'multi_video'):
|
||||
return [], info
|
||||
elif any(len(entry) > 1 for entry in traverse_obj(entries, (..., 'requested_downloads')) or []):
|
||||
elif traverse_obj(entries, (..., 'requested_downloads', lambda _, v: len(v) > 1)):
|
||||
raise PostProcessingError('Concatenation is not supported when downloading multiple separate formats')
|
||||
|
||||
in_files = traverse_obj(entries, (..., 'requested_downloads', 0, 'filepath')) or []
|
||||
|
||||
@@ -1040,7 +1040,7 @@ def make_HTTPS_handler(params, **kwargs):
|
||||
|
||||
|
||||
def bug_reports_message(before=';'):
|
||||
msg = ('please report this issue on https://github.com/yt-dlp/yt-dlp , '
|
||||
msg = ('please report this issue on https://github.com/yt-dlp/yt-dlp/issues?q= , '
|
||||
'filling out the appropriate issue template. '
|
||||
'Confirm you are on the latest version using yt-dlp -U')
|
||||
|
||||
@@ -2883,6 +2883,7 @@ class PagedList:
|
||||
|
||||
|
||||
class OnDemandPagedList(PagedList):
|
||||
"""Download pages until a page with less than maximum results"""
|
||||
def _getslice(self, start, end):
|
||||
for pagenum in itertools.count(start // self._pagesize):
|
||||
firstid = pagenum * self._pagesize
|
||||
@@ -2922,6 +2923,7 @@ class OnDemandPagedList(PagedList):
|
||||
|
||||
|
||||
class InAdvancePagedList(PagedList):
|
||||
"""PagedList with total number of pages known in advance"""
|
||||
def __init__(self, pagefunc, pagecount, pagesize):
|
||||
PagedList.__init__(self, pagefunc, pagesize, True)
|
||||
self._pagecount = pagecount
|
||||
@@ -3090,13 +3092,10 @@ def multipart_encode(data, boundary=None):
|
||||
|
||||
|
||||
def dict_get(d, key_or_keys, default=None, skip_false_values=True):
|
||||
if isinstance(key_or_keys, (list, tuple)):
|
||||
for key in key_or_keys:
|
||||
if key not in d or d[key] is None or skip_false_values and not d[key]:
|
||||
continue
|
||||
return d[key]
|
||||
return default
|
||||
return d.get(key_or_keys, default)
|
||||
for val in map(d.get, variadic(key_or_keys)):
|
||||
if val is not None and (val or not skip_false_values):
|
||||
return val
|
||||
return default
|
||||
|
||||
|
||||
def try_call(*funcs, expected_type=None, args=[], kwargs={}):
|
||||
@@ -3324,6 +3323,10 @@ def error_to_compat_str(err):
|
||||
return err_str
|
||||
|
||||
|
||||
def error_to_str(err):
|
||||
return f'{type(err).__name__}: {err}'
|
||||
|
||||
|
||||
def mimetype2ext(mt):
|
||||
if mt is None:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user