[utils, cleanup] Consolidate known media extensions

pull/4515/head
pukkandan 2 years ago
parent b4daacb4ec
commit 8dc5930511
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39

@ -916,7 +916,7 @@ You can also fork the project on github and run your fork's [build workflow](.gi
(requires ffmpeg and ffprobe) (requires ffmpeg and ffprobe)
--audio-format FORMAT Format to convert the audio to when -x is --audio-format FORMAT Format to convert the audio to when -x is
used. (currently supported: best (default), used. (currently supported: best (default),
mp3, aac, m4a, opus, vorbis, flac, alac, aac, alac, flac, m4a, mp3, opus, vorbis,
wav). You can specify multiple rules using wav). You can specify multiple rules using
similar syntax as --remux-video similar syntax as --remux-video
--audio-quality QUALITY Specify ffmpeg audio quality to use when --audio-quality QUALITY Specify ffmpeg audio quality to use when
@ -924,9 +924,9 @@ You can also fork the project on github and run your fork's [build workflow](.gi
between 0 (best) and 10 (worst) for VBR or a between 0 (best) and 10 (worst) for VBR or a
specific bitrate like 128K (default 5) specific bitrate like 128K (default 5)
--remux-video FORMAT Remux the video into another container if --remux-video FORMAT Remux the video into another container if
necessary (currently supported: mp4, mkv, necessary (currently supported: avi, flv,
flv, webm, mov, avi, mka, ogg, mp3, aac, mkv, mov, mp4, webm, aac, aiff, alac, flac,
m4a, opus, vorbis, flac, alac, wav). If m4a, mka, mp3, ogg, opus, vorbis, wav). If
target container does not support the target container does not support the
video/audio codec, remuxing will fail. You video/audio codec, remuxing will fail. You
can specify multiple rules; Eg. can specify multiple rules; Eg.
@ -1025,7 +1025,7 @@ You can also fork the project on github and run your fork's [build workflow](.gi
be used multiple times be used multiple times
--no-exec Remove any previously defined --exec --no-exec Remove any previously defined --exec
--convert-subs FORMAT Convert the subtitles to another format --convert-subs FORMAT Convert the subtitles to another format
(currently supported: srt, vtt, ass, lrc) (currently supported: ass, lrc, srt, vtt)
(Alias: --convert-subtitles) (Alias: --convert-subtitles)
--convert-thumbnails FORMAT Convert the thumbnails to another format --convert-thumbnails FORMAT Convert the thumbnails to another format
(currently supported: jpg, png, webp). You (currently supported: jpg, png, webp). You

@ -52,6 +52,7 @@ from .utils import (
DEFAULT_OUTTMPL, DEFAULT_OUTTMPL,
IDENTITY, IDENTITY,
LINK_TEMPLATES, LINK_TEMPLATES,
MEDIA_EXTENSIONS,
NO_DEFAULT, NO_DEFAULT,
NUMBER_RE, NUMBER_RE,
OUTTMPL_TYPES, OUTTMPL_TYPES,
@ -543,9 +544,9 @@ class YoutubeDL:
'page_url', 'app', 'play_path', 'tc_url', 'flash_version', 'rtmp_live', 'rtmp_conn', 'rtmp_protocol', 'rtmp_real_time' 'page_url', 'app', 'play_path', 'tc_url', 'flash_version', 'rtmp_live', 'rtmp_conn', 'rtmp_protocol', 'rtmp_real_time'
} }
_format_selection_exts = { _format_selection_exts = {
'audio': {'m4a', 'mp3', 'ogg', 'aac'}, 'audio': set(MEDIA_EXTENSIONS.common_audio),
'video': {'mp4', 'flv', 'webm', '3gp'}, 'video': set(MEDIA_EXTENSIONS.common_video + ('3gp', )),
'storyboards': {'mhtml'}, 'storyboards': set(MEDIA_EXTENSIONS.storyboards),
} }
def __init__(self, params=None, auto_init=True): def __init__(self, params=None, auto_init=True):

