1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-26 10:24:33 +01:00

[postprocessor/metadatafromtitle] Add support regex syntax for --metadata-from-title (closes #13065)

This commit is contained in:
Sergey M․ 2017-05-14 00:03:15 +07:00
parent 12f01118b0
commit fa26734e07
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D
2 changed files with 9 additions and 6 deletions

View File

@ -814,11 +814,12 @@ def parseOpts(overrideArguments=None):
'--metadata-from-title', '--metadata-from-title',
metavar='FORMAT', dest='metafromtitle', metavar='FORMAT', dest='metafromtitle',
help='Parse additional metadata like song title / artist from the video title. ' help='Parse additional metadata like song title / artist from the video title. '
'The format syntax is the same as --output, ' 'The format syntax is the same as --output. Regular expression with '
'the parsed parameters replace existing values. ' 'named capture groups may also be used. '
'Additional templates: %(album)s, %(artist)s. ' 'The parsed parameters replace existing values. '
'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like ' 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
'"Coldplay - Paradise"') '"Coldplay - Paradise". '
'Example (regex): --metadata-from-title "(?P<artist>.+?) - (?P<title>.+)"')
postproc.add_option( postproc.add_option(
'--xattrs', '--xattrs',
action='store_true', dest='xattrs', default=False, action='store_true', dest='xattrs', default=False,

View File

@ -9,7 +9,9 @@ class MetadataFromTitlePP(PostProcessor):
def __init__(self, downloader, titleformat): def __init__(self, downloader, titleformat):
super(MetadataFromTitlePP, self).__init__(downloader) super(MetadataFromTitlePP, self).__init__(downloader)
self._titleformat = titleformat self._titleformat = titleformat
self._titleregex = self.format_to_regex(titleformat) self._titleregex = (self.format_to_regex(titleformat)
if re.search(r'%\(\w+\)s', titleformat)
else titleformat)
def format_to_regex(self, fmt): def format_to_regex(self, fmt):
r""" r"""