aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--yt_dlp/postprocessor/ffmpeg.py21
2 files changed, 11 insertions, 12 deletions
diff --git a/README.md b/README.md
index dd9cbc7fc..cbd3f337d 100644
--- a/README.md
+++ b/README.md
@@ -1433,7 +1433,7 @@ Note that any field created by this can be used in the [output template](#output
This option also has a few special uses:
* You can download an additional URL based on the metadata of the currently downloaded video. To do this, set the field `additional_urls` to the URL that you want to download. Eg: `--parse-metadata "description:(?P<additional_urls>https?://www\.vimeo\.com/\d+)` will download the first vimeo video found in the description
-* You can use this to change the metadata that is embedded in the media file. To do this, set the value of the corresponding field with a `meta_` prefix. For example, any value you set to `meta_description` field will be added to the `description` field in the file. For example, you can use this to set a different "description" and "synopsis"
+* You can use this to change the metadata that is embedded in the media file. To do this, set the value of the corresponding field with a `meta_` prefix. For example, any value you set to `meta_description` field will be added to the `description` field in the file. For example, you can use this to set a different "description" and "synopsis". Any value set to the `meta_` field will overwrite all default values.
For reference, these are the fields yt-dlp adds by default to the file metadata:
diff --git a/yt_dlp/postprocessor/ffmpeg.py b/yt_dlp/postprocessor/ffmpeg.py
index e6aa2940a..e5595341d 100644
--- a/yt_dlp/postprocessor/ffmpeg.py
+++ b/yt_dlp/postprocessor/ffmpeg.py
@@ -10,7 +10,7 @@ import json
from .common import AudioConversionError, PostProcessor
-from ..compat import compat_str, compat_numeric_types
+from ..compat import compat_str
from ..utils import (
dfxp2srt,
encodeArgument,
@@ -664,15 +664,14 @@ class FFmpegMetadataPP(FFmpegPostProcessor):
def _get_metadata_opts(self, info):
metadata = {}
+ meta_prefix = 'meta_'
def add(meta_list, info_list=None):
- if not meta_list:
- return
- for info_f in variadic(info_list or meta_list):
- if isinstance(info.get(info_f), (compat_str, compat_numeric_types)):
- for meta_f in variadic(meta_list):
- metadata[meta_f] = info[info_f]
- break
+ value = next((
+ str(info[key]) for key in [meta_prefix] + list(variadic(info_list or meta_list))
+ if info.get(key) is not None), None)
+ if value not in ('', None):
+ metadata.update({meta_f: value for meta_f in variadic(meta_list)})
# See [1-4] for some info on media metadata/metadata supported
# by ffmpeg.
@@ -695,9 +694,9 @@ class FFmpegMetadataPP(FFmpegPostProcessor):
add('episode_id', ('episode', 'episode_id'))
add('episode_sort', 'episode_number')
- prefix = 'meta_'
- for key in filter(lambda k: k.startswith(prefix), info.keys()):
- add(key[len(prefix):], key)
+ for key, value in info.items():
+ if value is not None and key != meta_prefix and key.startswith(meta_prefix):
+ metadata[key[len(meta_prefix):]] = value
for name, value in metadata.items():
yield ('-metadata', f'{name}={value}')