]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/postprocessor/atomicparsley.py
Merge tag 'upstream/2014.07.11'
[youtubedl] / youtube_dl / postprocessor / atomicparsley.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4
5 import os
6 import subprocess
7
8 from .common import PostProcessor
9
10 from ..utils import (
11 check_executable,
12 compat_urlretrieve,
13 encodeFilename,
14 PostProcessingError,
15 prepend_extension,
16 shell_quote
17 )
18
19
20 class AtomicParsleyPPError(PostProcessingError):
21 pass
22
23
24 class AtomicParsleyPP(PostProcessor):
25 def run(self, info):
26 if not check_executable('AtomicParsley', ['-v']):
27 raise AtomicParsleyPPError('AtomicParsley was not found. Please install.')
28
29 filename = info['filepath']
30 temp_filename = prepend_extension(filename, 'temp')
31 temp_thumbnail = prepend_extension(filename, 'thumb')
32
33 if not info.get('thumbnail'):
34 raise AtomicParsleyPPError('Thumbnail was not found. Nothing to do.')
35
36 compat_urlretrieve(info['thumbnail'], temp_thumbnail)
37
38 cmd = ['AtomicParsley', filename, '--artwork', temp_thumbnail, '-o', temp_filename]
39
40 self._downloader.to_screen('[atomicparsley] Adding thumbnail to "%s"' % filename)
41
42 if self._downloader.params.get('verbose', False):
43 self._downloader.to_screen('[debug] AtomicParsley command line: %s' % shell_quote(cmd))
44
45 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
46 stdout, stderr = p.communicate()
47
48 if p.returncode != 0:
49 msg = stderr.decode('utf-8', 'replace').strip()
50 raise AtomicParsleyPPError(msg)
51
52 os.remove(encodeFilename(filename))
53 os.remove(encodeFilename(temp_thumbnail))
54 os.rename(encodeFilename(temp_filename), encodeFilename(filename))
55
56 return True, info