@ -19,8 +19,8 @@ from .extractor.adobepass import MSO_INFO
from .extractor.common import InfoExtractor from .extractor.common import InfoExtractor
from .options import parseOpts from .options import parseOpts
from .postprocessor import ( from .postprocessor import (
FFmpegPostProcessor,
FFmpegExtractAudioPP, FFmpegExtractAudioPP,
FFmpegPostProcessor,
FFmpegSubtitlesConvertorPP, FFmpegSubtitlesConvertorPP,
FFmpegThumbnailsConvertorPP, FFmpegThumbnailsConvertorPP,
FFmpegVideoConvertorPP, FFmpegVideoConvertorPP,

@ -972,7 +972,7 @@ def create_parser():
}, help=( }, help=(
'Name or path of the external downloader to use (optionally) prefixed by ' 'Name or path of the external downloader to use (optionally) prefixed by '
'the protocols (http, ftp, m3u8, dash, rstp, rtmp, mms) to use it for. ' 'the protocols (http, ftp, m3u8, dash, rstp, rtmp, mms) to use it for. '
f'Currently supports native, {", ".join(list_external_downloaders())}. ' f'Currently supports native, {", ".join(sorted(list_external_downloaders()))}. '
'You can use this option multiple times to set different downloaders for different protocols. ' 'You can use this option multiple times to set different downloaders for different protocols. '
'For example, --downloader aria2c --downloader "dash,m3u8:native" will use ' 'For example, --downloader aria2c --downloader "dash,m3u8:native" will use '
'aria2c for http/ftp downloads, and the native downloader for dash/m3u8 downloads ' 'aria2c for http/ftp downloads, and the native downloader for dash/m3u8 downloads '
@ -1469,7 +1469,7 @@ def create_parser():
'--audio-format', metavar='FORMAT', dest='audioformat', default='best', '--audio-format', metavar='FORMAT', dest='audioformat', default='best',
help=( help=(
'Format to convert the audio to when -x is used. ' 'Format to convert the audio to when -x is used. '
f'(currently supported: best (default), {", ".join(FFmpegExtractAudioPP.SUPPORTED_EXTS)}). ' f'(currently supported: best (default), {", ".join(sorted(FFmpegExtractAudioPP.SUPPORTED_EXTS))}). '
'You can specify multiple rules using similar syntax as --remux-video')) 'You can specify multiple rules using similar syntax as --remux-video'))
postproc.add_option( postproc.add_option(
'--audio-quality', metavar='QUALITY', '--audio-quality', metavar='QUALITY',
@ -1652,13 +1652,13 @@ def create_parser():
metavar='FORMAT', dest='convertsubtitles', default=None, metavar='FORMAT', dest='convertsubtitles', default=None,
help=( help=(
'Convert the subtitles to another format (currently supported: %s) ' 'Convert the subtitles to another format (currently supported: %s) '
'(Alias: --convert-subtitles)' % ', '.join(FFmpegSubtitlesConvertorPP.SUPPORTED_EXTS))) '(Alias: --convert-subtitles)' % ', '.join(sorted(FFmpegSubtitlesConvertorPP.SUPPORTED_EXTS))))
postproc.add_option( postproc.add_option(
'--convert-thumbnails', '--convert-thumbnails',
metavar='FORMAT', dest='convertthumbnails', default=None, metavar='FORMAT', dest='convertthumbnails', default=None,
help=( help=(
'Convert the thumbnails to another format ' 'Convert the thumbnails to another format '
f'(currently supported: {", ".join(FFmpegThumbnailsConvertorPP.SUPPORTED_EXTS)}). ' f'(currently supported: {", ".join(sorted(FFmpegThumbnailsConvertorPP.SUPPORTED_EXTS))}). '
'You can specify multiple rules using similar syntax as --remux-video')) 'You can specify multiple rules using similar syntax as --remux-video'))
postproc.add_option( postproc.add_option(
'--split-chapters', '--split-tracks', '--split-chapters', '--split-tracks',

@ -10,6 +10,7 @@ import time
from .common import PostProcessor from .common import PostProcessor
from ..compat import functools, imghdr from ..compat import functools, imghdr
from ..utils import ( from ..utils import (
MEDIA_EXTENSIONS,
ISO639Utils, ISO639Utils,
Popen, Popen,
PostProcessingError, PostProcessingError,
@ -424,7 +425,7 @@ class FFmpegPostProcessor(PostProcessor):
class FFmpegExtractAudioPP(FFmpegPostProcessor): class FFmpegExtractAudioPP(FFmpegPostProcessor):
COMMON_AUDIO_EXTS = ('wav', 'flac', 'm4a', 'aiff', 'mp3', 'ogg', 'mka', 'opus', 'wma') COMMON_AUDIO_EXTS = MEDIA_EXTENSIONS.common_audio + ('wma', )
SUPPORTED_EXTS = tuple(ACODECS.keys()) SUPPORTED_EXTS = tuple(ACODECS.keys())
FORMAT_RE = create_mapping_re(('best', *SUPPORTED_EXTS)) FORMAT_RE = create_mapping_re(('best', *SUPPORTED_EXTS))
@ -531,7 +532,7 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
class FFmpegVideoConvertorPP(FFmpegPostProcessor): class FFmpegVideoConvertorPP(FFmpegPostProcessor):
SUPPORTED_EXTS = ('mp4', 'mkv', 'flv', 'webm', 'mov', 'avi', 'mka', 'ogg', *FFmpegExtractAudioPP.SUPPORTED_EXTS) SUPPORTED_EXTS = (*MEDIA_EXTENSIONS.common_video, *sorted(MEDIA_EXTENSIONS.common_audio + ('aac', 'vorbis')))
FORMAT_RE = create_mapping_re(SUPPORTED_EXTS) FORMAT_RE = create_mapping_re(SUPPORTED_EXTS)
_ACTION = 'converting' _ACTION = 'converting'
@ -924,7 +925,7 @@ class FFmpegFixupDuplicateMoovPP(FFmpegCopyStreamPP):
class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor): class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
SUPPORTED_EXTS = ('srt', 'vtt', 'ass', 'lrc') SUPPORTED_EXTS = MEDIA_EXTENSIONS.subtitles
def __init__(self, downloader=None, format=None): def __init__(self, downloader=None, format=None):
super().__init__(downloader) super().__init__(downloader)
@ -1046,7 +1047,7 @@ class FFmpegSplitChaptersPP(FFmpegPostProcessor):
class FFmpegThumbnailsConvertorPP(FFmpegPostProcessor): class FFmpegThumbnailsConvertorPP(FFmpegPostProcessor):
SUPPORTED_EXTS = ('jpg', 'png', 'webp') SUPPORTED_EXTS = MEDIA_EXTENSIONS.thumbnails
FORMAT_RE = create_mapping_re(SUPPORTED_EXTS) FORMAT_RE = create_mapping_re(SUPPORTED_EXTS)
def __init__(self, downloader=None, format=None): def __init__(self, downloader=None, format=None):

@ -150,22 +150,6 @@ MONTH_NAMES = {
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'], 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
} }
KNOWN_EXTENSIONS = (
'mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'aac',
'flv', 'f4v', 'f4a', 'f4b',
'webm', 'ogg', 'ogv', 'oga', 'ogx', 'spx', 'opus',
'mkv', 'mka', 'mk3d',
'avi', 'divx',
'mov',
'asf', 'wmv', 'wma',
'3gp', '3g2',
'mp3',
'mpg',
'flac',
'ape',
'wav',
'f4f', 'f4m', 'm3u8', 'smil')
# needed for sanitizing filenames in restricted mode # needed for sanitizing filenames in restricted mode
ACCENT_CHARS = dict(zip('ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖŐØŒÙÚÛÜŰÝÞßàáâãäåæçèéêëìíîïðñòóôõöőøœùúûüűýþÿ', ACCENT_CHARS = dict(zip('ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖŐØŒÙÚÛÜŰÝÞßàáâãäåæçèéêëìíîïðñòóôõöőøœùúûüűýþÿ',
itertools.chain('AAAAAA', ['AE'], 'CEEEEIIIIDNOOOOOOO', ['OE'], 'UUUUUY', ['TH', 'ss'], itertools.chain('AAAAAA', ['AE'], 'CEEEEIIIIDNOOOOOOO', ['OE'], 'UUUUUY', ['TH', 'ss'],
@ -5647,6 +5631,22 @@ class Namespace(types.SimpleNamespace):
return self.__dict__.items() return self.__dict__.items()
MEDIA_EXTENSIONS = Namespace(
common_video=('avi', 'flv', 'mkv', 'mov', 'mp4', 'webm'),
video=('3g2', '3gp', 'f4v', 'mk3d', 'divx', 'mpg', 'ogv', 'm4v', 'wmv'),
common_audio=('aiff', 'alac', 'flac', 'm4a', 'mka', 'mp3', 'ogg', 'opus', 'wav'),
audio=('aac', 'ape', 'asf', 'f4a', 'f4b', 'm4b', 'm4p', 'm4r', 'oga', 'ogx', 'spx', 'vorbis', 'wma'),
thumbnails=('jpg', 'png', 'webp'),
storyboards=('mhtml', ),
subtitles=('srt', 'vtt', 'ass', 'lrc'),
manifests=('f4f', 'f4m', 'm3u8', 'smil', 'mpd'),
)
MEDIA_EXTENSIONS.video += MEDIA_EXTENSIONS.common_video
MEDIA_EXTENSIONS.audio += MEDIA_EXTENSIONS.common_audio
KNOWN_EXTENSIONS = (*MEDIA_EXTENSIONS.video, *MEDIA_EXTENSIONS.audio, *MEDIA_EXTENSIONS.manifests)
# Deprecated # Deprecated
has_certifi = bool(certifi) has_certifi = bool(certifi)
has_websockets = bool(websockets) has_websockets = bool(websockets)

Loading…
Cancel
Save