1
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-03-09 12:50:23 -05:00

Convert date strings to ISO 8601 before adding to metadata

This commit is contained in:
7x11x13 2025-02-01 15:54:43 -05:00
parent 03c3d70577
commit fae148b2df

View file

@ -8,6 +8,8 @@
import subprocess import subprocess
import time import time
from yt_dlp.utils._utils import strftime_or_none
from .common import PostProcessor from .common import PostProcessor
from ..compat import imghdr from ..compat import imghdr
from ..utils import ( from ..utils import (
@ -736,12 +738,12 @@ def _get_metadata_opts(self, info):
meta_prefix = 'meta' meta_prefix = 'meta'
metadata = collections.defaultdict(dict) metadata = collections.defaultdict(dict)
def add(meta_list, info_list=None): def add(meta_list, info_list=None, convert=str):
value = next(( value = next((
info[key] for key in [f'{meta_prefix}_', *variadic(info_list or meta_list)] info[key] for key in [f'{meta_prefix}_', *variadic(info_list or meta_list)]
if info.get(key) is not None), None) if info.get(key) is not None), None)
if value not in ('', None): if value not in ('', None):
value = ', '.join(map(str, variadic(value))) value = ', '.join(map(convert, variadic(value)))
value = value.replace('\0', '') # nul character cannot be passed in command line value = value.replace('\0', '') # nul character cannot be passed in command line
metadata['common'].update({meta_f: value for meta_f in variadic(meta_list)}) metadata['common'].update({meta_f: value for meta_f in variadic(meta_list)})
@ -751,7 +753,7 @@ def add(meta_list, info_list=None):
# https://kodi.wiki/view/Video_file_tagging # https://kodi.wiki/view/Video_file_tagging
add('title', ('track', 'title')) add('title', ('track', 'title'))
add('date', 'upload_date') add('date', ('release_date', 'upload_date'), lambda date: strftime_or_none(date, '%Y-%m-%d'))
add(('description', 'synopsis'), 'description') add(('description', 'synopsis'), 'description')
add(('purl', 'comment'), 'webpage_url') add(('purl', 'comment'), 'webpage_url')
add('track', 'track_number') add('track', 'track_number')