]>
jfr.im git - yt-dlp.git/blob - yt_dlp/postprocessor/exec.py
1 from __future__
import unicode_literals
5 from .common
import PostProcessor
6 from ..compat
import compat_shlex_quote
14 class ExecPP(PostProcessor
):
16 def __init__(self
, downloader
, exec_cmd
):
17 PostProcessor
.__init
__(self
, downloader
)
18 self
.exec_cmd
= variadic(exec_cmd
)
20 def parse_cmd(self
, cmd
, info
):
21 tmpl
, tmpl_dict
= self
._downloader
.prepare_outtmpl(cmd
, info
)
22 if tmpl_dict
: # if there are no replacements, tmpl_dict = {}
23 return self
._downloader
.escape_outtmpl(tmpl
) % tmpl_dict
25 filepath
= info
.get('filepath', info
.get('_filename'))
26 # If video, and no replacements are found, replace {} for backard compatibility
30 cmd
= cmd
.replace('{}', compat_shlex_quote(filepath
))
34 for tmpl
in self
.exec_cmd
:
35 cmd
= self
.parse_cmd(tmpl
, info
)
36 self
.to_screen('Executing command: %s' % cmd
)
37 retCode
= subprocess
.call(encodeArgument(cmd
), shell
=True)
39 raise PostProcessingError('Command returned error code %d' % retCode
)
44 class ExecAfterDownloadPP(ExecPP
):
45 def __init__(self
, *args
, **kwargs
):
46 super().__init
__(*args
, **kwargs
)
47 self
.deprecation_warning(
48 'yt_dlp.postprocessor.ExecAfterDownloadPP is deprecated '
49 'and may be removed in a future version. Use yt_dlp.postprocessor.ExecPP instead')