into a single file
allow_multiple_audio_streams: Allow multiple audio streams to be merged
into a single file
+ check_formats Whether to test if the formats are downloadable.
+ Can be True (check all), False (check none)
+ or None (check only if requested by extractor)
paths: Dictionary of output paths. The allowed keys are 'home'
'temp' and the keys of OUTTMPL_TYPES (in utils.py)
outtmpl: Dictionary of templates for output names. Allowed keys
if True, otherwise use ffmpeg/avconv if False, otherwise
use downloader suggested by extractor if None.
compat_opts: Compatibility options. See "Differences in default behavior".
- Note that only format-sort, format-spec, no-live-chat,
- no-attach-info-json, playlist-index, list-formats,
- no-direct-merge, embed-thumbnail-atomicparsley,
- no-youtube-unavailable-videos, no-youtube-channel-redirect,
- works when used via the API
+ The following options do not work when used through the API:
+ filename, abort-on-error, multistreams, no-live-chat,
+ no-playlist-metafiles. Refer __init__.py for their implementation
The following parameters are not used by YoutubeDL itself, they are used by
the downloader (see yt_dlp/downloader/common.py):
params = None
_ies = []
_pps = {'pre_process': [], 'before_dl': [], 'after_move': [], 'post_process': []}
- __prepare_filename_warned = False
+ _reported_warnings = set()
_first_webpage_request = True
_download_retcode = None
_num_downloads = None
self._ies = []
self._ies_instances = {}
self._pps = {'pre_process': [], 'before_dl': [], 'after_move': [], 'post_process': []}
- self.__prepare_filename_warned = False
+ self._reported_warnings = set()
self._first_webpage_request = True
self._post_hooks = []
self._progress_hooks = []
self.to_stdout(
message, skip_eol, quiet=self.params.get('quiet', False))
- def report_warning(self, message):
+ def report_warning(self, message, only_once=False):
'''
Print the message to stderr, it will be prefixed with 'WARNING:'
If stderr is a tty file the 'WARNING:' will be colored
'''
+ if only_once:
+ if message in self._reported_warnings:
+ return
+ self._reported_warnings.add(message)
if self.params.get('logger') is not None:
self.params['logger'].warning(message)
else:
filename = self._prepare_filename(info_dict, dir_type or 'default')
- if warn and not self.__prepare_filename_warned:
+ if warn:
if not self.params.get('paths'):
pass
elif filename == '-':
- self.report_warning('--paths is ignored when an outputting to stdout')
+ self.report_warning('--paths is ignored when an outputting to stdout', only_once=True)
elif os.path.isabs(filename):
- self.report_warning('--paths is ignored since an absolute path is given in output template')
+ self.report_warning('--paths is ignored since an absolute path is given in output template', only_once=True)
self.__prepare_filename_warned = True
if filename == '-' or not filename:
return filename
if not isinstance(ie_entries, (list, PagedList)):
ie_entries = LazyList(ie_entries)
+ def get_entry(i):
+ return YoutubeDL.__handle_extraction_exceptions(
+ lambda self, i: ie_entries[i - 1]
+ )(self, i)
+
entries = []
for i in playlistitems or itertools.count(playliststart):
if playlistitems is None and playlistend is not None and playlistend < i:
break
entry = None
try:
- entry = ie_entries[i - 1]
+ entry = get_entry(i)
if entry is None:
raise EntryNotInPlaylist()
except (IndexError, EntryNotInPlaylist):
def _check_formats(formats):
if not check_formats:
yield from formats
+ return
for f in formats:
self.to_screen('[info] Testing format %s' % f['format_id'])
temp_file = tempfile.NamedTemporaryFile(
t.get('id') if t.get('id') is not None else '',
t.get('url')))
- def test_thumbnail(t):
- self.to_screen('[info] Testing thumbnail %s' % t['id'])
- try:
- self.urlopen(HEADRequest(t['url']))
- except network_exceptions as err:
- self.to_screen('[info] Unable to connect to thumbnail %s URL "%s" - %s. Skipping...' % (
- t['id'], t['url'], error_to_compat_str(err)))
- return False
- return True
+ def thumbnail_tester():
+ if self.params.get('check_formats'):
+ test_all = True
+ to_screen = lambda msg: self.to_screen(f'[info] {msg}')
+ else:
+ test_all = False
+ to_screen = self.write_debug
+
+ def test_thumbnail(t):
+ if not test_all and not t.get('_test_url'):
+ return True
+ to_screen('Testing thumbnail %s' % t['id'])
+ try:
+ self.urlopen(HEADRequest(t['url']))
+ except network_exceptions as err:
+ to_screen('Unable to connect to thumbnail %s URL "%s" - %s. Skipping...' % (
+ t['id'], t['url'], error_to_compat_str(err)))
+ return False
+ return True
+
+ return test_thumbnail
for i, t in enumerate(thumbnails):
if t.get('id') is None:
if t.get('width') and t.get('height'):
t['resolution'] = '%dx%d' % (t['width'], t['height'])
t['url'] = sanitize_url(t['url'])
- if self.params.get('check_formats'):
- info_dict['thumbnails'] = LazyList(filter(test_thumbnail, thumbnails[::-1])).reverse()
+
+ if self.params.get('check_formats') is not False:
+ info_dict['thumbnails'] = LazyList(filter(thumbnail_tester(), thumbnails[::-1])).reverse()
+ else:
+ info_dict['thumbnails'] = thumbnails
def process_video_result(self, info_dict, download=True):
assert info_dict.get('_type', 'video') == 'video'
requested_formats = info_dict['requested_formats']
old_ext = info_dict['ext']
- if self.params.get('merge_output_format') is None:
- if not compatible_formats(requested_formats):
- info_dict['ext'] = 'mkv'
- self.report_warning(
- 'Requested formats are incompatible for merge and will be merged into mkv.')
- if (info_dict['ext'] == 'webm'
- and self.params.get('writethumbnail', False)
- and info_dict.get('thumbnails')):
- info_dict['ext'] = 'mkv'
- self.report_warning(
- 'webm doesn\'t support embedding a thumbnail, mkv will be used.')
+ if self.params.get('merge_output_format') is None and not compatible_formats(requested_formats):
+ info_dict['ext'] = 'mkv'
+ self.report_warning(
+ 'Requested formats are incompatible for merge and will be merged into mkv.')
def correct_ext(filename):
filename_real_ext = os.path.splitext(filename)[1][1:]
res += '~' + format_bytes(fdict['filesize_approx'])
return res
- def _format_note_table(self, f):
- def join_fields(*vargs):
- return ', '.join((val for val in vargs if val != ''))
-
- return join_fields(
- 'UNSUPPORTED' if f.get('ext') in ('f4f', 'f4m') else '',
- format_field(f, 'language', '[%s]'),
- format_field(f, 'format_note'),
- format_field(f, 'container', ignore=(None, f.get('ext'))),
- format_field(f, 'asr', '%5dHz'))
-
def list_formats(self, info_dict):
formats = info_dict.get('formats', [info_dict])
new_format = (
format_field(f, 'acodec', default='unknown').replace('none', ''),
format_field(f, 'abr', '%3dk'),
format_field(f, 'asr', '%5dHz'),
- self._format_note_table(f)]
- for f in formats
- if f.get('preference') is None or f['preference'] >= -1000]
+ ', '.join(filter(None, (
+ 'UNSUPPORTED' if f.get('ext') in ('f4f', 'f4m') else '',
+ format_field(f, 'language', '[%s]'),
+ format_field(f, 'format_note'),
+ format_field(f, 'container', ignore=(None, f.get('ext'))),
+ format_field(f, 'asr', '%5dHz')))),
+ ] for f in formats if f.get('preference') is None or f['preference'] >= -1000]
header_line = ['ID', 'EXT', 'RESOLUTION', 'FPS', '|', ' FILESIZE', ' TBR', 'PROTO',
- '|', 'VCODEC', ' VBR', 'ACODEC', ' ABR', ' ASR', 'NOTE']
+ '|', 'VCODEC', ' VBR', 'ACODEC', ' ABR', ' ASR', 'MORE INFO']
else:
table = [
[
self.to_screen(
'[info] Available formats for %s:' % info_dict['id'])
self.to_stdout(render_table(
- header_line,
- table,
- delim=new_format,
- extraGap=(0 if new_format else 1),
- hideEmpty=new_format))
+ header_line, table, delim=new_format, extraGap=(0 if new_format else 1), hideEmpty=new_format))
def list_thumbnails(self, info_dict):
thumbnails = list(info_dict.get('thumbnails'))