[cleanup] Misc cleanup

This commit is contained in:
pukkandan
2021-10-09 05:53:15 +05:30
parent 4e3b637d5b
commit b5ae35ee6d
25 changed files with 142 additions and 136 deletions

View File

@@ -9,6 +9,7 @@ import copy
import datetime
import errno
import fileinput
import functools
import io
import itertools
import json
@@ -330,7 +331,8 @@ class YoutubeDL(object):
* when: When to run the postprocessor. Can be one of
pre_process|before_dl|post_process|after_move.
Assumed to be 'post_process' if not given
post_hooks: A list of functions that get called as the final step
post_hooks: Deprecated - Register a custom postprocessor instead
A list of functions that get called as the final step
for each video file, after all postprocessors have been
called. The filename will be passed as the only argument.
progress_hooks: A list of functions that get called on download
@@ -423,7 +425,7 @@ class YoutubeDL(object):
use downloader suggested by extractor if None.
compat_opts: Compatibility options. See "Differences in default behavior".
The following options do not work when used through the API:
filename, abort-on-error, multistreams, no-live-chat,
filename, abort-on-error, multistreams, no-live-chat, format-sort
no-clean-infojson, no-playlist-metafiles, no-keep-subs.
Refer __init__.py for their implementation
progress_template: Dictionary of templates for progress outputs.
@@ -434,8 +436,9 @@ class YoutubeDL(object):
The following parameters are not used by YoutubeDL itself, they are used by
the downloader (see yt_dlp/downloader/common.py):
nopart, updatetime, buffersize, ratelimit, throttledratelimit, min_filesize,
max_filesize, test, noresizebuffer, retries, continuedl, noprogress,
xattr_set_filesize, external_downloader_args, hls_use_mpegts, http_chunk_size.
max_filesize, test, noresizebuffer, retries, fragment_retries, continuedl,
noprogress, xattr_set_filesize, hls_use_mpegts, http_chunk_size,
external_downloader_args.
The following options are used by the post processors:
prefer_ffmpeg: If False, use avconv instead of ffmpeg if both are available,
@@ -541,13 +544,13 @@ class YoutubeDL(object):
for msg in self.params.get('warnings', []):
self.report_warning(msg)
if self.params.get('overwrites') is None:
self.params.pop('overwrites', None)
elif self.params.get('nooverwrites') is not None:
if 'overwrites' not in self.params and self.params.get('nooverwrites') is not None:
# nooverwrites was unnecessarily changed to overwrites
# in 0c3d0f51778b153f65c21906031c2e091fcfb641
# This ensures compatibility with both keys
self.params['overwrites'] = not self.params['nooverwrites']
elif self.params.get('overwrites') is None:
self.params.pop('overwrites', None)
else:
self.params['nooverwrites'] = not self.params['overwrites']
@@ -1253,7 +1256,7 @@ class YoutubeDL(object):
self.report_error('no suitable InfoExtractor for URL %s' % url)
def __handle_extraction_exceptions(func):
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
@@ -1973,7 +1976,7 @@ class YoutubeDL(object):
elif format_spec in ('mhtml', ): # storyboards extension
filter_f = lambda f: f.get('ext') == format_spec and f.get('acodec') == 'none' and f.get('vcodec') == 'none'
else:
filter_f = (lambda f: f.get('format_id') == format_spec) # id
filter_f = lambda f: f.get('format_id') == format_spec # id
def selector_function(ctx):
formats = list(ctx['formats'])
@@ -2453,8 +2456,12 @@ class YoutubeDL(object):
if self.params.get('forceprint') or self.params.get('forcejson'):
self.post_extract(info_dict)
for tmpl in self.params.get('forceprint', []):
self.to_stdout(self.evaluate_outtmpl(
f'%({tmpl})s' if re.match(r'\w+$', tmpl) else tmpl, info_dict))
mobj = re.match(r'\w+(=?)$', tmpl)
if mobj and mobj.group(1):
tmpl = f'{tmpl[:-1]} = %({tmpl[:-1]})s'
elif mobj:
tmpl = '%({})s'.format(tmpl)
self.to_stdout(self.evaluate_outtmpl(tmpl, info_dict))
print_mandatory('title')
print_mandatory('id')

View File

@@ -735,10 +735,6 @@ def _real_main(argv=None):
'geo_bypass_ip_block': opts.geo_bypass_ip_block,
'warnings': warnings,
'compat_opts': compat_opts,
# just for deprecation check
'autonumber': opts.autonumber or None,
'usetitle': opts.usetitle or None,
'useid': opts.useid or None,
}
with YoutubeDL(ydl_opts) as ydl:

View File

