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