diff options
author | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com> | 2014-04-12 15:52:42 +0200 |
---|---|---|
committer | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com> | 2014-04-12 15:52:42 +0200 |
commit | 77477fa4c916599e7eaa236a3f3eb5703923cf91 (patch) | |
tree | 527528edd5feb3eccd088ad171d1e868d0a010ea /youtube_dl | |
parent | 381640e3acf65e9eac52b6ad47d7f7cad45a7d6d (diff) | |
parent | a169e18ce16567ef123007a22758bcda48d07f92 (diff) |
Merge branch 'atomicparsley' (closes #2436)
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/__init__.py | 8 | ||||
-rw-r--r-- | youtube_dl/postprocessor/__init__.py | 4 | ||||
-rw-r--r-- | youtube_dl/postprocessor/atomicparsley.py | 56 | ||||
-rw-r--r-- | youtube_dl/postprocessor/ffmpeg.py | 20 |
4 files changed, 87 insertions, 1 deletions
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 7e504b75c..42ef13786 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -92,6 +92,8 @@ from .extractor import gen_extractors from .version import __version__ from .YoutubeDL import YoutubeDL from .postprocessor import ( + AtomicParsleyPP, + FFmpegAudioFixPP, FFmpegMetadataPP, FFmpegVideoConvertor, FFmpegExtractAudioPP, @@ -503,6 +505,8 @@ def parseOpts(overrideArguments=None): help='do not overwrite post-processed files; the post-processed files are overwritten by default') postproc.add_option('--embed-subs', action='store_true', dest='embedsubtitles', default=False, help='embed subtitles in the video (only for mp4 videos)') + postproc.add_option('--embed-thumbnail', action='store_true', dest='embedthumbnail', default=False, + help='embed thumbnail in the audio as cover art') postproc.add_option('--add-metadata', action='store_true', dest='addmetadata', default=False, help='write metadata to the video file') postproc.add_option('--xattrs', action='store_true', dest='xattrs', default=False, @@ -808,6 +812,10 @@ def _real_main(argv=None): ydl.add_post_processor(FFmpegEmbedSubtitlePP(subtitlesformat=opts.subtitlesformat)) if opts.xattrs: ydl.add_post_processor(XAttrMetadataPP()) + if opts.embedthumbnail: + if not opts.addmetadata: + ydl.add_post_processor(FFmpegAudioFixPP()) + ydl.add_post_processor(AtomicParsleyPP()) # Update version if opts.update_self: diff --git a/youtube_dl/postprocessor/__init__.py b/youtube_dl/postprocessor/__init__.py index 7f19f717f..08e6ddd00 100644 --- a/youtube_dl/postprocessor/__init__.py +++ b/youtube_dl/postprocessor/__init__.py @@ -1,5 +1,7 @@ +from .atomicparsley import AtomicParsleyPP from .ffmpeg import ( + FFmpegAudioFixPP, FFmpegMergerPP, FFmpegMetadataPP, FFmpegVideoConvertor, @@ -9,6 +11,8 @@ from .ffmpeg import ( from .xattrpp import XAttrMetadataPP __all__ = [ + 'AtomicParsleyPP', + 'FFmpegAudioFixPP', 'FFmpegMergerPP', 'FFmpegMetadataPP', 'FFmpegVideoConvertor', diff --git a/youtube_dl/postprocessor/atomicparsley.py b/youtube_dl/postprocessor/atomicparsley.py new file mode 100644 index 000000000..765b2d9ee --- /dev/null +++ b/youtube_dl/postprocessor/atomicparsley.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + + +import os +import subprocess + +from .common import PostProcessor + +from ..utils import ( + check_executable, + compat_urlretrieve, + encodeFilename, + PostProcessingError, + prepend_extension, + shell_quote +) + + +class AtomicParsleyPPError(PostProcessingError): + pass + + +class AtomicParsleyPP(PostProcessor): + def run(self, info): + if not check_executable('AtomicParsley', ['-v']): + raise AtomicParsleyPPError('AtomicParsley was not found. Please install.') + + filename = info['filepath'] + temp_filename = prepend_extension(filename, 'temp') + temp_thumbnail = prepend_extension(filename, 'thumb') + + if not info.get('thumbnail'): + raise AtomicParsleyPPError('Thumbnail was not found. Nothing to do.') + + compat_urlretrieve(info['thumbnail'], temp_thumbnail) + + cmd = ['AtomicParsley', filename, '--artwork', temp_thumbnail, '-o', temp_filename] + + self._downloader.to_screen('[atomicparsley] Adding thumbnail to "%s"' % filename) + + if self._downloader.params.get('verbose', False): + self._downloader.to_screen('[debug] AtomicParsley command line: %s' % shell_quote(cmd)) + + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + + if p.returncode != 0: + msg = stderr.decode('utf-8', 'replace').strip() + raise AtomicParsleyPPError(msg) + + os.remove(encodeFilename(filename)) + os.remove(encodeFilename(temp_thumbnail)) + os.rename(encodeFilename(temp_filename), encodeFilename(filename)) + + return True, info diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py index 8922920cd..602e370f4 100644 --- a/youtube_dl/postprocessor/ffmpeg.py +++ b/youtube_dl/postprocessor/ffmpeg.py @@ -464,7 +464,11 @@ class FFmpegMetadataPP(FFmpegPostProcessor): filename = info['filepath'] temp_filename = prepend_extension(filename, 'temp') - options = ['-c', 'copy'] + if info['ext'] == u'm4a': + options = ['-vn', '-acodec', 'copy'] + else: + options = ['-c', 'copy'] + for (name, value) in metadata.items(): options.extend(['-metadata', '%s=%s' % (name, value)]) @@ -483,3 +487,17 @@ class FFmpegMergerPP(FFmpegPostProcessor): self.run_ffmpeg_multiple_files(info['__files_to_merge'], filename, args) return True, info + +class FFmpegAudioFixPP(FFmpegPostProcessor): + def run(self, info): + filename = info['filepath'] + temp_filename = prepend_extension(filename, 'temp') + + options = ['-vn', '-acodec', 'copy'] + self._downloader.to_screen(u'[ffmpeg] Fixing audio file "%s"' % filename) + self.run_ffmpeg(filename, temp_filename, options) + + os.remove(encodeFilename(filename)) + os.rename(encodeFilename(temp_filename), encodeFilename(filename)) + + return True, info |