@@ -48,8 +48,8 @@ class HttpFD(FileDownloader):
is_test = self.params.get('test', False)
chunk_size = self._TEST_FILE_SIZE if is_test else (
self.params.get('http_chunk_size') or
info_dict.get('downloader_options', {}).get('http_chunk_size')
self.params.get('http_chunk_size')
or info_dict.get('downloader_options', {}).get('http_chunk_size')
or 0)
ctx.open_mode = 'wb'

View File

@@ -1678,7 +1678,7 @@ class InfoExtractor(object):
has_multiple_limits = has_limit and has_multiple_fields and not self._get_field_setting(field, 'same_limit')
fields = self._get_field_setting(field, 'field') if has_multiple_fields else (field,)
limits = limit_text.split(":") if has_multiple_limits else (limit_text,) if has_limit else tuple()
limits = limit_text.split(':') if has_multiple_limits else (limit_text,) if has_limit else tuple()
limit_count = len(limits)
for (i, f) in enumerate(fields):
add_item(f, reverse, closest,
@@ -1762,9 +1762,9 @@ class InfoExtractor(object):
if format.get('vbr') is not None and format.get('abr') is not None:
format['tbr'] = format.get('vbr', 0) + format.get('abr', 0)
else:
if format.get('vcodec') != "none" and format.get('vbr') is None:
if format.get('vcodec') != 'none' and format.get('vbr') is None:
format['vbr'] = format.get('tbr') - format.get('abr', 0)
if format.get('acodec') != "none" and format.get('abr') is None:
if format.get('acodec') != 'none' and format.get('abr') is None:
format['abr'] = format.get('tbr') - format.get('vbr', 0)
return tuple(self._calculate_field_preference(format, field) for field in self._order)
@@ -1966,13 +1966,16 @@ class InfoExtractor(object):
'format_note': 'Quality selection URL',
}
def _report_ignoring_subs(self, name):
self.report_warning(bug_reports_message(
f'Ignoring subtitle tracks found in the {name} manifest; '
'if any subtitle tracks are missing,'
), only_once=True)
def _extract_m3u8_formats(self, *args, **kwargs):
fmts, subs = self._extract_m3u8_formats_and_subtitles(*args, **kwargs)
if subs:
self.report_warning(bug_reports_message(
"Ignoring subtitle tracks found in the HLS manifest; "
"if any subtitle tracks are missing,"
), only_once=True)
self._report_ignoring_subs('HLS')
return fmts
def _extract_m3u8_formats_and_subtitles(
@@ -2270,10 +2273,7 @@ class InfoExtractor(object):
def _extract_smil_formats(self, *args, **kwargs):
fmts, subs = self._extract_smil_formats_and_subtitles(*args, **kwargs)
if subs:
self.report_warning(bug_reports_message(
"Ignoring subtitle tracks found in the SMIL manifest; "
"if any subtitle tracks are missing,"
), only_once=True)
self._report_ignoring_subs('SMIL')
return fmts
def _extract_smil_info(self, smil_url, video_id, fatal=True, f4m_params=None):
@@ -2515,10 +2515,7 @@ class InfoExtractor(object):
def _extract_mpd_formats(self, *args, **kwargs):
fmts, subs = self._extract_mpd_formats_and_subtitles(*args, **kwargs)
if subs:
self.report_warning(bug_reports_message(
"Ignoring subtitle tracks found in the DASH manifest; "
"if any subtitle tracks are missing,"
), only_once=True)
self._report_ignoring_subs('DASH')
return fmts
def _extract_mpd_formats_and_subtitles(
@@ -2542,10 +2539,7 @@ class InfoExtractor(object):
def _parse_mpd_formats(self, *args, **kwargs):
fmts, subs = self._parse_mpd_formats_and_subtitles(*args, **kwargs)
if subs:
self.report_warning(bug_reports_message(
"Ignoring subtitle tracks found in the DASH manifest; "
"if any subtitle tracks are missing,"
), only_once=True)
self._report_ignoring_subs('DASH')
return fmts
def _parse_mpd_formats_and_subtitles(
@@ -2873,10 +2867,7 @@ class InfoExtractor(object):
def _extract_ism_formats(self, *args, **kwargs):
fmts, subs = self._extract_ism_formats_and_subtitles(*args, **kwargs)
if subs:
self.report_warning(bug_reports_message(
"Ignoring subtitle tracks found in the ISM manifest; "
"if any subtitle tracks are missing,"
))
self._report_ignoring_subs('ISM')
return fmts
def _extract_ism_formats_and_subtitles(self, ism_url, video_id, ism_id=None, note=None, errnote=None, fatal=True, data=None, headers={}, query={}):
@@ -3136,10 +3127,7 @@ class InfoExtractor(object):
def _extract_akamai_formats(self, *args, **kwargs):
fmts, subs = self._extract_akamai_formats_and_subtitles(*args, **kwargs)
if subs:
self.report_warning(bug_reports_message(
"Ignoring subtitle tracks found in the manifests; "
"if any subtitle tracks are missing,"
))
self._report_ignoring_subs('akamai')
return fmts
def _extract_akamai_formats_and_subtitles(self, manifest_url, video_id, hosts={}):

View File

@@ -93,7 +93,7 @@ class HiDiveIE(InfoExtractor):
raise ExtractorError(
'%s said: %s' % (self.IE_NAME, restriction), expected=True)
formats, subtitles, parsed_urls = [], {}, {None}
formats, parsed_urls = [], {}, {None}
for rendition_id, rendition in settings['renditions'].items():
audio, version, extra = rendition_id.split('_')
m3u8_url = url_or_none(try_get(rendition, lambda x: x['bitrates']['hls']))
@@ -105,14 +105,12 @@ class HiDiveIE(InfoExtractor):
f['language'] = audio
f['format_note'] = f'{version}, {extra}'
formats.extend(frmt)
self._extract_subtitles_from_rendition(rendition, subtitles, parsed_urls)
self._sort_formats(formats)
return {
'id': video_id,
'title': video_id,
'subtitles': self.extract_subtitles(url, video_id, title, key, subtitles, parsed_urls),
'subtitles': self.extract_subtitles(url, video_id, title, key, parsed_urls),
'formats': formats,
'series': title,
'season_number': int_or_none(

View File

@@ -37,7 +37,7 @@ class MinotoIE(InfoExtractor):
'filesize': int_or_none(fmt.get('filesize')),
'width': int_or_none(fmt.get('width')),
'height': int_or_none(fmt.get('height')),
'codecs': parse_codecs(fmt.get('codecs')),
**parse_codecs(fmt.get('codecs')),
})
self._sort_formats(formats)

View File

@@ -108,7 +108,7 @@ class PalcoMP3ArtistIE(PalcoMP3BaseIE):
}
name'''
@ classmethod
@classmethod
def suitable(cls, url):
return False if PalcoMP3IE._match_valid_url(url) else super(PalcoMP3ArtistIE, cls).suitable(url)

View File

@@ -1,3 +1,4 @@
import functools
from threading import Lock
from .utils import supports_terminal_sequences, TERMINAL_SEQUENCES
@@ -49,6 +50,7 @@ class MultilinePrinter(MultilinePrinterBase):
self._HAVE_FULLCAP = supports_terminal_sequences(self.stream)
def lock(func):
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
with self._movelock:
return func(self, *args, **kwargs)

View File

@@ -971,9 +971,6 @@ def parseOpts(overrideArguments=None):
dest='batchfile', metavar='FILE',
help="File containing URLs to download ('-' for stdin), one URL per line. "
"Lines starting with '#', ';' or ']' are considered as comments and ignored")
filesystem.add_option(
'--id', default=False,
action='store_true', dest='useid', help=optparse.SUPPRESS_HELP)
filesystem.add_option(
'-P', '--paths',
metavar='[TYPES:]PATH', dest='paths', default={}, type='str',
@@ -1029,18 +1026,6 @@ def parseOpts(overrideArguments=None):
'--trim-filenames', '--trim-file-names', metavar='LENGTH',
dest='trim_file_name', default=0, type=int,
help='Limit the filename length (excluding extension) to the specified number of characters')
filesystem.add_option(
'--auto-number',
action='store_true', dest='autonumber', default=False,
help=optparse.SUPPRESS_HELP)
filesystem.add_option(
'--title',
action='store_true', dest='usetitle', default=False,
help=optparse.SUPPRESS_HELP)
filesystem.add_option(
'--literal', default=False,
action='store_true', dest='usetitle',
help=optparse.SUPPRESS_HELP)
filesystem.add_option(
'-w', '--no-overwrites',
action='store_false', dest='overwrites', default=None,
@@ -1625,7 +1610,7 @@ def parseOpts(overrideArguments=None):
argv = configs['system'] + configs['user'] + configs['home'] + configs['portable'] + configs['custom'] + configs['command-line']
opts, args = parser.parse_args(argv)
if opts.verbose:
for label in ('System', 'User', 'Portable', 'Home', 'Custom', 'Command-line'):
for label in ('Command-line', 'Custom', 'Portable', 'Home', 'User', 'System'):
key = label.lower()
if paths.get(key):
write_string(f'[debug] {label} config file: {paths[key]}\n')