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