expose info to exec arg

This commit is contained in:
joncody 2018-04-07 19:00:39 -07:00
parent 960ef979cd
commit ac511509bf

View File

@ -1,6 +1,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import subprocess import subprocess
import sys
import numbers
from .common import PostProcessor from .common import PostProcessor
from ..compat import compat_shlex_quote from ..compat import compat_shlex_quote
@ -17,14 +19,15 @@ class ExecAfterDownloadPP(PostProcessor):
def run(self, information): def run(self, information):
cmd = self.exec_cmd cmd = self.exec_cmd
if '{}' not in cmd: info = {}
cmd += ' {}'
# expose the playlist_index and title variables to exec argument for key in information:
# youtube-dl -x -o "%(playlist_index)s - %(title)s.%(ext)s" --exec "id3v2 -T {playlist_index} -t {title} {}" PLAYLIST_ID value = information[key]
cmd = cmd.replace('{}', compat_shlex_quote(information['filepath'])) info[key] = compat_shlex_quote(value) if isinstance(value, (str, unicode)) else value
cmd = cmd.replace('{title}', compat_shlex_quote(information['title']))
cmd = cmd.replace('{playlist_index}', str(information['playlist_index'])) # expose info to exec argument
# youtube-dl -x -o "%(playlist_index)s - %(title)s.%(ext)s" --exec "id3v2 -T {0[playlist_index]} -t {0[title]} {0[filepath]}" PLAYLIST_ID
cmd = cmd.format(info)
self._downloader.to_screen('[exec] Executing command: %s' % cmd) self._downloader.to_screen('[exec] Executing command: %s' % cmd)
retCode = subprocess.call(encodeArgument(cmd), shell=True) retCode = subprocess.call(encodeArgument(cmd), shell=True)