mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-23 09:01:43 +00:00
[cleanup, utils] Don't use kwargs for format_field
This commit is contained in:
parent
e121e3cee7
commit
a70635b8a1
@ -90,7 +90,7 @@ def _real_extract(self, url):
|
||||
'timestamp': parse_iso8601(video.get('creationTime')),
|
||||
'channel': channel.get('name'),
|
||||
'channel_id': channel_id,
|
||||
'channel_url': format_field(channel_id, template=f'{self._BASE_URL}/?channel=%s'),
|
||||
'channel_url': format_field(channel_id, None, f'{self._BASE_URL}/?channel=%s'),
|
||||
'duration': float_or_none(video.get('duration'), 1000),
|
||||
'view_count': int_or_none(video.get('views')),
|
||||
'tags': video.get('hashtags'),
|
||||
|
@ -41,7 +41,7 @@ def _parse_video_data(self, video_data, video_id, is_live):
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'description': video_data.get('description_en') or video_data.get('description_ar'),
|
||||
'thumbnail': format_field(img, template='http://admin.mangomolo.com/analytics/%s'),
|
||||
'thumbnail': format_field(img, None, 'http://admin.mangomolo.com/analytics/%s'),
|
||||
'duration': int_or_none(video_data.get('duration')),
|
||||
'timestamp': parse_iso8601(video_data.get('create_time'), ' '),
|
||||
'is_live': is_live,
|
||||
|
@ -1050,7 +1050,7 @@ def _download_webpage(
|
||||
self._sleep(timeout, video_id)
|
||||
|
||||
def report_warning(self, msg, video_id=None, *args, only_once=False, **kwargs):
|
||||
idstr = format_field(video_id, template='%s: ')
|
||||
idstr = format_field(video_id, None, '%s: ')
|
||||
msg = f'[{self.IE_NAME}] {idstr}{msg}'
|
||||
if only_once:
|
||||
if f'WARNING: {msg}' in self._printed_messages:
|
||||
@ -1096,7 +1096,7 @@ def raise_login_required(
|
||||
self.get_param('ignore_no_formats_error') or self.get_param('wait_for_video')):
|
||||
self.report_warning(msg)
|
||||
return
|
||||
msg += format_field(self._login_hint(method), template='. %s')
|
||||
msg += format_field(self._login_hint(method), None, '. %s')
|
||||
raise ExtractorError(msg, expected=True)
|
||||
|
||||
def raise_geo_restricted(
|
||||
|
@ -94,7 +94,7 @@ def _real_extract(self, url):
|
||||
owner = video_info.get('owner', {})
|
||||
uploader_id = owner.get('nsid')
|
||||
uploader_path = owner.get('path_alias') or uploader_id
|
||||
uploader_url = format_field(uploader_path, template='https://www.flickr.com/photos/%s/')
|
||||
uploader_url = format_field(uploader_path, None, 'https://www.flickr.com/photos/%s/')
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
|
@ -410,7 +410,7 @@ def _real_extract(self, url):
|
||||
if nodes:
|
||||
return self.playlist_result(
|
||||
self._extract_nodes(nodes, True), video_id,
|
||||
format_field(username, template='Post by %s'), description)
|
||||
format_field(username, None, 'Post by %s'), description)
|
||||
|
||||
video_url = self._og_search_video_url(webpage, secure=False)
|
||||
|
||||
|
@ -610,7 +610,7 @@ def _real_extract(self, url):
|
||||
preview_time = traverse_obj(
|
||||
initial_format_data, ('boss_ts', (None, 'data'), ('previewTime', 'rtime')), expected_type=float_or_none, get_all=False)
|
||||
if traverse_obj(initial_format_data, ('boss_ts', 'data', 'prv'), expected_type=int_or_none):
|
||||
self.report_warning('This preview video is limited%s' % format_field(preview_time, template=' to %s seconds'))
|
||||
self.report_warning('This preview video is limited%s' % format_field(preview_time, None, ' to %s seconds'))
|
||||
|
||||
# TODO: Extract audio-only formats
|
||||
for bid in set(traverse_obj(initial_format_data, ('program', 'video', ..., 'bid'), expected_type=str_or_none, default=[])):
|
||||
|
@ -70,7 +70,7 @@ def _real_extract(self, url):
|
||||
r'(\d+)[pP]\.', format_url, 'height', default=None)
|
||||
formats.append({
|
||||
'url': format_url,
|
||||
'format_id': format_field(height, template='%sp'),
|
||||
'format_id': format_field(height, None, '%sp'),
|
||||
'height': int(height),
|
||||
})
|
||||
if not formats:
|
||||
|
@ -68,7 +68,7 @@ def extract_format(format_url, height=None):
|
||||
video_url, title, 32).decode('utf-8')
|
||||
formats.append({
|
||||
'url': format_url,
|
||||
'format_id': format_field(height, template='%dp'),
|
||||
'format_id': format_field(height, None, '%dp'),
|
||||
'height': height,
|
||||
'tbr': tbr,
|
||||
})
|
||||
|
@ -15,7 +15,7 @@ def _entries(self, url, playlist_id):
|
||||
for page_number in range(start_page_number, (last_page_number or start_page_number) + 1):
|
||||
webpage = self._download_webpage(
|
||||
url, playlist_id,
|
||||
note='Downloading page %d%s' % (page_number, format_field(last_page_number, template=' of %d')),
|
||||
note='Downloading page %d%s' % (page_number, format_field(last_page_number, None, ' of %d')),
|
||||
query={'page': page_number})
|
||||
page_entries = [
|
||||
self.url_result(player_url, 'Youtube')
|
||||
|
@ -34,7 +34,7 @@ def _parse_broadcast_item(self, item):
|
||||
'timestamp': int_or_none(item.get('createdAt')),
|
||||
'channel': channel.get('name'),
|
||||
'channel_id': channel_id,
|
||||
'channel_url': format_field(channel_id, template='https://live.line.me/channels/%s'),
|
||||
'channel_url': format_field(channel_id, None, 'https://live.line.me/channels/%s'),
|
||||
'duration': int_or_none(item.get('archiveDuration')),
|
||||
'view_count': int_or_none(item.get('viewerCount')),
|
||||
'comment_count': int_or_none(item.get('chatCount')),
|
||||
|
@ -116,7 +116,7 @@ def add_item(container, item_url, height, id_key='format_id', item_id=None):
|
||||
author = try_get(
|
||||
hydration_data, lambda x: list(x['profiles'].values())[0], dict) or {}
|
||||
author_id = str_or_none(author.get('id'))
|
||||
author_url = format_field(author_id, template='https://medal.tv/users/%s')
|
||||
author_url = format_field(author_id, None, 'https://medal.tv/users/%s')
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
|
@ -118,7 +118,7 @@ def _real_extract(self, url):
|
||||
'timestamp': int_or_none(entity.get('time_created')),
|
||||
'uploader': strip_or_none(owner.get('name')),
|
||||
'uploader_id': uploader_id,
|
||||
'uploader_url': format_field(uploader_id, template='https://www.minds.com/%s'),
|
||||
'uploader_url': format_field(uploader_id, None, 'https://www.minds.com/%s'),
|
||||
'view_count': int_or_none(entity.get('play:count')),
|
||||
'like_count': int_or_none(entity.get('thumbs:up:count')),
|
||||
'dislike_count': int_or_none(entity.get('thumbs:down:count')),
|
||||
|
@ -429,7 +429,7 @@ def add_format(format_url, height=None):
|
||||
default=None))
|
||||
formats.append({
|
||||
'url': format_url,
|
||||
'format_id': format_field(height, template='%dp'),
|
||||
'format_id': format_field(height, None, '%dp'),
|
||||
'height': height,
|
||||
})
|
||||
|
||||
|
@ -80,7 +80,7 @@ def _real_extract(self, url):
|
||||
'release_timestamp': release_date,
|
||||
'channel': channel.get('name'),
|
||||
'channel_id': channel_id,
|
||||
'channel_url': format_field(channel_id, template='https://rad.live/content/channel/%s'),
|
||||
'channel_url': format_field(channel_id, None, 'https://rad.live/content/channel/%s'),
|
||||
|
||||
}
|
||||
if content_type == 'episode':
|
||||
|
@ -146,7 +146,7 @@ def _get_comments(self, video_id):
|
||||
for page_n in itertools.count():
|
||||
raw_comments = self._download_json(
|
||||
f'{_API_BASE_URL}comment?postId={video_id[5:]}&page={page_n}&size=50',
|
||||
video_id, note=f'Downloading viewer comments page {page_n + 1}{format_field(pages_total, template=" of %s")}',
|
||||
video_id, note=f'Downloading viewer comments page {page_n + 1}{format_field(pages_total, None, " of %s")}',
|
||||
fatal=False) or {}
|
||||
|
||||
for comment in raw_comments.get('content') or []:
|
||||
@ -318,7 +318,7 @@ def _entries(self, channel_id, channel_name, tab):
|
||||
data_url = f'{_API_BASE_URL}post/search/{tab}?page={page_n}&size=50&creator={channel_id}'
|
||||
metadata = self._download_json(
|
||||
data_url, channel_name,
|
||||
note=f'Downloading video metadata page {page_n + 1}{format_field(pages_total, template=" of %s")}')
|
||||
note=f'Downloading video metadata page {page_n + 1}{format_field(pages_total, None, " of %s")}')
|
||||
|
||||
yield from self._get_video_data(metadata)
|
||||
pages_total = int_or_none(metadata.get('totalPages')) or None
|
||||
@ -369,7 +369,7 @@ def _search_results(self, query):
|
||||
for page_number in itertools.count(1):
|
||||
search_results = self._run_search_query(
|
||||
query, data={'query': query, 'page': {'size': 100, 'current': page_number}},
|
||||
note=f'Downloading page {page_number}{format_field(total_pages, template=" of ~%s")}')
|
||||
note=f'Downloading page {page_number}{format_field(total_pages, None, " of ~%s")}')
|
||||
total_pages = traverse_obj(search_results, ('meta', 'page', 'total_pages'), expected_type=int_or_none)
|
||||
|
||||
for result in search_results.get('results') or []:
|
||||
|
@ -44,7 +44,7 @@ def _parse_video(self, video):
|
||||
'timestamp': int_or_none(video.get('publishDate')),
|
||||
'uploader': video.get('username'),
|
||||
'uploader_id': uploader_id,
|
||||
'uploader_url': format_field(uploader_id, template='https://storyfire.com/user/%s/video'),
|
||||
'uploader_url': format_field(uploader_id, None, 'https://storyfire.com/user/%s/video'),
|
||||
'episode_number': int_or_none(video.get('episodeNumber') or video.get('episode_number')),
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ def _extract_streamer_info(self, data):
|
||||
return {
|
||||
'uploader': streamer_info.get('nickName'),
|
||||
'uploader_id': str_or_none(streamer_info.get('uid')),
|
||||
'uploader_url': format_field(username, template='https://trovo.live/%s'),
|
||||
'uploader_url': format_field(username, None, 'https://trovo.live/%s'),
|
||||
}
|
||||
|
||||
|
||||
|
@ -470,7 +470,7 @@ def _real_extract(self, url):
|
||||
'uploader': uploader,
|
||||
'timestamp': unified_timestamp(status.get('created_at')),
|
||||
'uploader_id': uploader_id,
|
||||
'uploader_url': format_field(uploader_id, template='https://twitter.com/%s'),
|
||||
'uploader_url': format_field(uploader_id, None, 'https://twitter.com/%s'),
|
||||
'like_count': int_or_none(status.get('favorite_count')),
|
||||
'repost_count': int_or_none(status.get('retweet_count')),
|
||||
'comment_count': int_or_none(status.get('reply_count')),
|
||||
|
@ -152,7 +152,7 @@ def _real_extract(self, url):
|
||||
'uploader': user.get('name'),
|
||||
'timestamp': parse_iso8601(video.get('created_at')),
|
||||
'uploader_id': username,
|
||||
'uploader_url': format_field(username, template='https://www.vidio.com/@%s'),
|
||||
'uploader_url': format_field(username, None, 'https://www.vidio.com/@%s'),
|
||||
'channel': channel.get('name'),
|
||||
'channel_id': str_or_none(channel.get('id')),
|
||||
'view_count': get_count('view_count'),
|
||||
@ -283,5 +283,5 @@ def _real_extract(self, url):
|
||||
'uploader': user.get('name'),
|
||||
'timestamp': parse_iso8601(stream_meta.get('start_time')),
|
||||
'uploader_id': username,
|
||||
'uploader_url': format_field(username, template='https://www.vidio.com/@%s'),
|
||||
'uploader_url': format_field(username, None, 'https://www.vidio.com/@%s'),
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ def _real_extract(self, url):
|
||||
uploader = self._search_regex(
|
||||
r'<div[^>]+class=["\']wt_person[^>]+>\s*<a[^>]+\bhref=["\']/user/[^>]+>([^<]+)',
|
||||
webpage, 'uploader', fatal=False)
|
||||
uploader_url = format_field(uploader, template='https://www.vidlii.com/user/%s')
|
||||
uploader_url = format_field(uploader, None, 'https://www.vidlii.com/user/%s')
|
||||
|
||||
upload_date = unified_strdate(self._html_search_meta(
|
||||
'datePublished', webpage, default=None) or self._search_regex(
|
||||
|
@ -89,7 +89,7 @@ def video_url(kind):
|
||||
|
||||
username = data.get('username')
|
||||
|
||||
alt_title = format_field(username, template='Vine by %s')
|
||||
alt_title = format_field(username, None, 'Vine by %s')
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
|
@ -91,7 +91,7 @@ def _extract_moment(item, fatal=True):
|
||||
|
||||
uploader = try_get(item, lambda x: x['owner']['name'], compat_str)
|
||||
uploader_id = try_get(item, lambda x: x['owner']['userId'])
|
||||
uploader_url = format_field(uploader, template='https://www.younow.com/%s')
|
||||
uploader_url = format_field(uploader, None, 'https://www.younow.com/%s')
|
||||
|
||||
entry = {
|
||||
'extractor_key': 'YouNowMoment',
|
||||
|
@ -3555,7 +3555,7 @@ def feed_entry(name):
|
||||
'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None,
|
||||
'uploader_url': owner_profile_url,
|
||||
'channel_id': channel_id,
|
||||
'channel_url': format_field(channel_id, template='https://www.youtube.com/channel/%s'),
|
||||
'channel_url': format_field(channel_id, None, 'https://www.youtube.com/channel/%s'),
|
||||
'duration': duration,
|
||||
'view_count': int_or_none(
|
||||
get_first((video_details, microformats), (..., 'viewCount'))
|
||||
@ -3625,7 +3625,7 @@ def process_language(container, base_url, lang_code, sub_name, query):
|
||||
if 'translated_subs' in self._configuration_arg('skip'):
|
||||
continue
|
||||
trans_code += f'-{lang_code}'
|
||||
trans_name += format_field(lang_name, template=' from %s')
|
||||
trans_name += format_field(lang_name, None, ' from %s')
|
||||
# Add an "-orig" label to the original language so that it can be distinguished.
|
||||
# The subs are returned without "-orig" as well for compatibility
|
||||
if lang_code == f'a-{orig_trans_code}':
|
||||
|
@ -58,7 +58,7 @@ def _real_extract(self, url):
|
||||
'uploader': author.get('name'),
|
||||
'timestamp': int_or_none(zvideo.get('published_at')),
|
||||
'uploader_id': author.get('id'),
|
||||
'uploader_url': format_field(url_token, template='https://www.zhihu.com/people/%s'),
|
||||
'uploader_url': format_field(url_token, None, 'https://www.zhihu.com/people/%s'),
|
||||
'duration': float_or_none(video.get('duration')),
|
||||
'view_count': int_or_none(zvideo.get('play_count')),
|
||||
'like_count': int_or_none(zvideo.get('liked_count')),
|
||||
|
@ -1038,10 +1038,10 @@ def __init__(self, msg, tb=None, expected=False, cause=None, video_id=None, ie=N
|
||||
self.exc_info = sys.exc_info() # preserve original exception
|
||||
|
||||
super().__init__(''.join((
|
||||
format_field(ie, template='[%s] '),
|
||||
format_field(video_id, template='%s: '),
|
||||
format_field(ie, None, '[%s] '),
|
||||
format_field(video_id, None, '%s: '),
|
||||
msg,
|
||||
format_field(cause, template=' (caused by %r)'),
|
||||
format_field(cause, None, ' (caused by %r)'),
|
||||
'' if expected else bug_reports_message())))
|
||||
|
||||
def format_traceback(self):
|
||||
|
Loading…
Reference in New Issue
Block a user