0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-26 02:55:17 +00:00

Improve --clean-infojson

It should not removes fields that may be needed for `--load-infojson`.
Eg: `_ffmpeg_args`, `_has_drm`
This commit is contained in:
pukkandan 2022-04-27 21:52:57 +05:30
parent 4877f9055c
commit 0a5a191a2a
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39
7 changed files with 21 additions and 15 deletions

View file

@ -661,7 +661,7 @@ def test_add_extra_info(self):
'duration': 100000,
'playlist_index': 1,
'playlist_autonumber': 2,
'_last_playlist_index': 100,
'__last_playlist_index': 100,
'n_entries': 10,
'formats': [{'id': 'id 1'}, {'id': 'id 2'}, {'id': 'id 3'}]
}

View file

@ -954,7 +954,7 @@ def report_file_delete(self, file_name):
self.to_screen('Deleting existing file')
def raise_no_formats(self, info, forced=False, *, msg=None):
has_drm = info.get('__has_drm')
has_drm = info.get('_has_drm')
ignored, expected = self.params.get('ignore_no_formats_error'), bool(msg)
msg = msg or has_drm and 'This video is DRM protected' or 'No video formats found!'
if forced or not ignored:
@ -1052,7 +1052,7 @@ def prepare_outtmpl(self, outtmpl, info_dict, sanitize=False):
# For fields playlist_index, playlist_autonumber and autonumber convert all occurrences
# of %(field)s to %(field)0Nd for backward compatibility
field_size_compat_map = {
'playlist_index': number_of_digits(info_dict.get('_last_playlist_index') or 0),
'playlist_index': number_of_digits(info_dict.get('__last_playlist_index') or 0),
'playlist_autonumber': number_of_digits(info_dict.get('n_entries') or 0),
'autonumber': self.params.get('autonumber_size') or 5,
}
@ -1764,7 +1764,7 @@ def get_entry(i):
entry['__x_forwarded_for_ip'] = x_forwarded_for
extra = {
'n_entries': n_entries,
'_last_playlist_index': max(playlistitems) if playlistitems else (playlistend or n_entries),
'__last_playlist_index': max(playlistitems) if playlistitems else (playlistend or n_entries),
'playlist_count': ie_result.get('playlist_count'),
'playlist_index': playlist_index,
'playlist_autonumber': i,
@ -2436,10 +2436,11 @@ def sanitize_numeric_fields(info):
else:
formats = info_dict['formats']
info_dict['__has_drm'] = any(f.get('has_drm') for f in formats)
# or None ensures --clean-infojson removes it
info_dict['_has_drm'] = any(f.get('has_drm') for f in formats) or None
if not self.params.get('allow_unplayable_formats'):
formats = [f for f in formats if not f.get('has_drm')]
if info_dict['__has_drm'] and all(
if info_dict['_has_drm'] and all(
f.get('acodec') == f.get('vcodec') == 'none' for f in formats):
self.report_warning(
'This video is DRM protected and only images are available for download. '
@ -3266,9 +3267,9 @@ def sanitize_info(info_dict, remove_private_keys=False):
info_dict.setdefault('_type', 'video')
if remove_private_keys:
reject = lambda k, v: v is None or (k.startswith('_') and k != '_type') or k in {
reject = lambda k, v: v is None or k.startswith('__') or k in {
'requested_downloads', 'requested_formats', 'requested_subtitles', 'requested_entries',
'entries', 'filepath', 'infojson_filename', 'original_url', 'playlist_autonumber',
'entries', 'filepath', '_filename', 'infojson_filename', 'original_url', 'playlist_autonumber',
}
else:
reject = lambda k, v: False

View file

@ -20,6 +20,7 @@
encodeFilename,
handle_youtubedl_headers,
remove_end,
traverse_obj,
)
@ -363,9 +364,11 @@ def _call_downloader(self, tmpfilename, info_dict):
if not self.params.get('verbose'):
args += ['-hide_banner']
args += info_dict.get('_ffmpeg_args', [])
args += traverse_obj(info_dict, ('downloader_options', 'ffmpeg_args'), default=[])
# This option exists only for compatibility. Extractors should use `_ffmpeg_args` instead
# These exists only for compatibility. Extractors should use
# info_dict['downloader_options']['ffmpeg_args'] instead
args += info_dict.get('_ffmpeg_args')
seekable = info_dict.get('_seekable')
if seekable is not None:
# setting -seekable prevents ffmpeg from guessing if the server

View file

@ -208,8 +208,10 @@ class InfoExtractor:
* no_resume The server does not support resuming the
(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 (For internal use only)
* downloader_options A dictionary of downloader options
(For internal use only)
* http_chunk_size Chunk size for HTTP downloads
* ffmpeg_args Extra arguments for ffmpeg downloader
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

View file

@ -579,7 +579,7 @@ def _real_extract(self, url):
for f in formats:
# -http_seekable requires ffmpeg 4.3+ but it doesnt seem possible to
# download with ffmpeg without this option
f['_ffmpeg_args'] = ['-seekable', '0', '-http_seekable', '0', '-icy', '0']
f['downloader_options'] = {'ffmpeg_args': ['-seekable', '0', '-http_seekable', '0', '-icy', '0']}
self._sort_formats(formats)
return {

View file

@ -125,7 +125,7 @@ def _extract_formats(self, video_id, station, is_onair, ft, cursor, auth_token,
# Prioritize live radio vs playback based on extractor
sf['preference'] = 100 if is_onair else -100
if not is_onair and url_attrib['timefree'] == '1' and time_to_skip:
sf['_ffmpeg_args'] = ['-ss', time_to_skip]
sf['downloader_options'] = {'ffmpeg_args': ['-ss', time_to_skip]}
formats.extend(subformats)
self._sort_formats(formats)

View file

@ -141,7 +141,7 @@ def _extract_cvp_info(self, data_src, video_id, path_data={}, ap_data={}, fatal=
m3u8_id=format_id or 'hls', fatal=False)
if '/secure/' in video_url and '?hdnea=' in video_url:
for f in m3u8_formats:
f['_ffmpeg_args'] = ['-seekable', '0']
f['downloader_options'] = {'ffmpeg_args': ['-seekable', '0']}
formats.extend(m3u8_formats)
elif ext == 'f4m':
formats.extend(self._extract_f4m_formats(