2021-06-03 11:43:42 +02:00
|
|
|
#!/usr/bin/env python3
|
2021-09-02 00:22:08 +02:00
|
|
|
f'You are using an unsupported version of Python. Only Python versions 3.6 and above are supported by yt-dlp' # noqa: F541
|
2014-11-16 15:08:34 +01:00
|
|
|
|
2011-11-21 19:59:59 +01:00
|
|
|
__license__ = 'Public Domain'
|
|
|
|
|
2021-08-09 21:52:55 +02:00
|
|
|
import itertools
|
2011-11-21 19:59:59 +01:00
|
|
|
import os
|
2013-07-01 18:52:19 +02:00
|
|
|
import random
|
2021-01-20 17:07:40 +01:00
|
|
|
import re
|
2011-11-21 19:59:59 +01:00
|
|
|
import sys
|
|
|
|
|
2022-04-12 00:32:57 +02:00
|
|
|
from .compat import compat_getpass, compat_os_name, compat_shlex_quote
|
|
|
|
from .cookies import SUPPORTED_BROWSERS, SUPPORTED_KEYRINGS
|
|
|
|
from .downloader import FileDownloader
|
|
|
|
from .extractor import gen_extractors, list_extractors
|
|
|
|
from .extractor.adobepass import MSO_INFO
|
|
|
|
from .extractor.common import InfoExtractor
|
2022-03-08 21:03:31 +01:00
|
|
|
from .options import parseOpts
|
2022-04-12 00:32:57 +02:00
|
|
|
from .postprocessor import (
|
|
|
|
FFmpegExtractAudioPP,
|
|
|
|
FFmpegSubtitlesConvertorPP,
|
|
|
|
FFmpegThumbnailsConvertorPP,
|
|
|
|
FFmpegVideoConvertorPP,
|
|
|
|
FFmpegVideoRemuxerPP,
|
|
|
|
MetadataFromFieldPP,
|
|
|
|
MetadataParserPP,
|
2014-11-02 11:23:40 +01:00
|
|
|
)
|
2022-04-12 00:32:57 +02:00
|
|
|
from .update import run_update
|
2014-11-02 11:23:40 +01:00
|
|
|
from .utils import (
|
2022-04-12 00:32:57 +02:00
|
|
|
NO_DEFAULT,
|
2013-10-15 02:07:26 +02:00
|
|
|
DateRange,
|
2021-11-28 22:22:52 +01:00
|
|
|
DownloadCancelled,
|
2013-10-15 02:07:26 +02:00
|
|
|
DownloadError,
|
2022-04-12 00:32:57 +02:00
|
|
|
GeoUtils,
|
|
|
|
SameFileError,
|
|
|
|
decodeOption,
|
2017-03-25 20:31:16 +01:00
|
|
|
expand_path,
|
2021-11-03 19:35:53 +01:00
|
|
|
float_or_none,
|
|
|
|
int_or_none,
|
2015-02-10 03:32:21 +01:00
|
|
|
match_filter_func,
|
2021-10-18 12:33:05 +02:00
|
|
|
parse_duration,
|
2013-10-15 02:07:26 +02:00
|
|
|
preferredencoding,
|
2014-02-25 01:43:17 +01:00
|
|
|
read_batch_urls,
|
2021-02-08 10:58:38 +01:00
|
|
|
render_table,
|
2013-12-16 05:04:12 +01:00
|
|
|
setproctitle,
|
2013-10-15 02:07:26 +02:00
|
|
|
std_headers,
|
2022-01-28 22:55:35 +01:00
|
|
|
traverse_obj,
|
2013-10-15 02:07:26 +02:00
|
|
|
write_string,
|
|
|
|
)
|
2013-06-18 22:14:21 +02:00
|
|
|
from .YoutubeDL import YoutubeDL
|
2013-10-15 02:07:26 +02:00
|
|
|
|
2011-11-21 19:59:59 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
def get_urls(urls, batchfile, verbose):
|
2012-11-28 02:04:46 +01:00
|
|
|
# Batch file verification
|
2014-02-25 01:43:17 +01:00
|
|
|
batch_urls = []
|
2022-03-08 21:03:31 +01:00
|
|
|
if batchfile is not None:
|
2012-11-28 02:04:46 +01:00
|
|
|
try:
|
2022-03-08 21:03:31 +01:00
|
|
|
if batchfile == '-':
|
2021-12-23 02:42:26 +01:00
|
|
|
write_string('Reading URLs from stdin - EOF (%s) to end:\n' % (
|
|
|
|
'Ctrl+Z' if compat_os_name == 'nt' else 'Ctrl+D'))
|
2012-11-28 02:04:46 +01:00
|
|
|
batchfd = sys.stdin
|
|
|
|
else:
|
2022-04-11 17:10:28 +02:00
|
|
|
batchfd = open(
|
|
|
|
expand_path(batchfile), encoding='utf-8', errors='ignore')
|
2014-02-25 01:43:17 +01:00
|
|
|
batch_urls = read_batch_urls(batchfd)
|
2022-03-08 21:03:31 +01:00
|
|
|
if verbose:
|
2014-11-16 15:08:34 +01:00
|
|
|
write_string('[debug] Batch file urls: ' + repr(batch_urls) + '\n')
|
2022-04-11 17:10:28 +02:00
|
|
|
except OSError:
|
2022-03-08 21:03:31 +01:00
|
|
|
sys.exit('ERROR: batch file %s could not be read' % batchfile)
|
2014-01-05 05:24:50 +01:00
|
|
|
_enc = preferredencoding()
|
2022-03-08 21:03:31 +01:00
|
|
|
return [
|
|
|
|
url.strip().decode(_enc, 'ignore') if isinstance(url, bytes) else url.strip()
|
|
|
|
for url in batch_urls + urls]
|
2012-11-28 02:04:46 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
|
|
|
|
def print_extractor_information(opts, urls):
|
2012-11-28 02:04:46 +01:00
|
|
|
if opts.list_extractors:
|
2015-01-07 07:20:20 +01:00
|
|
|
for ie in list_extractors(opts.age_limit):
|
2021-08-23 01:15:30 +02:00
|
|
|
write_string(ie.IE_NAME + (' (CURRENTLY BROKEN)' if not ie.working() else '') + '\n', out=sys.stdout)
|
2022-03-08 21:03:31 +01:00
|
|
|
matchedUrls = [url for url in urls if ie.suitable(url)]
|
2012-11-28 02:04:46 +01:00
|
|
|
for mu in matchedUrls:
|
2016-06-05 16:01:20 +02:00
|
|
|
write_string(' ' + mu + '\n', out=sys.stdout)
|
2022-03-08 21:03:31 +01:00
|
|
|
elif opts.list_extractor_descriptions:
|
2015-01-07 07:20:20 +01:00
|
|
|
for ie in list_extractors(opts.age_limit):
|
2021-08-23 01:15:30 +02:00
|
|
|
if not ie.working():
|
2013-07-01 18:52:19 +02:00
|
|
|
continue
|
2022-03-24 02:23:11 +01:00
|
|
|
if ie.IE_DESC is False:
|
2013-10-07 12:21:24 +02:00
|
|
|
continue
|
2022-03-24 02:23:11 +01:00
|
|
|
desc = ie.IE_DESC or ie.IE_NAME
|
2021-10-23 16:29:52 +02:00
|
|
|
if getattr(ie, 'SEARCH_KEY', None) is not None:
|
2015-01-01 22:47:21 +01:00
|
|
|
_SEARCHES = ('cute kittens', 'slithering pythons', 'falling cat', 'angry poodle', 'purple fish', 'running tortoise', 'sleeping bunny', 'burping cow')
|
2014-11-16 15:08:34 +01:00
|
|
|
_COUNTS = ('', '5', '10', 'all')
|
2021-10-23 16:29:52 +02:00
|
|
|
desc += f'; "{ie.SEARCH_KEY}:" prefix (Example: "{ie.SEARCH_KEY}{random.choice(_COUNTS)}:{random.choice(_SEARCHES)}")'
|
2016-06-05 16:01:20 +02:00
|
|
|
write_string(desc + '\n', out=sys.stdout)
|
2022-03-08 21:03:31 +01:00
|
|
|
elif opts.ap_list_mso:
|
2016-09-13 23:16:01 +02:00
|
|
|
table = [[mso_id, mso_info['name']] for mso_id, mso_info in MSO_INFO.items()]
|
2016-09-14 19:58:47 +02:00
|
|
|
write_string('Supported TV Providers:\n' + render_table(['mso', 'mso name'], table) + '\n', out=sys.stdout)
|
2013-04-27 14:01:55 +02:00
|
|
|
else:
|
2022-03-08 21:03:31 +01:00
|
|
|
return False
|
|
|
|
return True
|
2021-05-11 10:00:48 +02:00
|
|
|
|
2021-10-22 01:04:22 +02:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
def set_compat_opts(opts):
|
2021-05-11 10:00:48 +02:00
|
|
|
def _unused_compat_opt(name):
|
2022-03-08 21:03:31 +01:00
|
|
|
if name not in opts.compat_opts:
|
2021-05-11 10:00:48 +02:00
|
|
|
return False
|
2022-03-08 21:03:31 +01:00
|
|
|
opts.compat_opts.discard(name)
|
|
|
|
opts.compat_opts.update(['*%s' % name])
|
2021-05-11 10:00:48 +02:00
|
|
|
return True
|
|
|
|
|
2021-07-31 08:08:39 +02:00
|
|
|
def set_default_compat(compat_name, opt_name, default=True, remove_compat=True):
|
2021-05-11 10:00:48 +02:00
|
|
|
attr = getattr(opts, opt_name)
|
2022-03-08 21:03:31 +01:00
|
|
|
if compat_name in opts.compat_opts:
|
2021-05-11 10:00:48 +02:00
|
|
|
if attr is None:
|
|
|
|
setattr(opts, opt_name, not default)
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
if remove_compat:
|
|
|
|
_unused_compat_opt(compat_name)
|
|
|
|
return False
|
|
|
|
elif attr is None:
|
|
|
|
setattr(opts, opt_name, default)
|
|
|
|
return None
|
|
|
|
|
2021-09-24 02:21:54 +02:00
|
|
|
set_default_compat('abort-on-error', 'ignoreerrors', 'only_download')
|
2021-05-11 10:00:48 +02:00
|
|
|
set_default_compat('no-playlist-metafiles', 'allow_playlist_files')
|
2021-07-31 08:08:39 +02:00
|
|
|
set_default_compat('no-clean-infojson', 'clean_infojson')
|
2022-03-08 21:03:31 +01:00
|
|
|
if 'no-attach-info-json' in opts.compat_opts:
|
2021-11-14 23:33:41 +01:00
|
|
|
if opts.embed_infojson:
|
|
|
|
_unused_compat_opt('no-attach-info-json')
|
|
|
|
else:
|
|
|
|
opts.embed_infojson = False
|
2022-03-08 21:03:31 +01:00
|
|
|
if 'format-sort' in opts.compat_opts:
|
2021-05-11 10:00:48 +02:00
|
|
|
opts.format_sort.extend(InfoExtractor.FormatSort.ytdl_default)
|
|
|
|
_video_multistreams_set = set_default_compat('multistreams', 'allow_multiple_video_streams', False, remove_compat=False)
|
|
|
|
_audio_multistreams_set = set_default_compat('multistreams', 'allow_multiple_audio_streams', False, remove_compat=False)
|
|
|
|
if _video_multistreams_set is False and _audio_multistreams_set is False:
|
|
|
|
_unused_compat_opt('multistreams')
|
2022-03-08 21:03:31 +01:00
|
|
|
if 'filename' in opts.compat_opts:
|
|
|
|
if opts.outtmpl.get('default') is None:
|
|
|
|
opts.outtmpl.update({'default': '%(title)s-%(id)s.%(ext)s'})
|
2021-05-11 10:00:48 +02:00
|
|
|
else:
|
|
|
|
_unused_compat_opt('filename')
|
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
|
|
|
|
def validate_options(opts):
|
|
|
|
def validate(cndn, name, value=None, msg=None):
|
|
|
|
if cndn:
|
|
|
|
return True
|
|
|
|
raise ValueError((msg or 'invalid {name} "{value}" given').format(name=name, value=value))
|
|
|
|
|
|
|
|
def validate_in(name, value, items, msg=None):
|
|
|
|
return validate(value is None or value in items, name, value, msg)
|
|
|
|
|
|
|
|
def validate_regex(name, value, regex):
|
|
|
|
return validate(value is None or re.match(regex, value), name, value)
|
|
|
|
|
|
|
|
def validate_positive(name, value, strict=False):
|
|
|
|
return validate(value is None or value > 0 or (not strict and value == 0),
|
|
|
|
name, value, '{name} "{value}" must be positive' + ('' if strict else ' or 0'))
|
|
|
|
|
|
|
|
def validate_minmax(min_val, max_val, min_name, max_name=None):
|
|
|
|
if max_val is None or min_val is None or max_val >= min_val:
|
|
|
|
return
|
|
|
|
if not max_name:
|
|
|
|
min_name, max_name = f'min {min_name}', f'max {min_name}'
|
|
|
|
raise ValueError(f'{max_name} "{max_val}" must be must be greater than or equal to {min_name} "{min_val}"')
|
|
|
|
|
|
|
|
# Usernames and passwords
|
|
|
|
validate(not opts.usenetrc or (opts.username is None and opts.password is None),
|
|
|
|
'.netrc', msg='using {name} conflicts with giving username/password')
|
|
|
|
validate(opts.password is None or opts.username is not None, 'account username', msg='{name} missing')
|
|
|
|
validate(opts.ap_password is None or opts.ap_username is not None,
|
|
|
|
'TV Provider account username', msg='{name} missing')
|
|
|
|
validate_in('TV Provider', opts.ap_mso, MSO_INFO,
|
|
|
|
'Unsupported {name} "{value}", use --ap-list-mso to get a list of supported TV Providers')
|
|
|
|
|
|
|
|
# Numbers
|
|
|
|
validate_positive('autonumber start', opts.autonumber_start)
|
|
|
|
validate_positive('autonumber size', opts.autonumber_size, True)
|
|
|
|
validate_positive('concurrent fragments', opts.concurrent_fragment_downloads, True)
|
|
|
|
validate_positive('playlist start', opts.playliststart, True)
|
|
|
|
if opts.playlistend != -1:
|
|
|
|
validate_minmax(opts.playliststart, opts.playlistend, 'playlist start', 'playlist end')
|
|
|
|
|
|
|
|
# Time ranges
|
|
|
|
validate_positive('subtitles sleep interval', opts.sleep_interval_subtitles)
|
|
|
|
validate_positive('requests sleep interval', opts.sleep_interval_requests)
|
|
|
|
validate_positive('sleep interval', opts.sleep_interval)
|
|
|
|
validate_positive('max sleep interval', opts.max_sleep_interval)
|
2022-03-10 07:08:34 +01:00
|
|
|
if opts.sleep_interval is None:
|
2022-03-08 21:03:31 +01:00
|
|
|
validate(
|
2022-03-10 07:08:34 +01:00
|
|
|
opts.max_sleep_interval is None, 'min sleep interval',
|
2022-03-08 21:03:31 +01:00
|
|
|
msg='{name} must be specified; use --min-sleep-interval')
|
2022-03-10 07:08:34 +01:00
|
|
|
elif opts.max_sleep_interval is None:
|
|
|
|
opts.max_sleep_interval = opts.sleep_interval
|
|
|
|
else:
|
2022-03-08 21:03:31 +01:00
|
|
|
validate_minmax(opts.sleep_interval, opts.max_sleep_interval, 'sleep interval')
|
|
|
|
|
|
|
|
if opts.wait_for_video is not None:
|
|
|
|
min_wait, max_wait, *_ = map(parse_duration, opts.wait_for_video.split('-', 1) + [None])
|
|
|
|
validate(min_wait is not None and not (max_wait is None and '-' in opts.wait_for_video),
|
|
|
|
'time range to wait for video', opts.wait_for_video)
|
|
|
|
validate_minmax(min_wait, max_wait, 'time range to wait for video')
|
|
|
|
opts.wait_for_video = (min_wait, max_wait)
|
|
|
|
|
|
|
|
# Format sort
|
|
|
|
for f in opts.format_sort:
|
|
|
|
validate_regex('format sorting', f, InfoExtractor.FormatSort.regex)
|
|
|
|
|
|
|
|
# Postprocessor formats
|
|
|
|
validate_in('audio format', opts.audioformat, ['best'] + list(FFmpegExtractAudioPP.SUPPORTED_EXTS))
|
|
|
|
validate_in('subtitle format', opts.convertsubtitles, FFmpegSubtitlesConvertorPP.SUPPORTED_EXTS)
|
|
|
|
validate_in('thumbnail format', opts.convertthumbnails, FFmpegThumbnailsConvertorPP.SUPPORTED_EXTS)
|
|
|
|
if opts.recodevideo is not None:
|
|
|
|
opts.recodevideo = opts.recodevideo.replace(' ', '')
|
|
|
|
validate_regex('video recode format', opts.recodevideo, FFmpegVideoConvertorPP.FORMAT_RE)
|
|
|
|
if opts.remuxvideo is not None:
|
|
|
|
opts.remuxvideo = opts.remuxvideo.replace(' ', '')
|
|
|
|
validate_regex('video remux format', opts.remuxvideo, FFmpegVideoRemuxerPP.FORMAT_RE)
|
|
|
|
if opts.audioquality:
|
|
|
|
opts.audioquality = opts.audioquality.strip('k').strip('K')
|
|
|
|
# int_or_none prevents inf, nan
|
|
|
|
validate_positive('audio quality', int_or_none(float_or_none(opts.audioquality), default=0))
|
|
|
|
|
|
|
|
# Retries
|
|
|
|
def parse_retries(name, value):
|
|
|
|
if value is None:
|
|
|
|
return None
|
|
|
|
elif value in ('inf', 'infinite'):
|
|
|
|
return float('inf')
|
|
|
|
try:
|
|
|
|
return int(value)
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
validate(False, f'{name} retry count', value)
|
|
|
|
|
|
|
|
opts.retries = parse_retries('download', opts.retries)
|
|
|
|
opts.fragment_retries = parse_retries('fragment', opts.fragment_retries)
|
|
|
|
opts.extractor_retries = parse_retries('extractor', opts.extractor_retries)
|
|
|
|
opts.file_access_retries = parse_retries('file access', opts.file_access_retries)
|
|
|
|
|
|
|
|
# Bytes
|
|
|
|
def parse_bytes(name, value):
|
|
|
|
if value is None:
|
|
|
|
return None
|
|
|
|
numeric_limit = FileDownloader.parse_bytes(value)
|
|
|
|
validate(numeric_limit is not None, 'rate limit', value)
|
|
|
|
return numeric_limit
|
|
|
|
|
|
|
|
opts.ratelimit = parse_bytes('rate limit', opts.ratelimit)
|
2022-03-09 22:55:38 +01:00
|
|
|
opts.throttledratelimit = parse_bytes('throttled rate limit', opts.throttledratelimit)
|
2022-03-08 21:03:31 +01:00
|
|
|
opts.min_filesize = parse_bytes('min filesize', opts.min_filesize)
|
|
|
|
opts.max_filesize = parse_bytes('max filesize', opts.max_filesize)
|
|
|
|
opts.buffersize = parse_bytes('buffer size', opts.buffersize)
|
|
|
|
opts.http_chunk_size = parse_bytes('http chunk size', opts.http_chunk_size)
|
|
|
|
|
|
|
|
# Output templates
|
2021-06-08 16:41:00 +02:00
|
|
|
def validate_outtmpl(tmpl, msg):
|
|
|
|
err = YoutubeDL.validate_outtmpl(tmpl)
|
|
|
|
if err:
|
2022-03-08 21:03:31 +01:00
|
|
|
raise ValueError(f'invalid {msg} "{tmpl}": {err}')
|
2021-06-08 16:41:00 +02:00
|
|
|
|
|
|
|
for k, tmpl in opts.outtmpl.items():
|
2021-10-08 21:11:59 +02:00
|
|
|
validate_outtmpl(tmpl, f'{k} output template')
|
2022-01-02 11:52:00 +01:00
|
|
|
for type_, tmpl_list in opts.forceprint.items():
|
|
|
|
for tmpl in tmpl_list:
|
|
|
|
validate_outtmpl(tmpl, f'{type_} print template')
|
2022-01-23 22:34:19 +01:00
|
|
|
for type_, tmpl_list in opts.print_to_file.items():
|
|
|
|
for tmpl, file in tmpl_list:
|
2022-03-08 21:03:31 +01:00
|
|
|
validate_outtmpl(tmpl, f'{type_} print to file template')
|
|
|
|
validate_outtmpl(file, f'{type_} print to file filename')
|
2021-09-01 22:55:16 +02:00
|
|
|
validate_outtmpl(opts.sponsorblock_chapter_title, 'SponsorBlock chapter title')
|
2021-10-08 21:11:59 +02:00
|
|
|
for k, tmpl in opts.progress_template.items():
|
|
|
|
k = f'{k[:-6]} console title' if '-title' in k else f'{k} progress'
|
|
|
|
validate_outtmpl(tmpl, f'{k} template')
|
2021-06-08 16:41:00 +02:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
outtmpl_default = opts.outtmpl.get('default')
|
|
|
|
if outtmpl_default == '':
|
|
|
|
opts.skip_download = None
|
|
|
|
del opts.outtmpl['default']
|
|
|
|
if outtmpl_default and not os.path.splitext(outtmpl_default)[1] and opts.extractaudio:
|
|
|
|
raise ValueError(
|
|
|
|
'Cannot download a video and extract audio into the same file! '
|
|
|
|
f'Use "{outtmpl_default}.%(ext)s" instead of "{outtmpl_default}" as the output template')
|
|
|
|
|
|
|
|
# Remove chapters
|
|
|
|
remove_chapters_patterns, opts.remove_ranges = [], []
|
|
|
|
for regex in opts.remove_chapters or []:
|
|
|
|
if regex.startswith('*'):
|
|
|
|
dur = list(map(parse_duration, regex[1:].split('-')))
|
|
|
|
if len(dur) == 2 and all(t is not None for t in dur):
|
|
|
|
opts.remove_ranges.append(tuple(dur))
|
|
|
|
continue
|
|
|
|
raise ValueError(f'invalid --remove-chapters time range "{regex}". Must be of the form *start-end')
|
|
|
|
try:
|
|
|
|
remove_chapters_patterns.append(re.compile(regex))
|
|
|
|
except re.error as err:
|
|
|
|
raise ValueError(f'invalid --remove-chapters regex "{regex}" - {err}')
|
|
|
|
opts.remove_chapters = remove_chapters_patterns
|
2021-01-23 13:18:12 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
# Cookies from browser
|
|
|
|
if opts.cookiesfrombrowser:
|
|
|
|
mobj = re.match(r'(?P<name>[^+:]+)(\s*\+\s*(?P<keyring>[^:]+))?(\s*:(?P<profile>.+))?', opts.cookiesfrombrowser)
|
|
|
|
if mobj is None:
|
|
|
|
raise ValueError(f'invalid cookies from browser arguments: {opts.cookiesfrombrowser}')
|
|
|
|
browser_name, keyring, profile = mobj.group('name', 'keyring', 'profile')
|
|
|
|
browser_name = browser_name.lower()
|
|
|
|
if browser_name not in SUPPORTED_BROWSERS:
|
|
|
|
raise ValueError(f'unsupported browser specified for cookies: "{browser_name}". '
|
|
|
|
f'Supported browsers are: {", ".join(sorted(SUPPORTED_BROWSERS))}')
|
|
|
|
if keyring is not None:
|
|
|
|
keyring = keyring.upper()
|
|
|
|
if keyring not in SUPPORTED_KEYRINGS:
|
|
|
|
raise ValueError(f'unsupported keyring specified for cookies: "{keyring}". '
|
|
|
|
f'Supported keyrings are: {", ".join(sorted(SUPPORTED_KEYRINGS))}')
|
|
|
|
opts.cookiesfrombrowser = (browser_name, profile, keyring)
|
2013-09-24 21:55:25 +02:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
# MetadataParser
|
2021-08-09 21:52:55 +02:00
|
|
|
def metadataparser_actions(f):
|
|
|
|
if isinstance(f, str):
|
|
|
|
cmd = '--parse-metadata %s' % compat_shlex_quote(f)
|
|
|
|
try:
|
|
|
|
actions = [MetadataFromFieldPP.to_action(f)]
|
|
|
|
except Exception as err:
|
2022-03-08 21:03:31 +01:00
|
|
|
raise ValueError(f'{cmd} is invalid; {err}')
|
2021-08-09 21:52:55 +02:00
|
|
|
else:
|
|
|
|
cmd = '--replace-in-metadata %s' % ' '.join(map(compat_shlex_quote, f))
|
|
|
|
actions = ((MetadataParserPP.Actions.REPLACE, x, *f[1:]) for x in f[0].split(','))
|
|
|
|
|
|
|
|
for action in actions:
|
|
|
|
try:
|
|
|
|
MetadataParserPP.validate_action(*action)
|
|
|
|
except Exception as err:
|
2022-03-08 21:03:31 +01:00
|
|
|
raise ValueError(f'{cmd} is invalid; {err}')
|
2021-08-09 21:52:55 +02:00
|
|
|
yield action
|
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
parse_metadata = opts.parse_metadata or []
|
2021-01-26 11:20:20 +01:00
|
|
|
if opts.metafromtitle is not None:
|
2022-03-08 21:03:31 +01:00
|
|
|
parse_metadata.append('title:%s' % opts.metafromtitle)
|
|
|
|
opts.parse_metadata = list(itertools.chain(*map(metadataparser_actions, parse_metadata)))
|
2021-01-26 11:20:20 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
# Other options
|
|
|
|
geo_bypass_code = opts.geo_bypass_ip_block or opts.geo_bypass_country
|
|
|
|
if geo_bypass_code is not None:
|
|
|
|
try:
|
|
|
|
GeoUtils.random_ipv4(geo_bypass_code)
|
|
|
|
except Exception:
|
|
|
|
raise ValueError('unsupported geo-bypass country or ip-block')
|
2022-01-02 11:52:00 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
opts.match_filter = match_filter_func(opts.match_filter)
|
2013-12-16 04:15:10 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
if opts.download_archive is not None:
|
|
|
|
opts.download_archive = expand_path(opts.download_archive)
|
|
|
|
|
|
|
|
if opts.user_agent is not None:
|
|
|
|
opts.headers.setdefault('User-Agent', opts.user_agent)
|
|
|
|
if opts.referer is not None:
|
|
|
|
opts.headers.setdefault('Referer', opts.referer)
|
2021-02-28 16:25:32 +01:00
|
|
|
|
2021-09-01 22:55:16 +02:00
|
|
|
if opts.no_sponsorblock:
|
2022-03-08 21:03:31 +01:00
|
|
|
opts.sponsorblock_mark = opts.sponsorblock_remove = set()
|
|
|
|
|
|
|
|
warnings, deprecation_warnings = [], []
|
2021-09-01 22:55:16 +02:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
# Common mistake: -f best
|
|
|
|
if opts.format == 'best':
|
|
|
|
warnings.append('.\n '.join((
|
|
|
|
'"-f best" selects the best pre-merged format which is often not the best option',
|
|
|
|
'To let yt-dlp download and merge the best available formats, simply do not pass any format selection',
|
|
|
|
'If you know what you are doing and want only the best pre-merged format, use "-f b" instead to suppress this warning')))
|
|
|
|
|
2022-03-27 04:20:43 +02:00
|
|
|
# --(postprocessor/downloader)-args without name
|
2022-03-08 21:03:31 +01:00
|
|
|
def report_args_compat(name, value, key1, key2=None):
|
|
|
|
if key1 in value and key2 not in value:
|
|
|
|
warnings.append(f'{name} arguments given without specifying name. The arguments will be given to all {name}s')
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
report_args_compat('external downloader', opts.external_downloader_args, 'default')
|
|
|
|
if report_args_compat('post-processor', opts.postprocessor_args, 'default-compat', 'default'):
|
|
|
|
opts.postprocessor_args['default'] = opts.postprocessor_args.pop('default-compat')
|
|
|
|
opts.postprocessor_args.setdefault('sponskrub', [])
|
|
|
|
|
|
|
|
def report_conflict(arg1, opt1, arg2='--allow-unplayable-formats', opt2='allow_unplayable_formats',
|
|
|
|
val1=NO_DEFAULT, val2=NO_DEFAULT, default=False):
|
|
|
|
if val2 is NO_DEFAULT:
|
|
|
|
val2 = getattr(opts, opt2)
|
|
|
|
if not val2:
|
|
|
|
return
|
|
|
|
|
|
|
|
if val1 is NO_DEFAULT:
|
|
|
|
val1 = getattr(opts, opt1)
|
|
|
|
if val1:
|
|
|
|
warnings.append(f'{arg1} is ignored since {arg2} was given')
|
|
|
|
setattr(opts, opt1, default)
|
|
|
|
|
|
|
|
# Conflicting options
|
2022-03-11 09:59:11 +01:00
|
|
|
report_conflict('--dateafter', 'dateafter', '--date', 'date', default=None)
|
|
|
|
report_conflict('--datebefore', 'datebefore', '--date', 'date', default=None)
|
2022-03-08 21:03:31 +01:00
|
|
|
report_conflict('--exec-before-download', 'exec_before_dl_cmd', '"--exec before_dl:"', 'exec_cmd', opts.exec_cmd.get('before_dl'))
|
|
|
|
report_conflict('--id', 'useid', '--output', 'outtmpl', val2=opts.outtmpl.get('default'))
|
|
|
|
report_conflict('--remux-video', 'remuxvideo', '--recode-video', 'recodevideo')
|
|
|
|
report_conflict('--sponskrub', 'sponskrub', '--remove-chapters', 'remove_chapters')
|
|
|
|
report_conflict('--sponskrub', 'sponskrub', '--sponsorblock-mark', 'sponsorblock_mark')
|
|
|
|
report_conflict('--sponskrub', 'sponskrub', '--sponsorblock-remove', 'sponsorblock_remove')
|
|
|
|
report_conflict('--sponskrub-cut', 'sponskrub_cut', '--split-chapter', 'split_chapters', val1=opts.sponskrub and opts.sponskrub_cut)
|
|
|
|
|
|
|
|
# Conflicts with --allow-unplayable-formats
|
|
|
|
report_conflict('--add-metadata', 'addmetadata')
|
|
|
|
report_conflict('--embed-chapters', 'addchapters')
|
|
|
|
report_conflict('--embed-info-json', 'embed_infojson')
|
|
|
|
report_conflict('--embed-subs', 'embedsubtitles')
|
|
|
|
report_conflict('--embed-thumbnail', 'embedthumbnail')
|
|
|
|
report_conflict('--extract-audio', 'extractaudio')
|
|
|
|
report_conflict('--fixup', 'fixup', val1=(opts.fixup or '').lower() in ('', 'never', 'ignore'), default='never')
|
|
|
|
report_conflict('--recode-video', 'recodevideo')
|
|
|
|
report_conflict('--remove-chapters', 'remove_chapters', default=[])
|
|
|
|
report_conflict('--remux-video', 'remuxvideo')
|
|
|
|
report_conflict('--sponskrub', 'sponskrub')
|
|
|
|
report_conflict('--sponsorblock-remove', 'sponsorblock_remove', default=set())
|
|
|
|
report_conflict('--xattrs', 'xattrs')
|
|
|
|
|
|
|
|
# Fully deprecated options
|
|
|
|
def report_deprecation(val, old, new=None):
|
|
|
|
if not val:
|
|
|
|
return
|
|
|
|
deprecation_warnings.append(
|
|
|
|
f'{old} is deprecated and may be removed in a future version. Use {new} instead' if new
|
|
|
|
else f'{old} is deprecated and may not work as expected')
|
|
|
|
|
|
|
|
report_deprecation(opts.sponskrub, '--sponskrub', '--sponsorblock-mark or --sponsorblock-remove')
|
|
|
|
report_deprecation(not opts.prefer_ffmpeg, '--prefer-avconv', 'ffmpeg')
|
|
|
|
# report_deprecation(opts.include_ads, '--include-ads') # We may re-implement this in future
|
|
|
|
# report_deprecation(opts.call_home, '--call-home') # We may re-implement this in future
|
|
|
|
# report_deprecation(opts.writeannotations, '--write-annotations') # It's just that no website has it
|
|
|
|
|
|
|
|
# Dependent options
|
2022-03-11 09:59:11 +01:00
|
|
|
opts.date = DateRange.day(opts.date) if opts.date else DateRange(opts.dateafter, opts.datebefore)
|
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
if opts.exec_before_dl_cmd:
|
|
|
|
opts.exec_cmd['before_dl'] = opts.exec_before_dl_cmd
|
|
|
|
|
|
|
|
if opts.useid: # --id is not deprecated in youtube-dl
|
|
|
|
opts.outtmpl['default'] = '%(id)s.%(ext)s'
|
|
|
|
|
|
|
|
if opts.overwrites: # --force-overwrites implies --no-continue
|
|
|
|
opts.continue_dl = False
|
2021-02-12 04:51:59 +01:00
|
|
|
|
2021-11-19 01:06:28 +01:00
|
|
|
if (opts.addmetadata or opts.sponsorblock_mark) and opts.addchapters is None:
|
2022-03-08 21:03:31 +01:00
|
|
|
# Add chapters when adding metadata or marking sponsors
|
2021-11-19 01:06:28 +01:00
|
|
|
opts.addchapters = True
|
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
if opts.extractaudio and not opts.keepvideo and opts.format is None:
|
|
|
|
# Do not unnecessarily download audio
|
|
|
|
opts.format = 'bestaudio/best'
|
|
|
|
|
|
|
|
if opts.getcomments and opts.writeinfojson is None:
|
|
|
|
# If JSON is not printed anywhere, but comments are requested, save it to file
|
|
|
|
if not opts.dumpjson or opts.print_json or opts.dump_single_json:
|
|
|
|
opts.writeinfojson = True
|
|
|
|
|
|
|
|
if opts.allsubtitles and not (opts.embedsubtitles or opts.writeautomaticsub):
|
|
|
|
# --all-sub automatically sets --write-sub if --write-auto-sub is not given
|
|
|
|
opts.writesubtitles = True
|
|
|
|
|
|
|
|
if opts.addmetadata and opts.embed_infojson is None:
|
|
|
|
# If embedding metadata and infojson is present, embed it
|
|
|
|
opts.embed_infojson = 'if_exists'
|
|
|
|
|
|
|
|
# Ask for passwords
|
|
|
|
if opts.username is not None and opts.password is None:
|
|
|
|
opts.password = compat_getpass('Type account password and press [Return]: ')
|
|
|
|
if opts.ap_username is not None and opts.ap_password is None:
|
|
|
|
opts.ap_password = compat_getpass('Type TV provider account password and press [Return]: ')
|
|
|
|
|
|
|
|
return warnings, deprecation_warnings
|
|
|
|
|
|
|
|
|
|
|
|
def get_postprocessors(opts):
|
|
|
|
yield from opts.add_postprocessors
|
|
|
|
|
|
|
|
if opts.parse_metadata:
|
|
|
|
yield {
|
|
|
|
'key': 'MetadataParser',
|
|
|
|
'actions': opts.parse_metadata,
|
|
|
|
'when': 'pre_process'
|
|
|
|
}
|
|
|
|
sponsorblock_query = opts.sponsorblock_mark | opts.sponsorblock_remove
|
2021-09-01 22:55:16 +02:00
|
|
|
if sponsorblock_query:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2021-09-01 22:55:16 +02:00
|
|
|
'key': 'SponsorBlock',
|
|
|
|
'categories': sponsorblock_query,
|
|
|
|
'api': opts.sponsorblock_api,
|
2022-02-22 12:43:30 +01:00
|
|
|
'when': 'after_filter'
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2021-04-11 00:18:07 +02:00
|
|
|
if opts.convertsubtitles:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2021-04-11 00:18:07 +02:00
|
|
|
'key': 'FFmpegSubtitlesConvertor',
|
|
|
|
'format': opts.convertsubtitles,
|
|
|
|
'when': 'before_dl'
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2021-04-11 00:18:52 +02:00
|
|
|
if opts.convertthumbnails:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2021-04-11 00:18:52 +02:00
|
|
|
'key': 'FFmpegThumbnailsConvertor',
|
|
|
|
'format': opts.convertthumbnails,
|
|
|
|
'when': 'before_dl'
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2014-12-15 01:06:25 +01:00
|
|
|
if opts.extractaudio:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2014-12-15 01:06:25 +01:00
|
|
|
'key': 'FFmpegExtractAudio',
|
|
|
|
'preferredcodec': opts.audioformat,
|
|
|
|
'preferredquality': opts.audioquality,
|
|
|
|
'nopostoverwrites': opts.nopostoverwrites,
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2020-05-16 18:09:12 +02:00
|
|
|
if opts.remuxvideo:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2020-05-16 18:09:12 +02:00
|
|
|
'key': 'FFmpegVideoRemuxer',
|
|
|
|
'preferedformat': opts.remuxvideo,
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2014-12-15 01:06:25 +01:00
|
|
|
if opts.recodevideo:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2014-12-15 01:06:25 +01:00
|
|
|
'key': 'FFmpegVideoConvertor',
|
|
|
|
'preferedformat': opts.recodevideo,
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2021-09-01 22:55:16 +02:00
|
|
|
# If ModifyChapters is going to remove chapters, subtitles must already be in the container.
|
2014-12-15 01:06:25 +01:00
|
|
|
if opts.embedsubtitles:
|
2022-03-08 21:03:31 +01:00
|
|
|
keep_subs = 'no-keep-subs' not in opts.compat_opts
|
|
|
|
yield {
|
2014-12-15 01:06:25 +01:00
|
|
|
'key': 'FFmpegEmbedSubtitle',
|
2021-04-11 00:18:07 +02:00
|
|
|
# already_have_subtitle = True prevents the file from being deleted after embedding
|
2022-03-08 21:03:31 +01:00
|
|
|
'already_have_subtitle': opts.writesubtitles and keep_subs
|
|
|
|
}
|
|
|
|
if not opts.writeautomaticsub and keep_subs:
|
2021-02-09 19:37:10 +01:00
|
|
|
opts.writesubtitles = True
|
2022-03-08 21:03:31 +01:00
|
|
|
|
2021-09-01 22:55:16 +02:00
|
|
|
# ModifyChapters must run before FFmpegMetadataPP
|
|
|
|
if opts.remove_chapters or sponsorblock_query:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2021-09-01 22:55:16 +02:00
|
|
|
'key': 'ModifyChapters',
|
2022-03-08 21:03:31 +01:00
|
|
|
'remove_chapters_patterns': opts.remove_chapters,
|
2021-09-01 22:55:16 +02:00
|
|
|
'remove_sponsor_segments': opts.sponsorblock_remove,
|
2022-03-08 21:03:31 +01:00
|
|
|
'remove_ranges': opts.remove_ranges,
|
2021-09-01 22:55:16 +02:00
|
|
|
'sponsorblock_chapter_title': opts.sponsorblock_chapter_title,
|
|
|
|
'force_keyframes': opts.force_keyframes_at_cuts
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2021-09-01 22:55:16 +02:00
|
|
|
# FFmpegMetadataPP should be run after FFmpegVideoConvertorPP and
|
|
|
|
# FFmpegExtractAudioPP as containers before conversion may not support
|
|
|
|
# metadata (3gp, webm, etc.)
|
|
|
|
# By default ffmpeg preserves metadata applicable for both
|
|
|
|
# source and target containers. From this point the container won't change,
|
|
|
|
# so metadata can be added here.
|
2021-11-14 23:33:41 +01:00
|
|
|
if opts.addmetadata or opts.addchapters or opts.embed_infojson:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2021-09-01 22:55:16 +02:00
|
|
|
'key': 'FFmpegMetadata',
|
|
|
|
'add_chapters': opts.addchapters,
|
|
|
|
'add_metadata': opts.addmetadata,
|
2021-11-14 23:33:41 +01:00
|
|
|
'add_infojson': opts.embed_infojson,
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2021-11-29 18:46:06 +01:00
|
|
|
# Deprecated
|
2021-04-01 10:43:24 +02:00
|
|
|
# This should be above EmbedThumbnail since sponskrub removes the thumbnail attachment
|
|
|
|
# but must be below EmbedSubtitle and FFmpegMetadata
|
|
|
|
# See https://github.com/yt-dlp/yt-dlp/issues/204 , https://github.com/faissaloo/SponSkrub/issues/29
|
2020-11-15 01:28:41 +01:00
|
|
|
# If opts.sponskrub is None, sponskrub is used, but it silently fails if the executable can't be found
|
|
|
|
if opts.sponskrub is not False:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2020-11-15 01:28:41 +01:00
|
|
|
'key': 'SponSkrub',
|
|
|
|
'path': opts.sponskrub_path,
|
|
|
|
'args': opts.sponskrub_args,
|
|
|
|
'cut': opts.sponskrub_cut,
|
|
|
|
'force': opts.sponskrub_force,
|
|
|
|
'ignoreerror': opts.sponskrub is None,
|
2021-11-29 18:46:06 +01:00
|
|
|
'_from_cli': True,
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2021-04-01 10:43:24 +02:00
|
|
|
if opts.embedthumbnail:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2021-04-01 10:43:24 +02:00
|
|
|
'key': 'EmbedThumbnail',
|
2021-04-11 00:18:07 +02:00
|
|
|
# already_have_thumbnail = True prevents the file from being deleted after embedding
|
2021-12-06 18:56:34 +01:00
|
|
|
'already_have_thumbnail': opts.writethumbnail
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2021-12-06 18:56:34 +01:00
|
|
|
if not opts.writethumbnail:
|
2021-04-01 10:43:24 +02:00
|
|
|
opts.writethumbnail = True
|
2021-09-29 22:44:42 +02:00
|
|
|
opts.outtmpl['pl_thumbnail'] = ''
|
2021-03-15 00:02:13 +01:00
|
|
|
if opts.split_chapters:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2021-09-01 22:55:16 +02:00
|
|
|
'key': 'FFmpegSplitChapters',
|
|
|
|
'force_keyframes': opts.force_keyframes_at_cuts,
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2021-03-15 00:02:13 +01:00
|
|
|
# XAttrMetadataPP should be run after post-processors that may change file contents
|
|
|
|
if opts.xattrs:
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {'key': 'XAttrMetadata'}
|
2022-01-13 12:01:08 +01:00
|
|
|
if opts.concat_playlist != 'never':
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2022-01-13 12:01:08 +01:00
|
|
|
'key': 'FFmpegConcat',
|
|
|
|
'only_multi_video': opts.concat_playlist != 'always',
|
|
|
|
'when': 'playlist',
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2022-01-03 12:13:54 +01:00
|
|
|
# Exec must be the last PP of each category
|
|
|
|
for when, exec_cmd in opts.exec_cmd.items():
|
2022-03-08 21:03:31 +01:00
|
|
|
yield {
|
2021-08-09 14:10:24 +02:00
|
|
|
'key': 'Exec',
|
2022-01-03 12:13:54 +01:00
|
|
|
'exec_cmd': exec_cmd,
|
|
|
|
'when': when,
|
2022-03-08 21:03:31 +01:00
|
|
|
}
|
2021-01-07 20:28:41 +01:00
|
|
|
|
2021-05-03 11:41:59 +02:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
def parse_options(argv=None):
|
|
|
|
""" @returns (parser, opts, urls, ydl_opts) """
|
|
|
|
parser, opts, urls = parseOpts(argv)
|
|
|
|
urls = get_urls(urls, opts.batchfile, opts.verbose)
|
2021-01-23 13:11:21 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
set_compat_opts(opts)
|
|
|
|
try:
|
|
|
|
warnings, deprecation_warnings = validate_options(opts)
|
|
|
|
except ValueError as err:
|
|
|
|
parser.error(f'{err}\n')
|
2021-01-07 20:28:41 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
postprocessors = list(get_postprocessors(opts))
|
2021-11-29 18:46:06 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
any_getting = (any(opts.forceprint.values()) or opts.dumpjson or opts.dump_single_json
|
|
|
|
or opts.geturl or opts.gettitle or opts.getid or opts.getthumbnail
|
|
|
|
or opts.getdescription or opts.getfilename or opts.getformat or opts.getduration)
|
|
|
|
|
|
|
|
any_printing = opts.print_json
|
2021-11-29 18:46:06 +01:00
|
|
|
|
2021-02-08 10:58:38 +01:00
|
|
|
final_ext = (
|
2021-05-22 10:24:12 +02:00
|
|
|
opts.recodevideo if opts.recodevideo in FFmpegVideoConvertorPP.SUPPORTED_EXTS
|
|
|
|
else opts.remuxvideo if opts.remuxvideo in FFmpegVideoRemuxerPP.SUPPORTED_EXTS
|
|
|
|
else opts.audioformat if (opts.extractaudio and opts.audioformat != 'best')
|
|
|
|
else None)
|
2021-01-28 10:29:01 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
return parser, opts, urls, {
|
2012-11-28 02:04:46 +01:00
|
|
|
'usenetrc': opts.usenetrc,
|
2021-09-15 21:21:40 +02:00
|
|
|
'netrc_location': opts.netrc_location,
|
2012-11-28 02:04:46 +01:00
|
|
|
'username': opts.username,
|
|
|
|
'password': opts.password,
|
2014-08-16 23:28:41 +02:00
|
|
|
'twofactor': opts.twofactor,
|
2013-06-25 22:22:32 +02:00
|
|
|
'videopassword': opts.videopassword,
|
2016-09-14 19:58:47 +02:00
|
|
|
'ap_mso': opts.ap_mso,
|
2016-09-13 23:16:01 +02:00
|
|
|
'ap_username': opts.ap_username,
|
|
|
|
'ap_password': opts.ap_password,
|
2015-01-08 18:01:41 +01:00
|
|
|
'quiet': (opts.quiet or any_getting or any_printing),
|
2014-03-26 00:43:46 +01:00
|
|
|
'no_warnings': opts.no_warnings,
|
2012-11-28 02:04:46 +01:00
|
|
|
'forceurl': opts.geturl,
|
|
|
|
'forcetitle': opts.gettitle,
|
2013-05-06 07:30:07 +02:00
|
|
|
'forceid': opts.getid,
|
2012-11-28 02:04:46 +01:00
|
|
|
'forcethumbnail': opts.getthumbnail,
|
|
|
|
'forcedescription': opts.getdescription,
|
2013-12-16 04:15:10 +01:00
|
|
|
'forceduration': opts.getduration,
|
2012-11-28 02:04:46 +01:00
|
|
|
'forcefilename': opts.getfilename,
|
|
|
|
'forceformat': opts.getformat,
|
2021-05-13 13:39:43 +02:00
|
|
|
'forceprint': opts.forceprint,
|
2022-01-23 22:34:19 +01:00
|
|
|
'print_to_file': opts.print_to_file,
|
2015-01-08 18:01:41 +01:00
|
|
|
'forcejson': opts.dumpjson or opts.print_json,
|
2014-10-25 00:30:57 +02:00
|
|
|
'dump_single_json': opts.dump_single_json,
|
2020-11-05 18:43:21 +01:00
|
|
|
'force_write_download_archive': opts.force_write_download_archive,
|
2021-08-07 02:01:51 +02:00
|
|
|
'simulate': (any_getting or None) if opts.simulate is None else opts.simulate,
|
2014-10-26 13:01:57 +01:00
|
|
|
'skip_download': opts.skip_download,
|
2012-11-28 02:04:46 +01:00
|
|
|
'format': opts.format,
|
2021-02-12 04:51:59 +01:00
|
|
|
'allow_unplayable_formats': opts.allow_unplayable_formats,
|
2021-04-17 02:09:58 +02:00
|
|
|
'ignore_no_formats_error': opts.ignore_no_formats_error,
|
Better Format Sorting (Squashed)
* Added --format-sort (-S height,filesize)
* Made fields reversible (-S +height)
* Added --format-sort-force, --no-format-sort-force
* Added limit (-S height:720)
* Added codec preference (-S vcodec,acodec)
* Correct handling of preference<-1000
* Rebased to yt-dlc
* Automatically determine missing bitrates
* aext, vext, protocol, acodec, vcodec can now takes priority as string, not number (-S vext:webm)
* Correct handling of None in codec, audio_codec (None means the codec is unknown while 'none' means it doesn't exist)
* Correctly parse filesize (-S filesize:200M)
* Generalized preference calculation
* Rewrote entire code into the class FormatSort
* Correctly handle user input errors
* Combined fields (-S +ext:webm:webm)
* Closest mode (-S filesize~50M)
* Aliases (framerate=fps, br=bitrate etc)
* Documentation
2020-10-26 16:50:09 +01:00
|
|
|
'format_sort': opts.format_sort,
|
|
|
|
'format_sort_force': opts.format_sort_force,
|
Better Format Selection
* Added options: --video-multistreams, --no-video-multistreams, --audio-multistreams, --no-audio-multistreams
* New format selectors: best*, worst*, bestvideo*, bestaudio*, worstvideo*, worstaudio*
* Added b,w,v,a as alias for best, worst, video and audio respectively in format selection
* Changed video format sorting to show video only files and video+audio files together.
2020-11-05 16:35:36 +01:00
|
|
|
'allow_multiple_video_streams': opts.allow_multiple_video_streams,
|
|
|
|
'allow_multiple_audio_streams': opts.allow_multiple_audio_streams,
|
2021-05-04 17:54:00 +02:00
|
|
|
'check_formats': opts.check_formats,
|
2012-11-28 02:04:46 +01:00
|
|
|
'listformats': opts.listformats,
|
2020-12-13 15:29:09 +01:00
|
|
|
'listformats_table': opts.listformats_table,
|
2021-05-08 17:21:43 +02:00
|
|
|
'outtmpl': opts.outtmpl,
|
2021-01-16 18:12:05 +01:00
|
|
|
'outtmpl_na_placeholder': opts.outtmpl_na_placeholder,
|
2021-01-23 13:18:12 +01:00
|
|
|
'paths': opts.paths,
|
2013-04-02 06:40:07 +02:00
|
|
|
'autonumber_size': opts.autonumber_size,
|
2016-05-01 14:34:11 +02:00
|
|
|
'autonumber_start': opts.autonumber_start,
|
2012-11-28 02:04:46 +01:00
|
|
|
'restrictfilenames': opts.restrictfilenames,
|
2021-02-17 20:09:38 +01:00
|
|
|
'windowsfilenames': opts.windowsfilenames,
|
2012-11-28 02:04:46 +01:00
|
|
|
'ignoreerrors': opts.ignoreerrors,
|
2015-06-12 15:20:12 +02:00
|
|
|
'force_generic_extractor': opts.force_generic_extractor,
|
2012-11-28 02:04:46 +01:00
|
|
|
'ratelimit': opts.ratelimit,
|
2021-06-23 01:11:09 +02:00
|
|
|
'throttledratelimit': opts.throttledratelimit,
|
2019-10-13 18:00:48 +02:00
|
|
|
'overwrites': opts.overwrites,
|
2016-03-19 15:40:36 +01:00
|
|
|
'retries': opts.retries,
|
2021-12-23 03:29:03 +01:00
|
|
|
'file_access_retries': opts.file_access_retries,
|
2016-03-19 15:40:36 +01:00
|
|
|
'fragment_retries': opts.fragment_retries,
|
2021-03-01 00:48:37 +01:00
|
|
|
'extractor_retries': opts.extractor_retries,
|
2016-08-26 23:52:18 +02:00
|
|
|
'skip_unavailable_fragments': opts.skip_unavailable_fragments,
|
2017-04-23 22:09:08 +02:00
|
|
|
'keep_fragments': opts.keep_fragments,
|
2021-03-13 05:46:58 +01:00
|
|
|
'concurrent_fragment_downloads': opts.concurrent_fragment_downloads,
|
2012-11-28 02:04:46 +01:00
|
|
|
'buffersize': opts.buffersize,
|
|
|
|
'noresizebuffer': opts.noresizebuffer,
|
2018-01-28 07:21:45 +01:00
|
|
|
'http_chunk_size': opts.http_chunk_size,
|
2012-11-28 02:04:46 +01:00
|
|
|
'continuedl': opts.continue_dl,
|
2021-10-08 21:11:59 +02:00
|
|
|
'noprogress': opts.quiet if opts.noprogress is None else opts.noprogress,
|
2013-02-18 18:52:06 +01:00
|
|
|
'progress_with_newline': opts.progress_with_newline,
|
2021-10-08 21:11:59 +02:00
|
|
|
'progress_template': opts.progress_template,
|
2012-11-28 02:04:46 +01:00
|
|
|
'playliststart': opts.playliststart,
|
|
|
|
'playlistend': opts.playlistend,
|
2014-07-11 05:11:11 +02:00
|
|
|
'playlistreverse': opts.playlist_reverse,
|
2017-01-31 10:03:31 +01:00
|
|
|
'playlistrandom': opts.playlist_random,
|
2013-09-30 22:26:25 +02:00
|
|
|
'noplaylist': opts.noplaylist,
|
2022-03-08 21:03:31 +01:00
|
|
|
'logtostderr': opts.outtmpl.get('default') == '-',
|
2012-11-28 02:04:46 +01:00
|
|
|
'consoletitle': opts.consoletitle,
|
|
|
|
'nopart': opts.nopart,
|
|
|
|
'updatetime': opts.updatetime,
|
|
|
|
'writedescription': opts.writedescription,
|
2013-10-14 07:18:58 +02:00
|
|
|
'writeannotations': opts.writeannotations,
|
2021-02-28 16:25:32 +01:00
|
|
|
'writeinfojson': opts.writeinfojson,
|
2021-02-12 05:40:31 +01:00
|
|
|
'allow_playlist_files': opts.allow_playlist_files,
|
2021-03-18 16:27:20 +01:00
|
|
|
'clean_infojson': opts.clean_infojson,
|
2021-01-27 16:02:51 +01:00
|
|
|
'getcomments': opts.getcomments,
|
2021-12-06 18:56:34 +01:00
|
|
|
'writethumbnail': opts.writethumbnail is True,
|
|
|
|
'write_all_thumbnails': opts.writethumbnail == 'all',
|
2020-10-27 11:37:21 +01:00
|
|
|
'writelink': opts.writelink,
|
|
|
|
'writeurllink': opts.writeurllink,
|
|
|
|
'writewebloclink': opts.writewebloclink,
|
|
|
|
'writedesktoplink': opts.writedesktoplink,
|
2012-11-28 02:04:46 +01:00
|
|
|
'writesubtitles': opts.writesubtitles,
|
2013-06-25 23:45:16 +02:00
|
|
|
'writeautomaticsub': opts.writeautomaticsub,
|
2013-02-22 02:52:55 +01:00
|
|
|
'allsubtitles': opts.allsubtitles,
|
2013-02-22 04:50:05 +01:00
|
|
|
'listsubtitles': opts.listsubtitles,
|
2013-02-22 03:53:54 +01:00
|
|
|
'subtitlesformat': opts.subtitlesformat,
|
2013-09-06 16:26:22 +02:00
|
|
|
'subtitleslangs': opts.subtitleslangs,
|
2013-02-21 17:09:39 +01:00
|
|
|
'matchtitle': decodeOption(opts.matchtitle),
|
|
|
|
'rejecttitle': decodeOption(opts.rejecttitle),
|
2012-11-28 02:04:46 +01:00
|
|
|
'max_downloads': opts.max_downloads,
|
|
|
|
'prefer_free_formats': opts.prefer_free_formats,
|
2020-09-30 05:50:09 +02:00
|
|
|
'trim_file_name': opts.trim_file_name,
|
2012-11-28 02:04:46 +01:00
|
|
|
'verbose': opts.verbose,
|
2013-04-11 18:31:35 +02:00
|
|
|
'dump_intermediate_pages': opts.dump_intermediate_pages,
|
2013-10-28 10:44:02 +01:00
|
|
|
'write_pages': opts.write_pages,
|
2012-12-11 09:57:40 +01:00
|
|
|
'test': opts.test,
|
2013-01-12 15:07:59 +01:00
|
|
|
'keepvideo': opts.keepvideo,
|
2013-01-22 06:50:42 +01:00
|
|
|
'min_filesize': opts.min_filesize,
|
2013-04-27 14:01:55 +02:00
|
|
|
'max_filesize': opts.max_filesize,
|
2013-12-16 03:09:49 +01:00
|
|
|
'min_views': opts.min_views,
|
|
|
|
'max_views': opts.max_views,
|
2022-03-08 21:03:31 +01:00
|
|
|
'daterange': opts.date,
|
2013-09-24 21:26:10 +02:00
|
|
|
'cachedir': opts.cachedir,
|
2013-09-22 10:50:12 +02:00
|
|
|
'youtube_print_sig_code': opts.youtube_print_sig_code,
|
2013-10-06 06:06:30 +02:00
|
|
|
'age_limit': opts.age_limit,
|
2022-03-08 21:03:31 +01:00
|
|
|
'download_archive': opts.download_archive,
|
2020-09-21 17:26:18 +02:00
|
|
|
'break_on_existing': opts.break_on_existing,
|
2021-01-13 02:01:01 +01:00
|
|
|
'break_on_reject': opts.break_on_reject,
|
2021-11-28 22:11:55 +01:00
|
|
|
'break_per_url': opts.break_per_url,
|
2021-04-21 08:00:43 +02:00
|
|
|
'skip_playlist_after_errors': opts.skip_playlist_after_errors,
|
2013-11-22 19:57:52 +01:00
|
|
|
'cookiefile': opts.cookiefile,
|
2021-07-21 22:32:49 +02:00
|
|
|
'cookiesfrombrowser': opts.cookiesfrombrowser,
|
2022-01-21 07:12:30 +01:00
|
|
|
'legacyserverconnect': opts.legacy_server_connect,
|
2013-11-22 19:57:52 +01:00
|
|
|
'nocheckcertificate': opts.no_check_certificate,
|
2014-03-21 00:33:53 +01:00
|
|
|
'prefer_insecure': opts.prefer_insecure,
|
2022-01-28 22:55:35 +01:00
|
|
|
'http_headers': opts.headers,
|
2013-11-26 08:03:11 +01:00
|
|
|
'proxy': opts.proxy,
|
2013-12-02 13:37:05 +01:00
|
|
|
'socket_timeout': opts.socket_timeout,
|
2013-12-09 04:08:51 +01:00
|
|
|
'bidi_workaround': opts.bidi_workaround,
|
2013-12-29 15:28:32 +01:00
|
|
|
'debug_printtraffic': opts.debug_printtraffic,
|
2014-01-08 17:53:34 +01:00
|
|
|
'prefer_ffmpeg': opts.prefer_ffmpeg,
|
2014-01-21 02:09:49 +01:00
|
|
|
'include_ads': opts.include_ads,
|
2014-01-22 14:16:43 +01:00
|
|
|
'default_search': opts.default_search,
|
2020-09-16 13:00:41 +02:00
|
|
|
'dynamic_mpd': opts.dynamic_mpd,
|
2021-06-25 16:05:41 +02:00
|
|
|
'extractor_args': opts.extractor_args,
|
2014-01-22 21:56:37 +01:00
|
|
|
'youtube_include_dash_manifest': opts.youtube_include_dash_manifest,
|
2020-09-16 13:00:41 +02:00
|
|
|
'youtube_include_hls_manifest': opts.youtube_include_hls_manifest,
|
2014-03-30 06:02:41 +02:00
|
|
|
'encoding': opts.encoding,
|
2014-10-24 14:48:12 +02:00
|
|
|
'extract_flat': opts.extract_flat,
|
2021-12-20 07:06:46 +01:00
|
|
|
'live_from_start': opts.live_from_start,
|
2021-11-28 19:57:44 +01:00
|
|
|
'wait_for_video': opts.wait_for_video,
|
2016-02-29 20:01:33 +01:00
|
|
|
'mark_watched': opts.mark_watched,
|
2015-01-10 01:03:11 +01:00
|
|
|
'merge_output_format': opts.merge_output_format,
|
2021-02-08 10:58:38 +01:00
|
|
|
'final_ext': final_ext,
|
2014-12-15 01:06:25 +01:00
|
|
|
'postprocessors': postprocessors,
|
2015-01-10 05:45:51 +01:00
|
|
|
'fixup': opts.fixup,
|
2015-01-10 19:55:36 +01:00
|
|
|
'source_address': opts.source_address,
|
2015-01-10 21:02:27 +01:00
|
|
|
'call_home': opts.call_home,
|
2021-02-27 13:41:23 +01:00
|
|
|
'sleep_interval_requests': opts.sleep_interval_requests,
|
2015-01-23 12:05:01 +01:00
|
|
|
'sleep_interval': opts.sleep_interval,
|
2016-08-04 12:17:22 +02:00
|
|
|
'max_sleep_interval': opts.max_sleep_interval,
|
2020-09-29 05:11:32 +02:00
|
|
|
'sleep_interval_subtitles': opts.sleep_interval_subtitles,
|
2015-01-24 01:38:48 +01:00
|
|
|
'external_downloader': opts.external_downloader,
|
2015-01-25 02:38:47 +01:00
|
|
|
'list_thumbnails': opts.list_thumbnails,
|
2015-01-25 04:24:55 +01:00
|
|
|
'playlist_items': opts.playlist_items,
|
2015-01-25 04:49:44 +01:00
|
|
|
'xattr_set_filesize': opts.xattr_set_filesize,
|
2022-03-08 21:03:31 +01:00
|
|
|
'match_filter': opts.match_filter,
|
2015-02-10 04:22:10 +01:00
|
|
|
'no_color': opts.no_color,
|
2015-02-13 11:14:01 +01:00
|
|
|
'ffmpeg_location': opts.ffmpeg_location,
|
2015-02-17 12:09:12 +01:00
|
|
|
'hls_prefer_native': opts.hls_prefer_native,
|
2016-01-30 12:26:40 +01:00
|
|
|
'hls_use_mpegts': opts.hls_use_mpegts,
|
2021-02-24 15:47:53 +01:00
|
|
|
'hls_split_discontinuity': opts.hls_split_discontinuity,
|
2021-01-23 06:59:20 +01:00
|
|
|
'external_downloader_args': opts.external_downloader_args,
|
2021-01-23 06:57:27 +01:00
|
|
|
'postprocessor_args': opts.postprocessor_args,
|
2015-03-03 00:03:06 +01:00
|
|
|
'cn_verification_proxy': opts.cn_verification_proxy,
|
2016-07-03 17:23:48 +02:00
|
|
|
'geo_verification_proxy': opts.geo_verification_proxy,
|
2017-02-18 19:53:41 +01:00
|
|
|
'geo_bypass': opts.geo_bypass,
|
|
|
|
'geo_bypass_country': opts.geo_bypass_country,
|
2018-05-02 02:18:01 +02:00
|
|
|
'geo_bypass_ip_block': opts.geo_bypass_ip_block,
|
2021-10-22 22:37:20 +02:00
|
|
|
'_warnings': warnings,
|
2021-11-29 18:46:06 +01:00
|
|
|
'_deprecation_warnings': deprecation_warnings,
|
2022-03-08 21:03:31 +01:00
|
|
|
'compat_opts': opts.compat_opts,
|
2013-11-17 21:05:14 +01:00
|
|
|
}
|
2012-11-28 02:04:46 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
|
|
|
|
def _real_main(argv=None):
|
|
|
|
setproctitle('yt-dlp')
|
|
|
|
|
|
|
|
parser, opts, all_urls, ydl_opts = parse_options(argv)
|
|
|
|
|
|
|
|
# Dump user agent
|
|
|
|
if opts.dump_user_agent:
|
|
|
|
ua = traverse_obj(opts.headers, 'User-Agent', casesense=False, default=std_headers['User-Agent'])
|
|
|
|
write_string(f'{ua}\n', out=sys.stdout)
|
2022-03-13 10:08:06 +01:00
|
|
|
sys.exit(0)
|
2022-03-08 21:03:31 +01:00
|
|
|
|
|
|
|
if print_extractor_information(opts, all_urls):
|
|
|
|
sys.exit(0)
|
|
|
|
|
2013-11-17 21:05:14 +01:00
|
|
|
with YoutubeDL(ydl_opts) as ydl:
|
2021-11-28 22:22:52 +01:00
|
|
|
actual_use = all_urls or opts.load_info_filename
|
2013-11-17 21:05:14 +01:00
|
|
|
|
2014-07-24 12:16:16 +02:00
|
|
|
# Remove cache dir
|
|
|
|
if opts.rm_cachedir:
|
2014-09-03 12:41:05 +02:00
|
|
|
ydl.cache.remove()
|
2014-07-24 12:16:16 +02:00
|
|
|
|
2021-02-14 18:10:54 +01:00
|
|
|
# Update version
|
|
|
|
if opts.update_self:
|
|
|
|
# If updater returns True, exit. Required for windows
|
2021-05-25 21:43:08 +02:00
|
|
|
if run_update(ydl):
|
2021-02-14 18:10:54 +01:00
|
|
|
if actual_use:
|
2021-02-16 12:34:25 +01:00
|
|
|
sys.exit('ERROR: The program must exit for the update to complete')
|
2021-02-14 18:10:54 +01:00
|
|
|
sys.exit()
|
|
|
|
|
2013-11-17 21:05:14 +01:00
|
|
|
# Maybe do nothing
|
2021-02-14 18:10:54 +01:00
|
|
|
if not actual_use:
|
2014-11-23 10:49:19 +01:00
|
|
|
if opts.update_self or opts.rm_cachedir:
|
2013-11-17 21:05:14 +01:00
|
|
|
sys.exit()
|
2012-11-28 02:04:46 +01:00
|
|
|
|
2014-11-23 10:49:19 +01:00
|
|
|
ydl.warn_if_short_id(sys.argv[1:] if argv is None else argv)
|
2015-01-30 01:56:15 +01:00
|
|
|
parser.error(
|
|
|
|
'You must provide at least one URL.\n'
|
2021-02-24 19:45:56 +01:00
|
|
|
'Type yt-dlp --help to see a list of all options.')
|
2014-11-23 10:49:19 +01:00
|
|
|
|
2013-11-17 21:05:14 +01:00
|
|
|
try:
|
2013-11-22 14:57:53 +01:00
|
|
|
if opts.load_info_filename is not None:
|
2017-03-25 20:31:16 +01:00
|
|
|
retcode = ydl.download_with_info_file(expand_path(opts.load_info_filename))
|
2013-11-22 14:57:53 +01:00
|
|
|
else:
|
|
|
|
retcode = ydl.download(all_urls)
|
2021-11-28 22:22:52 +01:00
|
|
|
except DownloadCancelled:
|
2021-01-13 02:01:01 +01:00
|
|
|
ydl.to_screen('Aborting remaining downloads')
|
2013-11-17 21:05:14 +01:00
|
|
|
retcode = 101
|
2012-11-28 02:04:46 +01:00
|
|
|
|
|
|
|
sys.exit(retcode)
|
2011-11-21 19:59:59 +01:00
|
|
|
|
2013-10-07 18:50:26 +02:00
|
|
|
|
2013-04-16 19:26:48 +02:00
|
|
|
def main(argv=None):
|
2012-11-28 02:04:46 +01:00
|
|
|
try:
|
2013-04-16 19:26:48 +02:00
|
|
|
_real_main(argv)
|
2012-11-28 02:04:46 +01:00
|
|
|
except DownloadError:
|
|
|
|
sys.exit(1)
|
2021-11-09 23:49:33 +01:00
|
|
|
except SameFileError as e:
|
|
|
|
sys.exit(f'ERROR: {e}')
|
2012-11-28 02:04:46 +01:00
|
|
|
except KeyboardInterrupt:
|
2014-11-16 15:08:34 +01:00
|
|
|
sys.exit('\nERROR: Interrupted by user')
|
2021-11-09 23:49:33 +01:00
|
|
|
except BrokenPipeError as e:
|
2021-08-04 21:41:05 +02:00
|
|
|
# https://docs.python.org/3/library/signal.html#note-on-sigpipe
|
|
|
|
devnull = os.open(os.devnull, os.O_WRONLY)
|
|
|
|
os.dup2(devnull, sys.stdout.fileno())
|
2021-11-09 23:49:33 +01:00
|
|
|
sys.exit(f'\nERROR: {e}')
|
2015-01-07 07:41:05 +01:00
|
|
|
|
2016-11-17 12:42:56 +01:00
|
|
|
|
2022-03-08 21:03:31 +01:00
|
|
|
__all__ = [
|
|
|
|
'main',
|
|
|
|
'YoutubeDL',
|
|
|
|
'parse_options',
|
|
|
|
'gen_extractors',
|
|
|
|
'list_extractors',
|
|
|
|
]
|