]> jfr.im git - yt-dlp.git/blame_incremental - youtube_dlc/postprocessor/execafterdownload.py
Improved passing of multiple postprocessor-args
[yt-dlp.git] / youtube_dlc / postprocessor / execafterdownload.py
... / ...
CommitLineData
1from __future__ import unicode_literals
2
3import subprocess
4
5from .common import PostProcessor
6from ..compat import compat_shlex_quote
7from ..utils import (
8 encodeArgument,
9 PostProcessingError,
10)
11
12
13class ExecAfterDownloadPP(PostProcessor):
14
15 def __init__(self, downloader, exec_cmd):
16 super(ExecAfterDownloadPP, self).__init__(downloader)
17 self.exec_cmd = exec_cmd
18
19 @classmethod
20 def pp_key(cls):
21 return 'Exec'
22
23 def run(self, information):
24 cmd = self.exec_cmd
25 if '{}' not in cmd:
26 cmd += ' {}'
27
28 cmd = cmd.replace('{}', compat_shlex_quote(information['filepath']))
29
30 self.to_screen('Executing command: %s' % cmd)
31 retCode = subprocess.call(encodeArgument(cmd), shell=True)
32 if retCode != 0:
33 raise PostProcessingError(
34 'Command returned error code %d' % retCode)
35
36 return [], information