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