diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-06-13 01:32:19 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-06-13 03:45:53 +0530 |
commit | 8326b00aabc332cad3edec246fe5353bea069cb0 (patch) | |
tree | 286e543dd7b6b447b797ceae8bd8655999f97970 /yt_dlp/postprocessor | |
parent | b0249bcaf0f2ac1fafecbf5d44f7403c6f0d5850 (diff) | |
download | hypervideo-pre-8326b00aabc332cad3edec246fe5353bea069cb0.tar.lz hypervideo-pre-8326b00aabc332cad3edec246fe5353bea069cb0.tar.xz hypervideo-pre-8326b00aabc332cad3edec246fe5353bea069cb0.zip |
Allow `images` formats
Necessary for #343.
* They are identified by `vcodec=acodec='none'`
* These formats show as the worst in `-F`
* Any postprocessor that expects audio/video will be skipped
* `b*` and all related selectors will skip such formats
* This commit also does not add any selector for downloading such formats. They have to be explicitly requested by the `format_id`. Implementation of a selector is left for when #389 is resolved
Diffstat (limited to 'yt_dlp/postprocessor')
-rw-r--r-- | yt_dlp/postprocessor/common.py | 20 | ||||
-rw-r--r-- | yt_dlp/postprocessor/embedthumbnail.py | 2 | ||||
-rw-r--r-- | yt_dlp/postprocessor/ffmpeg.py | 9 | ||||
-rw-r--r-- | yt_dlp/postprocessor/sponskrub.py | 1 |
4 files changed, 32 insertions, 0 deletions
diff --git a/yt_dlp/postprocessor/common.py b/yt_dlp/postprocessor/common.py index b6d06f33f..9bd025ff6 100644 --- a/yt_dlp/postprocessor/common.py +++ b/yt_dlp/postprocessor/common.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +import functools import os from ..compat import compat_str @@ -67,6 +68,25 @@ class PostProcessor(object): """Sets the downloader for this PP.""" self._downloader = downloader + @staticmethod + def _restrict_to(*, video=True, audio=True, images=True): + allowed = {'video': video, 'audio': audio, 'images': images} + + def decorator(func): + @functools.wraps(func) + def wrapper(self, info): + format_type = ( + 'video' if info['vcodec'] != 'none' + else 'audio' if info['acodec'] != 'none' + else 'images') + if allowed[format_type]: + func(self, info) + else: + self.to_screen('Skipping %s' % format_type) + return [], info + return wrapper + return decorator + def run(self, information): """Run the PostProcessor. diff --git a/yt_dlp/postprocessor/embedthumbnail.py b/yt_dlp/postprocessor/embedthumbnail.py index 278a45eb6..3ac00b79a 100644 --- a/yt_dlp/postprocessor/embedthumbnail.py +++ b/yt_dlp/postprocessor/embedthumbnail.py @@ -16,6 +16,7 @@ try: except ImportError: has_mutagen = False +from .common import PostProcessor from .ffmpeg import ( FFmpegPostProcessor, FFmpegThumbnailsConvertorPP, @@ -62,6 +63,7 @@ class EmbedThumbnailPP(FFmpegPostProcessor): def _report_run(self, exe, filename): self.to_screen('%s: Adding thumbnail to "%s"' % (exe, filename)) + @PostProcessor._restrict_to(images=False) def run(self, info): filename = info['filepath'] temp_filename = prepend_extension(filename, 'temp') diff --git a/yt_dlp/postprocessor/ffmpeg.py b/yt_dlp/postprocessor/ffmpeg.py index 374da8c02..273f1b763 100644 --- a/yt_dlp/postprocessor/ffmpeg.py +++ b/yt_dlp/postprocessor/ffmpeg.py @@ -310,6 +310,7 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor): except FFmpegPostProcessorError as err: raise AudioConversionError(err.msg) + @PostProcessor._restrict_to(images=False) def run(self, information): path = information['filepath'] orig_ext = information['ext'] @@ -419,6 +420,7 @@ class FFmpegVideoConvertorPP(FFmpegPostProcessor): return ['-c:v', 'libxvid', '-vtag', 'XVID'] return [] + @PostProcessor._restrict_to(images=False) def run(self, information): path, source_ext = information['filepath'], information['ext'].lower() target_ext = self._target_ext(source_ext) @@ -456,6 +458,7 @@ class FFmpegEmbedSubtitlePP(FFmpegPostProcessor): super(FFmpegEmbedSubtitlePP, self).__init__(downloader) self._already_have_subtitle = already_have_subtitle + @PostProcessor._restrict_to(images=False) def run(self, information): if information['ext'] not in ('mp4', 'webm', 'mkv'): self.to_screen('Subtitles can only be embedded in mp4, webm or mkv files') @@ -523,6 +526,7 @@ class FFmpegEmbedSubtitlePP(FFmpegPostProcessor): class FFmpegMetadataPP(FFmpegPostProcessor): + @PostProcessor._restrict_to(images=False) def run(self, info): metadata = {} @@ -625,6 +629,7 @@ class FFmpegMetadataPP(FFmpegPostProcessor): class FFmpegMergerPP(FFmpegPostProcessor): + @PostProcessor._restrict_to(images=False) def run(self, info): filename = info['filepath'] temp_filename = prepend_extension(filename, 'temp') @@ -657,6 +662,7 @@ class FFmpegMergerPP(FFmpegPostProcessor): class FFmpegFixupStretchedPP(FFmpegPostProcessor): + @PostProcessor._restrict_to(images=False, audio=False) def run(self, info): stretched_ratio = info.get('stretched_ratio') if stretched_ratio is None or stretched_ratio == 1: @@ -676,6 +682,7 @@ class FFmpegFixupStretchedPP(FFmpegPostProcessor): class FFmpegFixupM4aPP(FFmpegPostProcessor): + @PostProcessor._restrict_to(images=False, video=False) def run(self, info): if info.get('container') != 'm4a_dash': return [], info @@ -694,6 +701,7 @@ class FFmpegFixupM4aPP(FFmpegPostProcessor): class FFmpegFixupM3u8PP(FFmpegPostProcessor): + @PostProcessor._restrict_to(images=False) def run(self, info): filename = info['filepath'] if self.get_audio_codec(filename) == 'aac': @@ -805,6 +813,7 @@ class FFmpegSplitChaptersPP(FFmpegPostProcessor): ['-ss', compat_str(chapter['start_time']), '-t', compat_str(chapter['end_time'] - chapter['start_time'])]) + @PostProcessor._restrict_to(images=False) def run(self, info): chapters = info.get('chapters') or [] if not chapters: diff --git a/yt_dlp/postprocessor/sponskrub.py b/yt_dlp/postprocessor/sponskrub.py index 51f841ac4..73b6b4a20 100644 --- a/yt_dlp/postprocessor/sponskrub.py +++ b/yt_dlp/postprocessor/sponskrub.py @@ -41,6 +41,7 @@ class SponSkrubPP(PostProcessor): return None return path + @PostProcessor._restrict_to(images=False) def run(self, information): if self.path is None: return [], information |