mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-10 00:58:17 +02:00
Allow multiple --exec
and --exec-before-download
This commit is contained in:
parent
379e44ed3c
commit
c681cb5d93
@ -1277,17 +1277,31 @@ def _dict_from_options_callback(
|
|||||||
dest='ffmpeg_location',
|
dest='ffmpeg_location',
|
||||||
help='Location of the ffmpeg binary; either the path to the binary or its containing directory')
|
help='Location of the ffmpeg binary; either the path to the binary or its containing directory')
|
||||||
postproc.add_option(
|
postproc.add_option(
|
||||||
'--exec',
|
'--exec', metavar='CMD',
|
||||||
metavar='CMD', dest='exec_cmd',
|
action='callback', dest='exec_cmd', default=[], type='str',
|
||||||
|
callback=_list_from_options_callback, callback_kwargs={'delim': None},
|
||||||
help=(
|
help=(
|
||||||
'Execute a command on the file after downloading and post-processing. '
|
'Execute a command on the file after downloading and post-processing. '
|
||||||
'Similar syntax to the output template can be used to pass any field as arguments to the command. '
|
'Similar syntax to the output template can be used to pass any field as arguments to the command. '
|
||||||
'An additional field "filepath" that contains the final path of the downloaded file is also available. '
|
'An additional field "filepath" that contains the final path of the downloaded file is also available. '
|
||||||
'If no fields are passed, %(filepath)q is appended to the end of the command'))
|
'If no fields are passed, %(filepath)q is appended to the end of the command. '
|
||||||
|
'This option can be used multiple times'))
|
||||||
postproc.add_option(
|
postproc.add_option(
|
||||||
'--exec-before-download',
|
'--no-exec',
|
||||||
metavar='CMD', dest='exec_before_dl_cmd',
|
action='store_const', dest='exec_cmd', const=[],
|
||||||
help='Execute a command before the actual download. The syntax is the same as --exec but "filepath" is not available')
|
help='Remove any previously defined --exec')
|
||||||
|
postproc.add_option(
|
||||||
|
'--exec-before-download', metavar='CMD',
|
||||||
|
action='callback', dest='exec_before_dl_cmd', default=[], type='str',
|
||||||
|
callback=_list_from_options_callback, callback_kwargs={'delim': None},
|
||||||
|
help=(
|
||||||
|
'Execute a command before the actual download. '
|
||||||
|
'The syntax is the same as --exec but "filepath" is not available. '
|
||||||
|
'This option can be used multiple times'))
|
||||||
|
postproc.add_option(
|
||||||
|
'--no-exec-before-download',
|
||||||
|
action='store_const', dest='exec_before_dl_cmd', const=[],
|
||||||
|
help='Remove any previously defined --exec-before-download')
|
||||||
postproc.add_option(
|
postproc.add_option(
|
||||||
'--convert-subs', '--convert-sub', '--convert-subtitles',
|
'--convert-subs', '--convert-sub', '--convert-subtitles',
|
||||||
metavar='FORMAT', dest='convertsubtitles', default=None,
|
metavar='FORMAT', dest='convertsubtitles', default=None,
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
from ..utils import (
|
from ..utils import (
|
||||||
encodeArgument,
|
encodeArgument,
|
||||||
PostProcessingError,
|
PostProcessingError,
|
||||||
|
variadic,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ class ExecAfterDownloadPP(PostProcessor):
|
|||||||
|
|
||||||
def __init__(self, downloader, exec_cmd):
|
def __init__(self, downloader, exec_cmd):
|
||||||
super(ExecAfterDownloadPP, self).__init__(downloader)
|
super(ExecAfterDownloadPP, self).__init__(downloader)
|
||||||
self.exec_cmd = exec_cmd
|
self.exec_cmd = variadic(exec_cmd)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pp_key(cls):
|
def pp_key(cls):
|
||||||
@ -32,9 +33,10 @@ def parse_cmd(self, cmd, info):
|
|||||||
info.get('filepath') or info['_filename']))
|
info.get('filepath') or info['_filename']))
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
cmd = self.parse_cmd(self.exec_cmd, info)
|
for tmpl in self.exec_cmd:
|
||||||
self.to_screen('Executing command: %s' % cmd)
|
cmd = self.parse_cmd(tmpl, info)
|
||||||
retCode = subprocess.call(encodeArgument(cmd), shell=True)
|
self.to_screen('Executing command: %s' % cmd)
|
||||||
if retCode != 0:
|
retCode = subprocess.call(encodeArgument(cmd), shell=True)
|
||||||
raise PostProcessingError('Command returned error code %d' % retCode)
|
if retCode != 0:
|
||||||
|
raise PostProcessingError('Command returned error code %d' % retCode)
|
||||||
return [], info
|
return [], info
|
||||||
|
Loading…
Reference in New Issue
Block a user