1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

[ytdl} fix dfe4f00c for legacy yt-dlp

This commit is contained in:
Mike Fährmann 2023-01-04 21:42:22 +01:00
parent f29ba089ff
commit fa144f38ed
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 32 additions and 17 deletions

View File

@ -199,18 +199,27 @@ def parse_command_line(module, argv):
action += args
yield action
if opts.metafromtitle is not None:
if "pre_process" not in opts.parse_metadata:
opts.parse_metadata["pre_process"] = []
opts.parse_metadata["pre_process"].append(
"title:%s" % opts.metafromtitle)
opts.metafromtitle = None
parse_metadata = getattr(opts, "parse_metadata", None)
if isinstance(parse_metadata, dict):
if opts.metafromtitle is not None:
if "pre_process" not in parse_metadata:
parse_metadata["pre_process"] = []
parse_metadata["pre_process"].append(
"title:%s" % opts.metafromtitle)
opts.parse_metadata = {
k: list(itertools.chain.from_iterable(map(
metadataparser_actions, v)))
for k, v in parse_metadata.items()
}
else:
if parse_metadata is None:
parse_metadata = []
if opts.metafromtitle is not None:
parse_metadata.append("title:%s" % opts.metafromtitle)
opts.parse_metadata = list(itertools.chain.from_iterable(map(
metadataparser_actions, parse_metadata)))
opts.parse_metadata = {
k: list(itertools.chain.from_iterable(map(
metadataparser_actions, v)))
for k, v in opts.parse_metadata.items()
}
opts.metafromtitle = None
else:
opts.parse_metadata = ()

View File

@ -262,15 +262,21 @@ class Test_CommandlineArguments_YtDlp(Test_CommandlineArguments):
def test_metadata_from_title(self):
opts = self._(["--metadata-from-title", "%(artist)s - %(title)s"])
try:
legacy = (self.module.version.__version__ < "2023.01.01")
except AttributeError:
legacy = True
actions = [self.module.MetadataFromFieldPP.to_action(
"title:%(artist)s - %(title)s")]
if not legacy:
actions = {"pre_process": actions}
self.assertEqual(opts["postprocessors"][0], {
"key" : "MetadataParser",
"when" : "pre_process",
"actions": {
"pre_process": [
self.module.MetadataFromFieldPP.to_action(
"title:%(artist)s - %(title)s")
],
},
"actions": actions,
})