[mangadex] load additional metadata using includes[] directives

- always provide 'artist', 'author', and 'group' metadata fields (#2049)
- remove 'metadata' option
pull/2056/head
Mike Fährmann 3 years ago
parent 19e00f1322
commit 11a3d96d13
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -1443,16 +1443,6 @@ Description
to filter chapters by. to filter chapters by.
extractor.mangadex.metadata
---------------------------
Type
``bool``
Default
``false``
Description
Provide ``artist``, ``author``, and ``group`` metadata fields.
extractor.mangadex.ratings extractor.mangadex.ratings
-------------------------- --------------------------
Type Type

@ -156,8 +156,9 @@
"mangadex": "mangadex":
{ {
"api-server": "https://api.mangadex.org", "api-server": "https://api.mangadex.org",
"metadata": false, "api-parameters": null,
"lang": null "lang": null,
"ratings": ["safe", "suggestive", "erotica", "pornographic"]
}, },
"mangoxo": "mangoxo":
{ {

@ -46,10 +46,10 @@ class MangadexExtractor(Extractor):
def _transform(self, chapter): def _transform(self, chapter):
relationships = defaultdict(list) relationships = defaultdict(list)
for item in chapter["relationships"]: for item in chapter["relationships"]:
relationships[item["type"]].append(item["id"]) relationships[item["type"]].append(item)
manga = self.api.manga(relationships["manga"][0]) manga = self.api.manga(relationships["manga"][0]["id"])
for item in manga["relationships"]: for item in manga["relationships"]:
relationships[item["type"]].append(item["id"]) relationships[item["type"]].append(item)
cattributes = chapter["attributes"] cattributes = chapter["attributes"]
mattributes = manga["attributes"] mattributes = manga["attributes"]
@ -75,16 +75,12 @@ class MangadexExtractor(Extractor):
"count" : len(cattributes["data"]), "count" : len(cattributes["data"]),
} }
if self.config("metadata"): data["artist"] = [artist["attributes"]["name"]
data["artist"] = [ for artist in relationships["artist"]]
self.api.author(uuid)["attributes"]["name"] data["author"] = [author["attributes"]["name"]
for uuid in relationships["artist"]] for author in relationships["author"]]
data["author"] = [ data["group"] = [group["attributes"]["name"]
self.api.author(uuid)["attributes"]["name"] for group in relationships["scanlation_group"]]
for uuid in relationships["author"]]
data["group"] = [
self.api.group(uuid)["attributes"]["name"]
for uuid in relationships["scanlation_group"]]
return data return data
@ -95,12 +91,11 @@ class MangadexChapterExtractor(MangadexExtractor):
pattern = BASE_PATTERN + r"/chapter/([0-9a-f-]+)" pattern = BASE_PATTERN + r"/chapter/([0-9a-f-]+)"
test = ( test = (
("https://mangadex.org/chapter/f946ac53-0b71-4b5d-aeb2-7931b13c4aaa", { ("https://mangadex.org/chapter/f946ac53-0b71-4b5d-aeb2-7931b13c4aaa", {
"keyword": "f6c2b908df06eb834d56193dfe1fa1f7c2c4dccd", "keyword": "86fb262cf767dac6d965cd904ad499adba466404",
# "content": "50383a4c15124682057b197d40261641a98db514", # "content": "50383a4c15124682057b197d40261641a98db514",
}), }),
# oneshot # oneshot
("https://mangadex.org/chapter/61a88817-9c29-4281-bdf1-77b3c1be9831", { ("https://mangadex.org/chapter/61a88817-9c29-4281-bdf1-77b3c1be9831", {
"options": (("metadata", True),),
"count": 64, "count": 64,
"keyword": "6abcbe1e24eeb1049dc931958853cd767ee483fb", "keyword": "6abcbe1e24eeb1049dc931958853cd767ee483fb",
}), }),
@ -147,6 +142,8 @@ class MangadexMangaExtractor(MangadexExtractor):
"date" : "type:datetime", "date" : "type:datetime",
"lang" : str, "lang" : str,
"language": str, "language": str,
"artist" : ["Arakawa Hiromu"],
"author" : ["Arakawa Hiromu"],
}, },
}), }),
("https://mangadex.cc/manga/d0c88e3b-ea64-4e07-9841-c1d2ac982f4a/", { ("https://mangadex.cc/manga/d0c88e3b-ea64-4e07-9841-c1d2ac982f4a/", {
@ -193,20 +190,14 @@ class MangadexAPI():
def athome_server(self, uuid): def athome_server(self, uuid):
return self._call("/at-home/server/" + uuid) return self._call("/at-home/server/" + uuid)
@memcache(keyarg=1)
def author(self, uuid):
return self._call("/author/" + uuid)["data"]
def chapter(self, uuid): def chapter(self, uuid):
return self._call("/chapter/" + uuid)["data"] params = {"includes[]": ("scanlation_group",)}
return self._call("/chapter/" + uuid, params)["data"]
@memcache(keyarg=1)
def group(self, uuid):
return self._call("/group/" + uuid)["data"]
@memcache(keyarg=1) @memcache(keyarg=1)
def manga(self, uuid): def manga(self, uuid):
return self._call("/manga/" + uuid)["data"] params = {"includes[]": ("artist", "author")}
return self._call("/manga/" + uuid, params)["data"]
def manga_feed(self, uuid): def manga_feed(self, uuid):
order = "desc" if self.extractor.config("chapter-reverse") else "asc" order = "desc" if self.extractor.config("chapter-reverse") else "asc"
@ -275,6 +266,7 @@ class MangadexAPI():
ratings = ("safe", "suggestive", "erotica", "pornographic") ratings = ("safe", "suggestive", "erotica", "pornographic")
params["contentRating[]"] = ratings params["contentRating[]"] = ratings
params["includes[]"] = ("scanlation_group",)
params["translatedLanguage[]"] = config("lang") params["translatedLanguage[]"] = config("lang")
params["offset"] = 0 params["offset"] = 0

Loading…
Cancel
Save