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(temp_thumbnail))
54 # for formats that don't support thumbnails (like 3gp) AtomicParsley
55 # won't create to the temporary file
56 if b'No changes' in stdout:
57 self._downloader.report_warning('The file format doesn\'t support embedding a thumbnail')
59 os.remove(encodeFilename(filename))
60 os.rename(encodeFilename(temp_filename), encodeFilename(filename))