]>
Commit | Line | Data |
---|---|---|
a2360a4c | 1 | from __future__ import unicode_literals |
8d31fa3c | 2 | |
a2360a4c | 3 | import subprocess |
8d31fa3c PH |
4 | |
5 | from .common import PostProcessor | |
702ccf2d | 6 | from ..compat import compat_shlex_quote |
8b6ac49e S |
7 | from ..utils import ( |
8 | encodeArgument, | |
9 | PostProcessingError, | |
c681cb5d | 10 | variadic, |
8b6ac49e | 11 | ) |
a7cacbca | 12 | |
a7cacbca | 13 | |
ad3dc496 | 14 | class ExecPP(PostProcessor): |
1b77b347 | 15 | |
69b46b3d | 16 | def __init__(self, downloader, exec_cmd): |
ad3dc496 | 17 | PostProcessor.__init__(self, downloader) |
c681cb5d | 18 | self.exec_cmd = variadic(exec_cmd) |
a7cacbca | 19 | |
c6ce8154 | 20 | def parse_cmd(self, cmd, info): |
752cda38 | 21 | tmpl, tmpl_dict = self._downloader.prepare_outtmpl(cmd, info) |
22 | if tmpl_dict: # if there are no replacements, tmpl_dict = {} | |
901130bb | 23 | return self._downloader.escape_outtmpl(tmpl) % tmpl_dict |
752cda38 | 24 | |
25 | # If no replacements are found, replace {} for backard compatibility | |
26 | if '{}' not in cmd: | |
27 | cmd += ' {}' | |
5520aa2d | 28 | return cmd.replace('{}', compat_shlex_quote( |
29 | info.get('filepath') or info['_filename'])) | |
8d31fa3c | 30 | |
c6ce8154 | 31 | def run(self, info): |
c681cb5d | 32 | for tmpl in self.exec_cmd: |
33 | cmd = self.parse_cmd(tmpl, info) | |
34 | self.to_screen('Executing command: %s' % cmd) | |
35 | retCode = subprocess.call(encodeArgument(cmd), shell=True) | |
36 | if retCode != 0: | |
37 | raise PostProcessingError('Command returned error code %d' % retCode) | |
9de3ea31 | 38 | return [], info |
ad3dc496 | 39 | |
40 | ||
ee8dd27a | 41 | # Deprecated |
42 | class ExecAfterDownloadPP(ExecPP): | |
43 | def __init__(self, *args, **kwargs): | |
44 | super().__init__(*args, **kwargs) | |
45 | self.deprecation_warning( | |
46 | 'yt_dlp.postprocessor.ExecAfterDownloadPP is deprecated ' | |
47 | 'and may be removed in a future version. Use yt_dlp.postprocessor.ExecPP instead') |