1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2026-02-21 16:06:13 +00:00

[cleanup] Misc cleanup

This commit is contained in:
pukkandan
2022-01-04 01:07:24 +05:30
parent 21df2117e4
commit 9e907ebddf
8 changed files with 47 additions and 44 deletions

View File

@@ -1161,7 +1161,7 @@ class YoutubeDL(object):
str_fmt = f'{fmt[:-1]}s'
if fmt[-1] == 'l': # list
delim = '\n' if '#' in flags else ', '
value, fmt = delim.join(variadic(value, allowed_types=(str, bytes))), str_fmt
value, fmt = delim.join(map(str, variadic(value, allowed_types=(str, bytes)))), str_fmt
elif fmt[-1] == 'j': # json
value, fmt = json.dumps(value, default=_dumpjson_default, indent=4 if '#' in flags else None), str_fmt
elif fmt[-1] == 'q': # quoted
@@ -2396,6 +2396,9 @@ class YoutubeDL(object):
if not get_from_start:
info_dict['title'] += ' ' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
# backward compatibility
info_dict['fulltitle'] = info_dict['title']
if not formats:
self.raise_no_formats(info_dict)
@@ -2584,7 +2587,7 @@ class YoutubeDL(object):
if max_downloads_reached:
break
write_archive = set(f.get('_write_download_archive', False) for f in formats_to_download)
write_archive = set(f.get('__write_download_archive', False) for f in formats_to_download)
assert write_archive.issubset({True, False, 'ignore'})
if True in write_archive and False not in write_archive:
self.record_download_archive(info_dict)
@@ -2754,14 +2757,11 @@ class YoutubeDL(object):
assert info_dict.get('_type', 'video') == 'video'
original_infodict = info_dict
# TODO: backward compatibility, to be removed
info_dict['fulltitle'] = info_dict['title']
if 'format' not in info_dict and 'ext' in info_dict:
info_dict['format'] = info_dict['ext']
if self._match_entry(info_dict) is not None:
info_dict['_write_download_archive'] = 'ignore'
info_dict['__write_download_archive'] = 'ignore'
return
self.post_extract(info_dict)
@@ -2776,7 +2776,7 @@ class YoutubeDL(object):
self.__forced_printings(info_dict, full_filename, incomplete=('format' not in info_dict))
if self.params.get('simulate'):
info_dict['_write_download_archive'] = self.params.get('force_write_download_archive')
info_dict['__write_download_archive'] = self.params.get('force_write_download_archive')
return
if full_filename is None:
@@ -2890,7 +2890,7 @@ class YoutubeDL(object):
info_dict['__finaldir'] = os.path.dirname(os.path.abspath(encodeFilename(full_filename)))
info_dict['__files_to_move'] = files_to_move
replace_info_dict(self.run_pp(MoveFilesAfterDownloadPP(self, False), info_dict))
info_dict['_write_download_archive'] = self.params.get('force_write_download_archive')
info_dict['__write_download_archive'] = self.params.get('force_write_download_archive')
else:
# Download
info_dict.setdefault('__postprocessors', [])
@@ -3119,10 +3119,10 @@ class YoutubeDL(object):
except Exception as err:
self.report_error('post hooks: %s' % str(err))
return
info_dict['_write_download_archive'] = True
info_dict['__write_download_archive'] = True
if self.params.get('force_write_download_archive'):
info_dict['_write_download_archive'] = True
info_dict['__write_download_archive'] = True
# Make sure the info_dict was modified in-place
assert info_dict is original_infodict

View File

@@ -110,6 +110,8 @@ class Zee5IE(InfoExtractor):
raise ExtractorError(otp_request_json['message'], expected=True)
elif username.lower() == 'token' and len(password) > 1198:
self._USER_TOKEN = password
else:
raise ExtractorError(self._LOGIN_HINT, expected=True)
def _real_initialize(self):
self._login()

View File

