From d93b5474c3e5910887fccaba51081d80d9dae48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 5 Oct 2021 19:46:48 +0200 Subject: [PATCH] [mangadex] update parameter handling for API requests - move common parameters into '_pagination()' - add 'ratings' (#1908) and 'api-parameters' options --- docs/configuration.rst | 23 +++++++++++++++++++++++ gallery_dl/extractor/mangadex.py | 27 ++++++++++++++++----------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index ddc0632c..3b6da408 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1403,6 +1403,19 @@ Description The server to use for API requests. +extractor.mangadex.api-parameters +--------------------------------- +Type + ``object`` +Example + ``{"order[updatedAt]": "desc"}`` +Description + Additional query parameters to send when fetching manga chapters. + + (See `/manga/{id}/feed `_ + and `/user/follows/manga/feed `_) + + extractor.mangadex.lang ----------------------- Type @@ -1424,6 +1437,16 @@ Description Provide ``artist``, ``author``, and ``group`` metadata fields. +extractor.mangadex.ratings +-------------------------- +Type + ``list`` of ``strings`` +Default + ``["safe", "suggestive", "erotica", "pornographic"]`` +Description + List of acceptable content ratings for returned chapters. + + extractor.mastodon.reblogs -------------------------- Type diff --git a/gallery_dl/extractor/mangadex.py b/gallery_dl/extractor/mangadex.py index 634a92d3..ff1d7c3d 100644 --- a/gallery_dl/extractor/mangadex.py +++ b/gallery_dl/extractor/mangadex.py @@ -209,22 +209,15 @@ class MangadexAPI(): return self._call("/manga/" + uuid)["data"] def manga_feed(self, uuid): - config = self.extractor.config - order = "desc" if config("chapter-reverse") else "asc" + order = "desc" if self.extractor.config("chapter-reverse") else "asc" params = { - "order[volume]" : order, - "order[chapter]" : order, - "translatedLanguage[]": config("lang"), - "contentRating[]" : [ - "safe", "suggestive", "erotica", "pornographic"], + "order[volume]" : order, + "order[chapter]": order, } return self._pagination("/manga/" + uuid + "/feed", params) def user_follows_manga_feed(self): - params = { - "order[publishAt]" : "desc", - "translatedLanguage[]": self.extractor.config("lang"), - } + params = {"order[publishAt]": "desc"} return self._pagination("/user/follows/manga/feed", params) def authenticate(self): @@ -275,8 +268,20 @@ class MangadexAPI(): def _pagination(self, endpoint, params=None): if params is None: params = {} + + config = self.extractor.config + ratings = config("ratings") + if ratings is None: + ratings = ("safe", "suggestive", "erotica", "pornographic") + + params["contentRating[]"] = ratings + params["translatedLanguage[]"] = config("lang") params["offset"] = 0 + api_params = config("api-parameters") + if api_params: + params.update(api_params) + while True: data = self._call(endpoint, params) yield from data["data"]