aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/postprocessor/execafterdownload.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2021-06-03 23:30:38 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2021-06-06 00:59:04 +0530
commit752cda3880f30a46bed1d27b69188ab93ad1a368 (patch)
tree1a6bc38ff775f70f4723be63d6f635f6781d38d6 /yt_dlp/postprocessor/execafterdownload.py
parent9d83ad93d04a1e16fe4a2acadf5f9f10bef6d1b9 (diff)
downloadhypervideo-pre-752cda3880f30a46bed1d27b69188ab93ad1a368.tar.lz
hypervideo-pre-752cda3880f30a46bed1d27b69188ab93ad1a368.tar.xz
hypervideo-pre-752cda3880f30a46bed1d27b69188ab93ad1a368.zip
Fix and refactor `prepare_outtmpl`
The following tests would have failed previously: %(id)d %(id)r %(ext)s-%(ext|def)d %(width|)d %(id)r %(height)r %(formats.0)r %s
Diffstat (limited to 'yt_dlp/postprocessor/execafterdownload.py')
-rw-r--r--yt_dlp/postprocessor/execafterdownload.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/yt_dlp/postprocessor/execafterdownload.py b/yt_dlp/postprocessor/execafterdownload.py
index 9d68583e7..948b3ffb3 100644
--- a/yt_dlp/postprocessor/execafterdownload.py
+++ b/yt_dlp/postprocessor/execafterdownload.py
@@ -1,13 +1,11 @@
from __future__ import unicode_literals
-import re
import subprocess
from .common import PostProcessor
from ..compat import compat_shlex_quote
from ..utils import (
encodeArgument,
- FORMAT_RE,
PostProcessingError,
)
@@ -23,14 +21,14 @@ class ExecAfterDownloadPP(PostProcessor):
return 'Exec'
def parse_cmd(self, cmd, info):
- # If no %(key)s is found, replace {} for backard compatibility
- if not re.search(FORMAT_RE.format(r'[^)]*'), cmd):
- if '{}' not in cmd:
- cmd += ' {}'
- return cmd.replace('{}', compat_shlex_quote(info['filepath']))
-
- tmpl, info_copy = self._downloader.prepare_outtmpl(cmd, info)
- return tmpl % info_copy
+ tmpl, tmpl_dict = self._downloader.prepare_outtmpl(cmd, info)
+ if tmpl_dict: # if there are no replacements, tmpl_dict = {}
+ return tmpl % tmpl_dict
+
+ # If no replacements are found, replace {} for backard compatibility
+ if '{}' not in cmd:
+ cmd += ' {}'
+ return cmd.replace('{}', compat_shlex_quote(info['filepath']))
def run(self, info):
cmd = self.parse_cmd(self.exec_cmd, info)