A feature-rich command-line audio/video downloader
Let `--parse/replace-in-metadata` run at any post-processing stage
pukkandanfe74d5b59243
diff --git a/README.md b/README.mdindex d31fedb00e..500f92387b 100644--- a/README.md+++ b/README.md@@ -952,13 +952,18 @@ You can also fork the project on GitHub and run your fork's [build workflow](.gimkv/mka video files--no-embed-info-json Do not embed the infojson as an attachmentto the video file- --parse-metadata FROM:TO Parse additional metadata like title/artist+ --parse-metadata [WHEN:]FROM:TO+ Parse additional metadata like title/artistfrom other fields; see "MODIFYING METADATA"- for details- --replace-in-metadata FIELDS REGEX REPLACE+ for details. Supported values of "WHEN" are+ the same as that of --use-postprocessor+ (default: pre_process)+ --replace-in-metadata [WHEN:]FIELDS REGEX REPLACEReplace text in a metadata field using thegiven 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(using dublin core and xdg standards)--concat-playlist POLICY Concatenate videos in a playlist. One ofdiff --git a/yt_dlp/__init__.py b/yt_dlp/__init__.pyindex 202f102ba9..3490816c4c 100644--- a/yt_dlp/__init__.py+++ b/yt_dlp/__init__.py@@ -386,10 +386,12 @@ def validate_options(opts):raise ValueError(f'{cmd} is invalid; {err}')yield action- parse_metadata = opts.parse_metadata or []if opts.metafromtitle is not None:- parse_metadata.append('title:%s' % opts.metafromtitle)- opts.parse_metadata = list(itertools.chain(*map(metadataparser_actions, parse_metadata)))+ opts.parse_metadata.setdefault('pre_process', []).append('title:%s' % opts.metafromtitle)+ opts.parse_metadata = {+ k: list(itertools.chain(*map(metadataparser_actions, v)))+ for k, v in opts.parse_metadata.items()+ }# Other optionsif opts.playlist_items is not None:@@ -561,11 +563,11 @@ def validate_options(opts):def get_postprocessors(opts):yield from opts.add_postprocessors- if opts.parse_metadata:+ for when, actions in opts.parse_metadata.items():yield {'key': 'MetadataParser',- 'actions': opts.parse_metadata,- 'when': 'pre_process'+ 'actions': actions,+ 'when': when}sponsorblock_query = opts.sponsorblock_mark | opts.sponsorblock_removeif sponsorblock_query:diff --git a/yt_dlp/options.py b/yt_dlp/options.pyindex 096a502491..ed83cb763e 100644--- a/yt_dlp/options.py+++ b/yt_dlp/options.py@@ -1586,14 +1586,16 @@ def create_parser():help=optparse.SUPPRESS_HELP)postproc.add_option('--parse-metadata',- metavar='FROM:TO', dest='parse_metadata', action='append',+ metavar='[WHEN:]FROM:TO', dest='parse_metadata', **when_prefix('pre_process'),help=(- 'Parse additional metadata like title/artist from other fields; '- 'see "MODIFYING METADATA" for details'))+ 'Parse additional metadata like title/artist from other fields; see "MODIFYING METADATA" for details. '+ 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: pre_process)'))postproc.add_option('--replace-in-metadata',- dest='parse_metadata', metavar='FIELDS REGEX REPLACE', action='append', nargs=3,- help='Replace text in a metadata field using the given regex. This option can be used multiple times')+ 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. '+ 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: pre_process)'))postproc.add_option('--xattrs', '--xattr',action='store_true', dest='xattrs', default=False,