mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-01-09 08:21:24 +00:00
Fix --parse-metadata when TO is a single field name (#14577)
Closes #14576 Authored by: clayote, bashonly Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
This commit is contained in:
@@ -1821,6 +1821,9 @@ $ yt-dlp --parse-metadata "title:%(artist)s - %(title)s"
|
||||
# Regex example
|
||||
$ yt-dlp --parse-metadata "description:Artist - (?P<artist>.+)"
|
||||
|
||||
# Copy the episode field to the title field (with FROM and TO as single fields)
|
||||
$ yt-dlp --parse-metadata "episode:title"
|
||||
|
||||
# Set title as "Series name S01E05"
|
||||
$ yt-dlp --parse-metadata "%(series)s S%(season_number)02dE%(episode_number)02d:%(title)s"
|
||||
|
||||
|
||||
@@ -29,6 +29,11 @@ class TestMetadataFromField(unittest.TestCase):
|
||||
MetadataParserPP.format_to_regex('%(title)s - %(artist)s'),
|
||||
r'(?P<title>.+)\ \-\ (?P<artist>.+)')
|
||||
self.assertEqual(MetadataParserPP.format_to_regex(r'(?P<x>.+)'), r'(?P<x>.+)')
|
||||
self.assertEqual(MetadataParserPP.format_to_regex(r'text (?P<x>.+)'), r'text (?P<x>.+)')
|
||||
self.assertEqual(MetadataParserPP.format_to_regex('x'), r'(?s)(?P<x>.+)')
|
||||
self.assertEqual(MetadataParserPP.format_to_regex('Field_Name1'), r'(?s)(?P<Field_Name1>.+)')
|
||||
self.assertEqual(MetadataParserPP.format_to_regex('é'), r'(?s)(?P<é>.+)')
|
||||
self.assertEqual(MetadataParserPP.format_to_regex('invalid '), 'invalid ')
|
||||
|
||||
def test_field_to_template(self):
|
||||
self.assertEqual(MetadataParserPP.field_to_template('title'), '%(title)s')
|
||||
|
||||
@@ -42,6 +42,9 @@ class MetadataParserPP(PostProcessor):
|
||||
to a regex like
|
||||
'(?P<title>.+)\ \-\ (?P<artist>.+)'
|
||||
"""
|
||||
if re.fullmatch(r'\w+', fmt):
|
||||
# convert a single field name into regex pattern that matches the entire input
|
||||
return rf'(?s)(?P<{fmt}>.+)'
|
||||
if not re.search(r'%\(\w+\)s', fmt):
|
||||
return fmt
|
||||
lastpos = 0
|
||||
|
||||
Reference in New Issue
Block a user