]>
jfr.im git - yt-dlp.git/blob - yt_dlp/postprocessor/exec.py
1 from .common
import PostProcessor
2 from ..compat
import compat_shlex_quote
3 from ..utils
import Popen
, PostProcessingError
, variadic
6 class ExecPP(PostProcessor
):
8 def __init__(self
, downloader
, exec_cmd
):
9 PostProcessor
.__init
__(self
, downloader
)
10 self
.exec_cmd
= variadic(exec_cmd
)
12 def parse_cmd(self
, cmd
, info
):
13 tmpl
, tmpl_dict
= self
._downloader
.prepare_outtmpl(cmd
, info
)
14 if tmpl_dict
: # if there are no replacements, tmpl_dict = {}
15 return self
._downloader
.escape_outtmpl(tmpl
) % tmpl_dict
17 filepath
= info
.get('filepath', info
.get('_filename'))
18 # If video, and no replacements are found, replace {} for backard compatibility
22 cmd
= cmd
.replace('{}', compat_shlex_quote(filepath
))
26 for tmpl
in self
.exec_cmd
:
27 cmd
= self
.parse_cmd(tmpl
, info
)
28 self
.to_screen(f
'Executing command: {cmd}')
29 _
, _
, return_code
= Popen
.run(cmd
, shell
=True)
31 raise PostProcessingError(f
'Command returned error code {return_code}')
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')