mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-12-26 21:59:08 +01: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:
parent
4877f9055c
commit
0a5a191a2a
7 changed files with 21 additions and 15 deletions
|
@ -661,7 +661,7 @@ class TestYoutubeDL(unittest.TestCase):
|
||||||
'duration': 100000,
|
'duration': 100000,
|
||||||
'playlist_index': 1,
|
'playlist_index': 1,
|
||||||
'playlist_autonumber': 2,
|
'playlist_autonumber': 2,
|
||||||
'_last_playlist_index': 100,
|
'__last_playlist_index': 100,
|
||||||
'n_entries': 10,
|
'n_entries': 10,
|
||||||
'formats': [{'id': 'id 1'}, {'id': 'id 2'}, {'id': 'id 3'}]
|
'formats': [{'id': 'id 1'}, {'id': 'id 2'}, {'id': 'id 3'}]
|
||||||
}
|
}
|
||||||
|
|
|
@ -954,7 +954,7 @@ class YoutubeDL:
|
||||||
self.to_screen('Deleting existing file')
|
self.to_screen('Deleting existing file')
|
||||||
|
|
||||||
def raise_no_formats(self, info, forced=False, *, msg=None):
|
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)
|
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!'
|
msg = msg or has_drm and 'This video is DRM protected' or 'No video formats found!'
|
||||||
if forced or not ignored:
|
if forced or not ignored:
|
||||||
|
@ -1052,7 +1052,7 @@ class YoutubeDL:
|
||||||
# For fields playlist_index, playlist_autonumber and autonumber convert all occurrences
|
# For fields playlist_index, playlist_autonumber and autonumber convert all occurrences
|
||||||
# of %(field)s to %(field)0Nd for backward compatibility
|
# of %(field)s to %(field)0Nd for backward compatibility
|
||||||
field_size_compat_map = {
|
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),
|
'playlist_autonumber': number_of_digits(info_dict.get('n_entries') or 0),
|
||||||
'autonumber': self.params.get('autonumber_size') or 5,
|
'autonumber': self.params.get('autonumber_size') or 5,
|
||||||
}
|
}
|
||||||
|
@ -1764,7 +1764,7 @@ class YoutubeDL:
|
||||||
entry['__x_forwarded_for_ip'] = x_forwarded_for
|
entry['__x_forwarded_for_ip'] = x_forwarded_for
|
||||||
extra = {
|
extra = {
|
||||||
'n_entries': n_entries,
|
'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_count': ie_result.get('playlist_count'),
|
||||||
'playlist_index': playlist_index,
|
'playlist_index': playlist_index,
|
||||||
'playlist_autonumber': i,
|
'playlist_autonumber': i,
|
||||||
|
@ -2436,10 +2436,11 @@ class YoutubeDL:
|
||||||
else:
|
else:
|
||||||
formats = info_dict['formats']
|
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'):
|
if not self.params.get('allow_unplayable_formats'):
|
||||||
formats = [f for f in formats if not f.get('has_drm')]
|
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):
|
f.get('acodec') == f.get('vcodec') == 'none' for f in formats):
|
||||||
self.report_warning(
|
self.report_warning(
|
||||||
'This video is DRM protected and only images are available for download. '
|
'This video is DRM protected and only images are available for download. '
|
||||||
|
@ -3266,9 +3267,9 @@ class YoutubeDL:
|
||||||
info_dict.setdefault('_type', 'video')
|
info_dict.setdefault('_type', 'video')
|
||||||
|
|
||||||
if remove_private_keys:
|
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',
|
'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:
|
else:
|
||||||
reject = lambda k, v: False
|
reject = lambda k, v: False
|
||||||
|
|
|
@ -20,6 +20,7 @@ from ..utils import (
|
||||||
encodeFilename,
|
encodeFilename,
|
||||||
handle_youtubedl_headers,
|
handle_youtubedl_headers,
|
||||||
remove_end,
|
remove_end,
|
||||||
|
traverse_obj,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -363,9 +364,11 @@ class FFmpegFD(ExternalFD):
|
||||||
if not self.params.get('verbose'):
|
if not self.params.get('verbose'):
|
||||||
args += ['-hide_banner']
|
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')
|
seekable = info_dict.get('_seekable')
|
||||||
if seekable is not None:
|
if seekable is not None:
|
||||||
# setting -seekable prevents ffmpeg from guessing if the server
|
# setting -seekable prevents ffmpeg from guessing if the server
|
||||||
|
|
|
@ -208,8 +208,10 @@ class InfoExtractor:
|
||||||
* no_resume The server does not support resuming the
|
* no_resume The server does not support resuming the
|
||||||
(HTTP or RTMP) download. Boolean.
|
(HTTP or RTMP) download. Boolean.
|
||||||
* has_drm The format has DRM and cannot be downloaded. Boolean
|
* has_drm The format has DRM and cannot be downloaded. Boolean
|
||||||
* downloader_options A dictionary of downloader options as
|
* downloader_options A dictionary of downloader options
|
||||||
described in FileDownloader (For internal use only)
|
(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,
|
RTMP formats can also have the additional fields: page_url,
|
||||||
app, play_path, tc_url, flash_version, rtmp_live, rtmp_conn,
|
app, play_path, tc_url, flash_version, rtmp_live, rtmp_conn,
|
||||||
rtmp_protocol, rtmp_real_time
|
rtmp_protocol, rtmp_real_time
|
||||||
|
|
|
@ -579,7 +579,7 @@ class NBCOlympicsStreamIE(AdobePassIE):
|
||||||
for f in formats:
|
for f in formats:
|
||||||
# -http_seekable requires ffmpeg 4.3+ but it doesnt seem possible to
|
# -http_seekable requires ffmpeg 4.3+ but it doesnt seem possible to
|
||||||
# download with ffmpeg without this option
|
# 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)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -125,7 +125,7 @@ class RadikoBaseIE(InfoExtractor):
|
||||||
# Prioritize live radio vs playback based on extractor
|
# Prioritize live radio vs playback based on extractor
|
||||||
sf['preference'] = 100 if is_onair else -100
|
sf['preference'] = 100 if is_onair else -100
|
||||||
if not is_onair and url_attrib['timefree'] == '1' and time_to_skip:
|
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)
|
formats.extend(subformats)
|
||||||
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
|
@ -141,7 +141,7 @@ class TurnerBaseIE(AdobePassIE):
|
||||||
m3u8_id=format_id or 'hls', fatal=False)
|
m3u8_id=format_id or 'hls', fatal=False)
|
||||||
if '/secure/' in video_url and '?hdnea=' in video_url:
|
if '/secure/' in video_url and '?hdnea=' in video_url:
|
||||||
for f in m3u8_formats:
|
for f in m3u8_formats:
|
||||||
f['_ffmpeg_args'] = ['-seekable', '0']
|
f['downloader_options'] = {'ffmpeg_args': ['-seekable', '0']}
|
||||||
formats.extend(m3u8_formats)
|
formats.extend(m3u8_formats)
|
||||||
elif ext == 'f4m':
|
elif ext == 'f4m':
|
||||||
formats.extend(self._extract_f4m_formats(
|
formats.extend(self._extract_f4m_formats(
|
||||||
|
|
Loading…
Reference in a new issue