-#!/usr/bin/env python
+#!/usr/bin/env python3
# coding: utf-8
from __future__ import unicode_literals
DateRange,
decodeOption,
DownloadError,
+ error_to_compat_str,
ExistingVideoReached,
expand_path,
match_filter_func,
preferredencoding,
read_batch_urls,
RejectedVideoReached,
- REMUX_EXTENSIONS,
render_table,
SameFileError,
setproctitle,
std_headers,
write_string,
)
-from .update import update_self
+from .update import run_update
from .downloader import (
FileDownloader,
)
from .extractor import gen_extractors, list_extractors
from .extractor.common import InfoExtractor
from .extractor.adobepass import MSO_INFO
+from .postprocessor.ffmpeg import (
+ FFmpegExtractAudioPP,
+ FFmpegSubtitlesConvertorPP,
+ FFmpegThumbnailsConvertorPP,
+ FFmpegVideoConvertorPP,
+ FFmpegVideoRemuxerPP,
+)
from .postprocessor.metadatafromfield import MetadataFromFieldPP
from .YoutubeDL import YoutubeDL
if numeric_limit is None:
parser.error('invalid rate limit specified')
opts.ratelimit = numeric_limit
+ if opts.throttledratelimit is not None:
+ numeric_limit = FileDownloader.parse_bytes(opts.throttledratelimit)
+ if numeric_limit is None:
+ parser.error('invalid rate limit specified')
+ opts.throttledratelimit = numeric_limit
if opts.min_filesize is not None:
numeric_limit = FileDownloader.parse_bytes(opts.min_filesize)
if numeric_limit is None:
if opts.playlistend not in (-1, None) and opts.playlistend < opts.playliststart:
raise ValueError('Playlist end must be greater than playlist start')
if opts.extractaudio:
- if opts.audioformat not in ['best', 'aac', 'flac', 'mp3', 'm4a', 'opus', 'vorbis', 'wav']:
+ if opts.audioformat not in ['best'] + list(FFmpegExtractAudioPP.SUPPORTED_EXTS):
parser.error('invalid audio format specified')
if opts.audioquality:
opts.audioquality = opts.audioquality.strip('k').strip('K')
if not opts.audioquality.isdigit():
parser.error('invalid audio quality specified')
if opts.recodevideo is not None:
- if opts.recodevideo not in REMUX_EXTENSIONS:
- parser.error('invalid video recode format specified')
+ opts.recodevideo = opts.recodevideo.replace(' ', '')
+ if not re.match(FFmpegVideoConvertorPP.FORMAT_RE, opts.recodevideo):
+ parser.error('invalid video remux format specified')
if opts.remuxvideo is not None:
opts.remuxvideo = opts.remuxvideo.replace(' ', '')
- remux_regex = r'{0}(?:/{0})*$'.format(r'(?:\w+>)?(?:%s)' % '|'.join(REMUX_EXTENSIONS))
- if not re.match(remux_regex, opts.remuxvideo):
+ if not re.match(FFmpegVideoRemuxerPP.FORMAT_RE, opts.remuxvideo):
parser.error('invalid video remux format specified')
if opts.convertsubtitles is not None:
- if opts.convertsubtitles not in ('srt', 'vtt', 'ass', 'lrc'):
+ if opts.convertsubtitles not in FFmpegSubtitlesConvertorPP.SUPPORTED_EXTS:
parser.error('invalid subtitle format specified')
if opts.convertthumbnails is not None:
- if opts.convertthumbnails not in ('jpg', ):
+ if opts.convertthumbnails not in FFmpegThumbnailsConvertorPP.SUPPORTED_EXTS:
parser.error('invalid thumbnail format specified')
if opts.date is not None:
return parsed_compat_opts
all_compat_opts = [
- 'filename', 'format-sort', 'abort-on-error', 'format-spec', 'multistreams',
- 'no-playlist-metafiles', 'no-live-chat', 'playlist-index', 'list-formats',
+ 'filename', 'format-sort', 'abort-on-error', 'format-spec', 'no-playlist-metafiles',
+ 'multistreams', 'no-live-chat', 'playlist-index', 'list-formats', 'no-direct-merge',
'no-youtube-channel-redirect', 'no-youtube-unavailable-videos', 'no-attach-info-json',
+ 'embed-thumbnail-atomicparsley', 'seperate-video-versions',
]
compat_opts = parse_compat_opts()
else:
_unused_compat_opt('filename')
+ def validate_outtmpl(tmpl, msg):
+ err = YoutubeDL.validate_outtmpl(tmpl)
+ if err:
+ parser.error('invalid %s %r: %s' % (msg, tmpl, error_to_compat_str(err)))
+
+ for k, tmpl in opts.outtmpl.items():
+ validate_outtmpl(tmpl, '%s output template' % k)
+ for tmpl in opts.forceprint:
+ validate_outtmpl(tmpl, 'print template')
+
if opts.extractaudio and not opts.keepvideo and opts.format is None:
opts.format = 'bestaudio/best'
if re.match(MetadataFromFieldPP.regex, f) is None:
parser.error('invalid format string "%s" specified for --parse-metadata' % f)
- any_getting = opts.geturl or opts.gettitle or opts.getid or opts.getthumbnail or opts.getdescription or opts.getfilename or opts.getformat or opts.getduration or opts.dumpjson or opts.dump_single_json
+ any_getting = opts.forceprint or opts.geturl or opts.gettitle or opts.getid or opts.getthumbnail or opts.getdescription or opts.getfilename or opts.getformat or opts.getduration or opts.dumpjson or opts.dump_single_json
any_printing = opts.print_json
download_archive_fn = expand_path(opts.download_archive) if opts.download_archive is not None else opts.download_archive
opts.postprocessor_args['default'] = opts.postprocessor_args['default-compat']
final_ext = (
- opts.recodevideo
- or (opts.remuxvideo in REMUX_EXTENSIONS) and opts.remuxvideo
- or (opts.extractaudio and opts.audioformat != 'best') and opts.audioformat
- or None)
+ 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)
match_filter = (
None if opts.match_filter is None
'forceduration': opts.getduration,
'forcefilename': opts.getfilename,
'forceformat': opts.getformat,
+ 'forceprint': opts.forceprint,
'forcejson': opts.dumpjson or opts.print_json,
'dump_single_json': opts.dump_single_json,
'force_write_download_archive': opts.force_write_download_archive,
'ignoreerrors': opts.ignoreerrors,
'force_generic_extractor': opts.force_generic_extractor,
'ratelimit': opts.ratelimit,
+ 'throttledratelimit': opts.throttledratelimit,
'overwrites': opts.overwrites,
'retries': opts.retries,
'fragment_retries': opts.fragment_retries,
'include_ads': opts.include_ads,
'default_search': opts.default_search,
'dynamic_mpd': opts.dynamic_mpd,
+ 'extractor_args': opts.extractor_args,
'youtube_include_dash_manifest': opts.youtube_include_dash_manifest,
'youtube_include_hls_manifest': opts.youtube_include_hls_manifest,
'encoding': opts.encoding,
# Update version
if opts.update_self:
# If updater returns True, exit. Required for windows
- if update_self(ydl.to_screen, opts.verbose, ydl._opener):
+ if run_update(ydl):
if actual_use:
sys.exit('ERROR: The program must exit for the update to complete')
sys.exit()