A feature-rich command-line audio/video downloader
[utils, cleanup] Consolidate known media extensions
pukkandan8dc593051132
diff --git a/README.md b/README.mdindex 59e26c49f0..607e929890 100644--- a/README.md+++ b/README.md@@ -916,7 +916,7 @@ You can also fork the project on github and run your fork's [build workflow](.gi(requires ffmpeg and ffprobe)--audio-format FORMAT Format to convert the audio to when -x isused. (currently supported: best (default),- mp3, aac, m4a, opus, vorbis, flac, alac,+ aac, alac, flac, m4a, mp3, opus, vorbis,wav). You can specify multiple rules usingsimilar syntax as --remux-video--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](.gibetween 0 (best) and 10 (worst) for VBR or aspecific bitrate like 128K (default 5)--remux-video FORMAT Remux the video into another container if- necessary (currently supported: mp4, mkv,- flv, webm, mov, avi, mka, ogg, mp3, aac,- m4a, opus, vorbis, flac, alac, wav). If+ necessary (currently supported: avi, flv,+ mkv, mov, mp4, webm, aac, aiff, alac, flac,+ m4a, mka, mp3, ogg, opus, vorbis, wav). Iftarget container does not support thevideo/audio codec, remuxing will fail. Youcan specify multiple rules; Eg.@@ -1025,7 +1025,7 @@ You can also fork the project on github and run your fork's [build workflow](.gibe used multiple times--no-exec Remove any previously defined --exec--convert-subs FORMAT Convert the subtitles to another format- (currently supported: srt, vtt, ass, lrc)+ (currently supported: ass, lrc, srt, vtt)(Alias: --convert-subtitles)--convert-thumbnails FORMAT Convert the thumbnails to another format(currently supported: jpg, png, webp). Youdiff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.pyindex 38a8bb6c1a..e9a51cba40 100644--- a/yt_dlp/YoutubeDL.py+++ b/yt_dlp/YoutubeDL.py@@ -52,6 +52,7 @@ from .utils import (DEFAULT_OUTTMPL,IDENTITY,LINK_TEMPLATES,+ MEDIA_EXTENSIONS,NO_DEFAULT,NUMBER_RE,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'}_format_selection_exts = {- 'audio': {'m4a', 'mp3', 'ogg', 'aac'},- 'video': {'mp4', 'flv', 'webm', '3gp'},- 'storyboards': {'mhtml'},+ 'audio': set(MEDIA_EXTENSIONS.common_audio),+ 'video': set(MEDIA_EXTENSIONS.common_video + ('3gp', )),+ 'storyboards': set(MEDIA_EXTENSIONS.storyboards),}def __init__(self, params=None, auto_init=True):diff --git a/yt_dlp/__init__.py b/yt_dlp/__init__.pyindex 24f6153e05..0bff4e7c82 100644--- a/yt_dlp/__init__.py+++ b/yt_dlp/__init__.py@@ -19,8 +19,8 @@ from .extractor.adobepass import MSO_INFOfrom .extractor.common import InfoExtractorfrom .options import parseOptsfrom .postprocessor import (- FFmpegPostProcessor,FFmpegExtractAudioPP,+ FFmpegPostProcessor,FFmpegSubtitlesConvertorPP,FFmpegThumbnailsConvertorPP,FFmpegVideoConvertorPP,diff --git a/yt_dlp/options.py b/yt_dlp/options.pyindex 1e23e2b98c..43d1af96df 100644--- a/yt_dlp/options.py+++ b/yt_dlp/options.py@@ -972,7 +972,7 @@ def create_parser():}, help=('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. '- 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. ''For example, --downloader aria2c --downloader "dash,m3u8:native" will use ''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',help=('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'))postproc.add_option('--audio-quality', metavar='QUALITY',@@ -1652,13 +1652,13 @@ def create_parser():metavar='FORMAT', dest='convertsubtitles', default=None,help=('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('--convert-thumbnails',metavar='FORMAT', dest='convertthumbnails', default=None,help=('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'))postproc.add_option('--split-chapters', '--split-tracks',diff --git a/yt_dlp/postprocessor/ffmpeg.py b/yt_dlp/postprocessor/ffmpeg.pyindex f77ca427e3..c4dc99fe87 100644--- a/yt_dlp/postprocessor/ffmpeg.py+++ b/yt_dlp/postprocessor/ffmpeg.py@@ -10,6 +10,7 @@ import timefrom .common import PostProcessorfrom ..compat import functools, imghdrfrom ..utils import (+ MEDIA_EXTENSIONS,ISO639Utils,Popen,PostProcessingError,@@ -424,7 +425,7 @@ class FFmpegPostProcessor(PostProcessor):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())FORMAT_RE = create_mapping_re(('best', *SUPPORTED_EXTS))@@ -531,7 +532,7 @@ class FFmpegExtractAudioPP(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)_ACTION = 'converting'@@ -924,7 +925,7 @@ class FFmpegFixupDuplicateMoovPP(FFmpegCopyStreamPP):class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):- SUPPORTED_EXTS = ('srt', 'vtt', 'ass', 'lrc')+ SUPPORTED_EXTS = MEDIA_EXTENSIONS.subtitlesdef __init__(self, downloader=None, format=None):super().__init__(downloader)@@ -1046,7 +1047,7 @@ class FFmpegSplitChaptersPP(FFmpegPostProcessor):class FFmpegThumbnailsConvertorPP(FFmpegPostProcessor):- SUPPORTED_EXTS = ('jpg', 'png', 'webp')+ SUPPORTED_EXTS = MEDIA_EXTENSIONS.thumbnailsFORMAT_RE = create_mapping_re(SUPPORTED_EXTS)def __init__(self, downloader=None, format=None):diff --git a/yt_dlp/utils.py b/yt_dlp/utils.pyindex 3145690f30..fcc25388d8 100644--- a/yt_dlp/utils.py+++ b/yt_dlp/utils.py@@ -150,22 +150,6 @@ MONTH_NAMES = {'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 modeACCENT_CHARS = dict(zip('ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖŐØŒÙÚÛÜŰÝÞßàáâãäåæçèéêëìíîïðñòóôõöőøœùúûüűýþÿ',itertools.chain('AAAAAA', ['AE'], 'CEEEEIIIIDNOOOOOOO', ['OE'], 'UUUUUY', ['TH', 'ss'],@@ -5647,6 +5631,22 @@ class Namespace(types.SimpleNamespace):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)++# Deprecatedhas_certifi = bool(certifi)has_websockets = bool(websockets)