diff options
author | pulpe <Pulpan3@gmail.com> | 2014-02-22 13:55:51 +0100 |
---|---|---|
committer | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com> | 2014-03-26 15:22:51 +0100 |
commit | 0c14e2fbe3c5cba16af27525aa6715819226e6d8 (patch) | |
tree | 15a314fddb62e975c73a3f82991324508dbc896b /youtube_dl/postprocessor/atomicparsley.py | |
parent | 98acdc895bb6795efa1b5890a7af1b6e662051bd (diff) |
add post processor
Diffstat (limited to 'youtube_dl/postprocessor/atomicparsley.py')
-rw-r--r-- | youtube_dl/postprocessor/atomicparsley.py | 59 |
1 files changed, 59 insertions, 0 deletions
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 |