[danbooru] extend 'metadata' option

make it possible to specify a custom list of metadata includes
This commit is contained in:
Mike Fährmann
2023-01-13 16:20:01 +01:00
parent 26c3292538
commit c87bd1a752
2 changed files with 26 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2022 Mike Fährmann
# Copyright 2014-2023 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -40,7 +40,17 @@ class DanbooruExtractor(BaseExtractor):
self.ugoira = self.config("ugoira", False)
self.external = self.config("external", False)
self.extended_metadata = self.config("metadata", False)
metadata = self.config("metadata", False)
if metadata:
if isinstance(metadata, (list, tuple)):
metadata = ",".join(metadata)
elif not isinstance(metadata, str):
metadata = "artist_commentary,children,notes,parent,uploader"
self.metadata_includes = metadata
else:
self.metadata_includes = None
threshold = self.config("threshold")
if isinstance(threshold, int):
self.threshold = 1 if threshold < 1 else threshold
@@ -99,13 +109,10 @@ class DanbooruExtractor(BaseExtractor):
url = post["large_file_url"]
post["extension"] = "webm"
if self.extended_metadata:
template = (
"{}/posts/{}.json?only=artist_commentary,children,notes,"
"parent,uploader"
)
resp = self.request(template.format(self.root, post["id"]))
post.update(resp.json())
if self.metadata_includes:
meta_url = "{}/posts/{}.json?only={}".format(
self.root, post["id"], self.metadata_includes)
post.update(self.request(meta_url).json())
if url[0] == "/":
url = self.root + url