@@ -137,7 +137,7 @@ def create_parser():
def _list_from_options_callback(option, opt_str, value, parser, append=True, delim=',', process=str.strip):
# append can be True, False or -1 (prepend)
current = getattr(parser.values, option.dest) if append else []
current = list(getattr(parser.values, option.dest)) if append else []
value = list(filter(None, [process(value)] if delim is None else map(process, value.split(delim))))
setattr(
parser.values, option.dest,
@@ -146,7 +146,7 @@ def create_parser():
def _set_from_options_callback(
option, opt_str, value, parser, delim=',', allowed_values=None, aliases={},
process=lambda x: x.lower().strip()):
current = getattr(parser.values, option.dest)
current = set(getattr(parser.values, option.dest))
values = [process(value)] if delim is None else list(map(process, value.split(delim)[::-1]))
while values:
actual_val = val = values.pop()
@@ -261,7 +261,7 @@ def create_parser():
'--ignore-config', '--no-config',
action='store_true', dest='ignoreconfig',
help=(
'Disable loading any further configuration files except the one provided by --config-locations. '
'Don\'t load any more configuration files except those given by --config-locations. '
'For backward compatibility, if this option is found inside the system configuration file, the user configuration is not loaded'))
general.add_option(
'--no-config-locations',
@@ -286,7 +286,7 @@ def create_parser():
general.add_option(
'--live-from-start',
action='store_true', dest='live_from_start',
help='Download livestreams from the start. Currently only supported for YouTube')
help='Download livestreams from the start. Currently only supported for YouTube (Experimental)')
general.add_option(
'--no-live-from-start',
action='store_false', dest='live_from_start',
@@ -811,7 +811,7 @@ def create_parser():
metavar='NAME:ARGS', dest='external_downloader_args', default={}, type='str',
action='callback', callback=_dict_from_options_callback,
callback_kwargs={
'allowed_keys': r'ffmpeg_[io]\d*|%s' % '|'.join(list_external_downloaders()),
'allowed_keys': r'ffmpeg_[io]\d*|%s' % '|'.join(map(re.escape, list_external_downloaders())),
'default_key': 'default',
'process': compat_shlex_split
}, help=(
@@ -1050,7 +1050,7 @@ def create_parser():
metavar='[TYPES:]PATH', dest='paths', default={}, type='str',
action='callback', callback=_dict_from_options_callback,
callback_kwargs={
'allowed_keys': 'home|temp|%s' % '|'.join(OUTTMPL_TYPES.keys()),
'allowed_keys': 'home|temp|%s' % '|'.join(map(re.escape, OUTTMPL_TYPES.keys())),
'default_key': 'home'
}, help=(
'The paths where the files should be downloaded. '
@@ -1065,7 +1065,7 @@ def create_parser():
metavar='[TYPES:]TEMPLATE', dest='outtmpl', default={}, type='str',
action='callback', callback=_dict_from_options_callback,
callback_kwargs={
'allowed_keys': '|'.join(OUTTMPL_TYPES.keys()),
'allowed_keys': '|'.join(map(re.escape, OUTTMPL_TYPES.keys())),
'default_key': 'default'
}, help='Output filename template; see "OUTPUT TEMPLATE" for details')
filesystem.add_option(
@@ -1302,7 +1302,8 @@ def create_parser():
metavar='NAME:ARGS', dest='postprocessor_args', default={}, type='str',
action='callback', callback=_dict_from_options_callback,
callback_kwargs={
'allowed_keys': r'\w+(?:\+\w+)?', 'default_key': 'default-compat',
'allowed_keys': r'\w+(?:\+\w+)?',
'default_key': 'default-compat',
'process': compat_shlex_split,
'multiple_keys': False
}, help=(

View File

@@ -2381,13 +2381,8 @@ class PUTRequest(compat_urllib_request.Request):
def int_or_none(v, scale=1, default=None, get_attr=None, invscale=1):
if get_attr:
if v is not None:
v = getattr(v, get_attr, None)
if v == '':
v = None
if v is None:
return default
if get_attr and v is not None:
v = getattr(v, get_attr, None)
try:
return int(v) * invscale // scale
except (ValueError, TypeError, OverflowError):
@@ -5036,7 +5031,6 @@ def traverse_obj(
return default
# Deprecated
def traverse_dict(dictn, keys, casesense=True):
write_string('DeprecationWarning: yt_dlp.utils.traverse_dict is deprecated '
'and may be removed in a future version. Use yt_dlp.utils.traverse_obj instead')