]>
jfr.im git - yt-dlp.git/blob - yt_dlp/postprocessor/exec.py
3 from .common
import PostProcessor
4 from ..compat
import compat_shlex_quote
5 from ..utils
import PostProcessingError
, encodeArgument
, variadic
8 class ExecPP(PostProcessor
):
10 def __init__(self
, downloader
, exec_cmd
):
11 PostProcessor
.__init
__(self
, downloader
)
12 self
.exec_cmd
= variadic(exec_cmd
)
14 def parse_cmd(self
, cmd
, info
):
15 tmpl
, tmpl_dict
= self
._downloader
.prepare_outtmpl(cmd
, info
)
16 if tmpl_dict
: # if there are no replacements, tmpl_dict = {}
17 return self
._downloader
.escape_outtmpl(tmpl
) % tmpl_dict
19 filepath
= info
.get('filepath', info
.get('_filename'))
20 # If video, and no replacements are found, replace {} for backard compatibility
24 cmd
= cmd
.replace('{}', compat_shlex_quote(filepath
))
28 for tmpl
in self
.exec_cmd
:
29 cmd
= self
.parse_cmd(tmpl
, info
)
30 self
.to_screen('Executing command: %s' % cmd
)
31 retCode
= subprocess
.call(encodeArgument(cmd
), shell
=True)
33 raise PostProcessingError('Command returned error code %d' % retCode
)
38 class ExecAfterDownloadPP(ExecPP
):
39 def __init__(self
, *args
, **kwargs
):
40 super().__init
__(*args
, **kwargs
)
41 self
.deprecation_warning(
42 'yt_dlp.postprocessor.ExecAfterDownloadPP is deprecated '
43 'and may be removed in a future version. Use yt_dlp.postprocessor.ExecPP instead')