aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/postprocessor
diff options
context:
space:
mode:
Diffstat (limited to 'youtube_dl/postprocessor')
-rw-r--r--youtube_dl/postprocessor/__init__.py4
-rw-r--r--youtube_dl/postprocessor/atomicparsley.py59
-rw-r--r--youtube_dl/postprocessor/ffmpeg.py14
3 files changed, 77 insertions, 0 deletions
diff --git a/youtube_dl/postprocessor/__init__.py b/youtube_dl/postprocessor/__init__.py
index 7f19f717f..9410dcf5b 100644
--- a/youtube_dl/postprocessor/__init__.py
+++ b/youtube_dl/postprocessor/__init__.py
@@ -1,5 +1,7 @@
+from .atomicparsley import AtomicParsleyPP
from .ffmpeg import (
+ FFmpegMediaFixPP,
FFmpegMergerPP,
FFmpegMetadataPP,
FFmpegVideoConvertor,
@@ -9,6 +11,8 @@ from .ffmpeg import (
from .xattrpp import XAttrMetadataPP
__all__ = [
+ 'AtomicParsleyPP',
+ 'FFmpegMediaFixPP',
'FFmpegMergerPP',
'FFmpegMetadataPP',
'FFmpegVideoConvertor',
diff --git a/youtube_dl/postprocessor/atomicparsley.py b/youtube_dl/postprocessor/atomicparsley.py
new file mode 100644
index 000000000..0f7cf5417
--- /dev/null
+++ b/youtube_dl/postprocessor/atomicparsley.py
@@ -0,0 +1,59 @@
+# -*- 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 __init__(self, downloader=None):
+ PostProcessor.__init__(self, downloader)
+
+ 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 c22f2cdc6..26a70491a 100644
--- a/youtube_dl/postprocessor/ffmpeg.py
+++ b/youtube_dl/postprocessor/ffmpeg.py
@@ -483,3 +483,17 @@ class FFmpegMergerPP(FFmpegPostProcessor):
self.run_ffmpeg_multiple_files(info['__files_to_merge'], filename, args)
return True, info
+
+class FFmpegMediaFixPP(FFmpegPostProcessor):
+ def run(self, info):
+ filename = info['filepath']
+ temp_filename = prepend_extension(filename, 'temp')
+
+ options = ['-vcodec', 'copy', '-acodec', 'copy']
+ self._downloader.to_screen(u'[ffmpeg] Fixing media file "%s"' % filename)
+ self.run_ffmpeg(filename, temp_filename, options)
+
+ os.remove(encodeFilename(filename))
+ os.rename(encodeFilename(temp_filename), encodeFilename(filename))
+
+ return True, info