]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/postprocessor/execafterdownload.py
New upstream version 2017.09.24
[youtubedl] / youtube_dl / postprocessor / execafterdownload.py
1 from __future__ import unicode_literals
2
3 import subprocess
4
5 from .common import PostProcessor
6 from ..compat import compat_shlex_quote
7 from ..utils import (
8 encodeArgument,
9 PostProcessingError,
10 )
11
12
13 class ExecAfterDownloadPP(PostProcessor):
14 def __init__(self, downloader, exec_cmd):
15 super(ExecAfterDownloadPP, self).__init__(downloader)
16 self.exec_cmd = exec_cmd
17
18 def run(self, information):
19 cmd = self.exec_cmd
20 if '{}' not in cmd:
21 cmd += ' {}'
22
23 cmd = cmd.replace('{}', compat_shlex_quote(information['filepath']))
24
25 self._downloader.to_screen('[exec] Executing command: %s' % cmd)
26 retCode = subprocess.call(encodeArgument(cmd), shell=True)
27 if retCode != 0:
28 raise PostProcessingError(
29 'Command returned error code %d' % retCode)
30
31 return [], information