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