1 from .common
import PostProcessor
2 from ..utils
import Popen
, PostProcessingError
, shell_quote
, variadic
5 class ExecPP(PostProcessor
):
7 def __init__(self
, downloader
, exec_cmd
):
8 PostProcessor
.__init
__(self
, downloader
)
9 self
.exec_cmd
= variadic(exec_cmd
)
11 def parse_cmd(self
, cmd
, info
):
12 tmpl
, tmpl_dict
= self
._downloader
.prepare_outtmpl(cmd
, info
)
13 if tmpl_dict
: # if there are no replacements, tmpl_dict = {}
14 return self
._downloader
.escape_outtmpl(tmpl
) % tmpl_dict
16 filepath
= info
.get('filepath', info
.get('_filename'))
17 # If video, and no replacements are found, replace {} for backard compatibility
21 cmd
= cmd
.replace('{}', shell_quote(filepath
))
25 for tmpl
in self
.exec_cmd
:
26 cmd
= self
.parse_cmd(tmpl
, info
)
27 self
.to_screen(f
'Executing command: {cmd}')
28 _
, _
, return_code
= Popen
.run(cmd
, shell
=True)
30 raise PostProcessingError(f
'Command returned error code {return_code}')
35 class ExecAfterDownloadPP(ExecPP
):
36 def __init__(self
, *args
, **kwargs
):
37 super().__init
__(*args
, **kwargs
)
38 self
.deprecation_warning(
39 'yt_dlp.postprocessor.ExecAfterDownloadPP is deprecated '
40 'and may be removed in a future version. Use yt_dlp.postprocessor.ExecPP instead')