1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
8 from .common import PostProcessor
21 class AtomicParsleyPPError(PostProcessingError):
25 class AtomicParsleyPP(PostProcessor):
27 if not check_executable('AtomicParsley', ['-v']):
28 raise AtomicParsleyPPError('AtomicParsley was not found. Please install.')
30 filename = info['filepath']
31 temp_filename = prepend_extension(filename, 'temp')
32 temp_thumbnail = prepend_extension(filename, 'thumb')
34 if not info.get('thumbnail'):
35 raise AtomicParsleyPPError('Thumbnail was not found. Nothing to do.')
37 compat_urlretrieve(info['thumbnail'], temp_thumbnail)
39 cmd = ['AtomicParsley', filename, '--artwork', temp_thumbnail, '-o', temp_filename]
41 self._downloader.to_screen('[atomicparsley] Adding thumbnail to "%s"' % filename)
43 if self._downloader.params.get('verbose', False):
44 self._downloader.to_screen('[debug] AtomicParsley command line: %s' % shell_quote(cmd))
46 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
47 stdout, stderr = p.communicate()
50 msg = stderr.decode('utf-8', 'replace').strip()
51 raise AtomicParsleyPPError(msg)
53 os.remove(encodeFilename(filename))
54 os.remove(encodeFilename(temp_thumbnail))
55 os.rename(encodeFilename(temp_filename), encodeFilename(filename))