]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/postprocessor/atomicparsley.py
[rtve] Detect videos that are no longer available
[youtube-dl] / 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 from ..compat import (
10     compat_urlretrieve,
11 )
12 from ..utils import (
13     check_executable,
14     encodeFilename,
15     PostProcessingError,
16     prepend_extension,
17     shell_quote
18 )
19
20
21 class AtomicParsleyPPError(PostProcessingError):
22     pass
23
24
25 class AtomicParsleyPP(PostProcessor):
26     def run(self, info):
27         if not check_executable('AtomicParsley', ['-v']):
28             raise AtomicParsleyPPError('AtomicParsley was not found. Please install.')
29
30         filename = info['filepath']
31         temp_filename = prepend_extension(filename, 'temp')
32         temp_thumbnail = prepend_extension(filename, 'thumb')
33
34         if not info.get('thumbnail'):
35             raise AtomicParsleyPPError('Thumbnail was not found. Nothing to do.')
36
37         compat_urlretrieve(info['thumbnail'], temp_thumbnail)
38
39         cmd = ['AtomicParsley', filename, '--artwork', temp_thumbnail, '-o', temp_filename]
40
41         self._downloader.to_screen('[atomicparsley] Adding thumbnail to "%s"' % filename)
42
43         if self._downloader.params.get('verbose', False):
44             self._downloader.to_screen('[debug] AtomicParsley command line: %s' % shell_quote(cmd))
45
46         p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
47         stdout, stderr = p.communicate()
48
49         if p.returncode != 0:
50             msg = stderr.decode('utf-8', 'replace').strip()
51             raise AtomicParsleyPPError(msg)
52
53         os.remove(encodeFilename(filename))
54         os.remove(encodeFilename(temp_thumbnail))
55         os.rename(encodeFilename(temp_filename), encodeFilename(filename))
56
57         return True, info