aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpukkandan <pukkandan@gmail.com>2021-02-08 15:28:38 +0530
committerpukkandan <pukkandan@gmail.com>2021-02-08 15:29:02 +0530
commitdf692c5a7aa46850e915b538461b01eeddd03901 (patch)
tree583c82146d4b35e3e5704bbfe5c4bd4cf2280cdc
parentecc97af3448423a461f017badd07bb5fa9206f37 (diff)
downloadhypervideo-pre-df692c5a7aa46850e915b538461b01eeddd03901.tar.lz
hypervideo-pre-df692c5a7aa46850e915b538461b01eeddd03901.tar.xz
hypervideo-pre-df692c5a7aa46850e915b538461b01eeddd03901.zip
[remuxvideo] Fix validation of conditional remux
-rw-r--r--youtube_dlc/__init__.py18
-rw-r--r--youtube_dlc/options.py6
-rw-r--r--youtube_dlc/utils.py2
3 files changed, 16 insertions, 10 deletions
diff --git a/youtube_dlc/__init__.py b/youtube_dlc/__init__.py
index c17e9a3df..d28510467 100644
--- a/youtube_dlc/__init__.py
+++ b/youtube_dlc/__init__.py
@@ -15,7 +15,6 @@ import sys
from .options import (
parseOpts,
- _remux_formats,
)
from .compat import (
compat_getpass,
@@ -32,11 +31,12 @@ from .utils import (
preferredencoding,
read_batch_urls,
RejectedVideoReached,
+ REMUX_EXTENSIONS,
+ render_table,
SameFileError,
setproctitle,
std_headers,
write_string,
- render_table,
)
from .update import update_self
from .downloader import (
@@ -210,13 +210,15 @@ def _real_main(argv=None):
if not opts.audioquality.isdigit():
parser.error('invalid audio quality specified')
if opts.recodevideo is not None:
- if opts.recodevideo not in _remux_formats:
+ if opts.recodevideo not in REMUX_EXTENSIONS:
parser.error('invalid video recode format specified')
if opts.remuxvideo and opts.recodevideo:
opts.remuxvideo = None
write_string('WARNING: --remux-video is ignored since --recode-video was given\n', out=sys.stderr)
if opts.remuxvideo is not None:
- if opts.remuxvideo not in _remux_formats:
+ 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):
parser.error('invalid video remux format specified')
if opts.convertsubtitles is not None:
if opts.convertsubtitles not in ['srt', 'vtt', 'ass', 'lrc']:
@@ -352,7 +354,11 @@ def _real_main(argv=None):
opts.postprocessor_args.setdefault('sponskrub', [])
opts.postprocessor_args['default'] = opts.postprocessor_args['default-compat']
- audio_ext = opts.audioformat if (opts.extractaudio and opts.audioformat != 'best') else None
+ 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)
match_filter = (
None if opts.match_filter is None
@@ -473,7 +479,7 @@ def _real_main(argv=None):
'extract_flat': opts.extract_flat,
'mark_watched': opts.mark_watched,
'merge_output_format': opts.merge_output_format,
- 'final_ext': opts.recodevideo or opts.remuxvideo or audio_ext,
+ 'final_ext': final_ext,
'postprocessors': postprocessors,
'fixup': opts.fixup,
'source_address': opts.source_address,
diff --git a/youtube_dlc/options.py b/youtube_dlc/options.py
index 06273c20a..a7c870171 100644
--- a/youtube_dlc/options.py
+++ b/youtube_dlc/options.py
@@ -18,14 +18,12 @@ from .utils import (
get_executable_path,
OUTTMPL_TYPES,
preferredencoding,
+ REMUX_EXTENSIONS,
write_string,
)
from .version import __version__
-_remux_formats = ('mp4', 'mkv', 'flv', 'webm', 'mov', 'avi', 'mp3', 'mka', 'm4a', 'ogg', 'opus')
-
-
def _hide_login_info(opts):
PRIVATE_OPTS = set(['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username'])
eqre = re.compile('^(?P<key>' + ('|'.join(re.escape(po) for po in PRIVATE_OPTS)) + ')=.+$')
@@ -1042,7 +1040,7 @@ def parseOpts(overrideArguments=None):
'Remux the video into another container if necessary (currently supported: %s). '
'If target container does not support the video/audio codec, remuxing will fail. '
'You can specify multiple rules; eg. "aac>m4a/mov>mp4/mkv" will remux aac to m4a, mov to mp4 '
- 'and anything else to mkv.' % '|'.join(_remux_formats)))
+ 'and anything else to mkv.' % '|'.join(REMUX_EXTENSIONS)))
postproc.add_option(
'--recode-video',
metavar='FORMAT', dest='recodevideo', default=None,
diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py
index 79a0f6a63..f4ee52afb 100644
--- a/youtube_dlc/utils.py
+++ b/youtube_dlc/utils.py
@@ -1715,6 +1715,8 @@ KNOWN_EXTENSIONS = (
'wav',
'f4f', 'f4m', 'm3u8', 'smil')
+REMUX_EXTENSIONS = ('mp4', 'mkv', 'flv', 'webm', 'mov', 'avi', 'mp3', 'mka', 'm4a', 'ogg', 'opus')
+
# needed for sanitizing filenames in restricted mode
ACCENT_CHARS = dict(zip('ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖŐØŒÙÚÛÜŰÝÞßàáâãäåæçèéêëìíîïðñòóôõöőøœùúûüűýþÿ',
itertools.chain('AAAAAA', ['AE'], 'CEEEEIIIIDNOOOOOOO', ['OE'], 'UUUUUY', ['TH', 'ss'],