mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-10 00:58:17 +02:00
Pass any field to --exec
using similar syntax to output template
Related: https://github.com/ytdl-org/youtube-dl/issues/28642
This commit is contained in:
parent
e01d6aa435
commit
9de3ea3126
11
README.md
11
README.md
@ -686,9 +686,14 @@ ## Post-Processing Options:
|
|||||||
path to the binary or its containing
|
path to the binary or its containing
|
||||||
directory
|
directory
|
||||||
--exec CMD Execute a command on the file after
|
--exec CMD Execute a command on the file after
|
||||||
downloading and post-processing, similar to
|
downloading and post-processing. Similar
|
||||||
find's -exec syntax. Example: --exec 'adb
|
syntax to the output template can be used
|
||||||
push {} /sdcard/Music/ && rm {}'
|
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. If no
|
||||||
|
fields are passed, "%(filepath)s" is
|
||||||
|
appended to the end of the command
|
||||||
--convert-subs FORMAT Convert the subtitles to another format
|
--convert-subs FORMAT Convert the subtitles to another format
|
||||||
(currently supported: srt|ass|vtt|lrc)
|
(currently supported: srt|ass|vtt|lrc)
|
||||||
(Alias: --convert-subtitles)
|
(Alias: --convert-subtitles)
|
||||||
|
@ -1195,7 +1195,11 @@ def _dict_from_multiple_values_options_callback(
|
|||||||
postproc.add_option(
|
postproc.add_option(
|
||||||
'--exec',
|
'--exec',
|
||||||
metavar='CMD', dest='exec_cmd',
|
metavar='CMD', dest='exec_cmd',
|
||||||
help='Execute a command on the file after downloading and post-processing, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
|
help=(
|
||||||
|
'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. '
|
||||||
|
'An additional field "filepath" that contains the final path of the downloaded file is also available. '
|
||||||
|
'If no fields are passed, "%(filepath)s" is appended to the end of the command'))
|
||||||
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,
|
||||||
|
@ -20,12 +20,13 @@ def __init__(self, downloader, exec_cmd):
|
|||||||
def pp_key(cls):
|
def pp_key(cls):
|
||||||
return 'Exec'
|
return 'Exec'
|
||||||
|
|
||||||
def run(self, information):
|
def run(self, info):
|
||||||
cmd = self.exec_cmd
|
tmpl, info_copy = self._downloader.prepare_outtmpl(self.exec_cmd, info)
|
||||||
if '{}' not in cmd:
|
cmd = tmpl % info_copy
|
||||||
cmd += ' {}'
|
if cmd == self.exec_cmd: # No replacements were made
|
||||||
|
if '{}' not in self.exec_cmd:
|
||||||
cmd = cmd.replace('{}', compat_shlex_quote(information['filepath']))
|
self.exec_cmd += ' {}'
|
||||||
|
cmd = self.exec_cmd.replace('{}', compat_shlex_quote(info['filepath']))
|
||||||
|
|
||||||
self.to_screen('Executing command: %s' % cmd)
|
self.to_screen('Executing command: %s' % cmd)
|
||||||
retCode = subprocess.call(encodeArgument(cmd), shell=True)
|
retCode = subprocess.call(encodeArgument(cmd), shell=True)
|
||||||
@ -33,4 +34,4 @@ def run(self, information):
|
|||||||
raise PostProcessingError(
|
raise PostProcessingError(
|
||||||
'Command returned error code %d' % retCode)
|
'Command returned error code %d' % retCode)
|
||||||
|
|
||||||
return [], information
|
return [], info
|
||||||
|
Loading…
Reference in New Issue
Block a user