mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-05 18:39:37 +02:00
Let --parse/replace-in-metadata
run at any post-processing stage
Closes #5808, #456
This commit is contained in:
parent
119e40ef64
commit
fe74d5b592
13
README.md
13
README.md
@ -952,13 +952,18 @@ ## Post-Processing Options:
|
|||||||
mkv/mka video files
|
mkv/mka video files
|
||||||
--no-embed-info-json Do not embed the infojson as an attachment
|
--no-embed-info-json Do not embed the infojson as an attachment
|
||||||
to the video file
|
to the video file
|
||||||
--parse-metadata FROM:TO Parse additional metadata like title/artist
|
--parse-metadata [WHEN:]FROM:TO
|
||||||
|
Parse additional metadata like title/artist
|
||||||
from other fields; see "MODIFYING METADATA"
|
from other fields; see "MODIFYING METADATA"
|
||||||
for details
|
for details. Supported values of "WHEN" are
|
||||||
--replace-in-metadata FIELDS REGEX REPLACE
|
the same as that of --use-postprocessor
|
||||||
|
(default: pre_process)
|
||||||
|
--replace-in-metadata [WHEN:]FIELDS REGEX REPLACE
|
||||||
Replace text in a metadata field using the
|
Replace text in a metadata field using the
|
||||||
given regex. This option can be used
|
given regex. This option can be used
|
||||||
multiple times
|
multiple times. Supported values of "WHEN"
|
||||||
|
are the same as that of --use-postprocessor
|
||||||
|
(default: pre_process)
|
||||||
--xattrs Write metadata to the video file's xattrs
|
--xattrs Write metadata to the video file's xattrs
|
||||||
(using dublin core and xdg standards)
|
(using dublin core and xdg standards)
|
||||||
--concat-playlist POLICY Concatenate videos in a playlist. One of
|
--concat-playlist POLICY Concatenate videos in a playlist. One of
|
||||||
|
@ -386,10 +386,12 @@ def metadataparser_actions(f):
|
|||||||
raise ValueError(f'{cmd} is invalid; {err}')
|
raise ValueError(f'{cmd} is invalid; {err}')
|
||||||
yield action
|
yield action
|
||||||
|
|
||||||
parse_metadata = opts.parse_metadata or []
|
|
||||||
if opts.metafromtitle is not None:
|
if opts.metafromtitle is not None:
|
||||||
parse_metadata.append('title:%s' % opts.metafromtitle)
|
opts.parse_metadata.setdefault('pre_process', []).append('title:%s' % opts.metafromtitle)
|
||||||
opts.parse_metadata = list(itertools.chain(*map(metadataparser_actions, parse_metadata)))
|
opts.parse_metadata = {
|
||||||
|
k: list(itertools.chain(*map(metadataparser_actions, v)))
|
||||||
|
for k, v in opts.parse_metadata.items()
|
||||||
|
}
|
||||||
|
|
||||||
# Other options
|
# Other options
|
||||||
if opts.playlist_items is not None:
|
if opts.playlist_items is not None:
|
||||||
@ -561,11 +563,11 @@ def report_deprecation(val, old, new=None):
|
|||||||
def get_postprocessors(opts):
|
def get_postprocessors(opts):
|
||||||
yield from opts.add_postprocessors
|
yield from opts.add_postprocessors
|
||||||
|
|
||||||
if opts.parse_metadata:
|
for when, actions in opts.parse_metadata.items():
|
||||||
yield {
|
yield {
|
||||||
'key': 'MetadataParser',
|
'key': 'MetadataParser',
|
||||||
'actions': opts.parse_metadata,
|
'actions': actions,
|
||||||
'when': 'pre_process'
|
'when': when
|
||||||
}
|
}
|
||||||
sponsorblock_query = opts.sponsorblock_mark | opts.sponsorblock_remove
|
sponsorblock_query = opts.sponsorblock_mark | opts.sponsorblock_remove
|
||||||
if sponsorblock_query:
|
if sponsorblock_query:
|
||||||
|
@ -1586,14 +1586,16 @@ def _alias_callback(option, opt_str, value, parser, opts, nargs):
|
|||||||
help=optparse.SUPPRESS_HELP)
|
help=optparse.SUPPRESS_HELP)
|
||||||
postproc.add_option(
|
postproc.add_option(
|
||||||
'--parse-metadata',
|
'--parse-metadata',
|
||||||
metavar='FROM:TO', dest='parse_metadata', action='append',
|
metavar='[WHEN:]FROM:TO', dest='parse_metadata', **when_prefix('pre_process'),
|
||||||
help=(
|
help=(
|
||||||
'Parse additional metadata like title/artist from other fields; '
|
'Parse additional metadata like title/artist from other fields; see "MODIFYING METADATA" for details. '
|
||||||
'see "MODIFYING METADATA" for details'))
|
'Supported values of "WHEN" are the same as that of --use-postprocessor (default: pre_process)'))
|
||||||
postproc.add_option(
|
postproc.add_option(
|
||||||
'--replace-in-metadata',
|
'--replace-in-metadata',
|
||||||
dest='parse_metadata', metavar='FIELDS REGEX REPLACE', action='append', nargs=3,
|
dest='parse_metadata', metavar='[WHEN:]FIELDS REGEX REPLACE', nargs=3, **when_prefix('pre_process'),
|
||||||
help='Replace text in a metadata field using the given regex. This option can be used multiple times')
|
help=(
|
||||||
|
'Replace text in a metadata field using the given regex. This option can be used multiple times. '
|
||||||
|
'Supported values of "WHEN" are the same as that of --use-postprocessor (default: pre_process)'))
|
||||||
postproc.add_option(
|
postproc.add_option(
|
||||||
'--xattrs', '--xattr',
|
'--xattrs', '--xattr',
|
||||||
action='store_true', dest='xattrs', default=False,
|
action='store_true', dest='xattrs', default=False,
|
||||||
|
Loading…
Reference in New Issue
Block a user