mirror of https://github.com/yt-dlp/yt-dlp
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
10 years ago
|
from __future__ import unicode_literals
|
||
10 years ago
|
|
||
10 years ago
|
import subprocess
|
||
10 years ago
|
|
||
|
from .common import PostProcessor
|
||
9 years ago
|
from ..compat import compat_shlex_quote
|
||
8 years ago
|
from ..utils import (
|
||
|
encodeArgument,
|
||
|
PostProcessingError,
|
||
3 years ago
|
variadic,
|
||
8 years ago
|
)
|
||
10 years ago
|
|
||
|
|
||
3 years ago
|
class ExecPP(PostProcessor):
|
||
4 years ago
|
|
||
10 years ago
|
def __init__(self, downloader, exec_cmd):
|
||
3 years ago
|
PostProcessor.__init__(self, downloader)
|
||
3 years ago
|
self.exec_cmd = variadic(exec_cmd)
|
||
10 years ago
|
|
||
4 years ago
|
def parse_cmd(self, cmd, info):
|
||
3 years ago
|
tmpl, tmpl_dict = self._downloader.prepare_outtmpl(cmd, info)
|
||
|
if tmpl_dict: # if there are no replacements, tmpl_dict = {}
|
||
3 years ago
|
return self._downloader.escape_outtmpl(tmpl) % tmpl_dict
|
||
3 years ago
|
|
||
|
# If no replacements are found, replace {} for backard compatibility
|
||
|
if '{}' not in cmd:
|
||
|
cmd += ' {}'
|
||
3 years ago
|
return cmd.replace('{}', compat_shlex_quote(
|
||
|
info.get('filepath') or info['_filename']))
|
||
10 years ago
|
|
||
4 years ago
|
def run(self, info):
|
||
3 years ago
|
for tmpl in self.exec_cmd:
|
||
|
cmd = self.parse_cmd(tmpl, info)
|
||
|
self.to_screen('Executing command: %s' % cmd)
|
||
|
retCode = subprocess.call(encodeArgument(cmd), shell=True)
|
||
|
if retCode != 0:
|
||
|
raise PostProcessingError('Command returned error code %d' % retCode)
|
||
4 years ago
|
return [], info
|
||
3 years ago
|
|
||
|
|
||
|
class ExecAfterDownloadPP(ExecPP): # for backward compatibility
|
||
|
pass
|