diff --git a/gallery_dl/extractor/wikimedia.py b/gallery_dl/extractor/wikimedia.py index b254a9c8..e927bc1a 100644 --- a/gallery_dl/extractor/wikimedia.py +++ b/gallery_dl/extractor/wikimedia.py @@ -33,9 +33,11 @@ class WikimediaExtractor(BaseExtractor): self.per_page = self.config("limit", 50) + if useragent := self.config_instance("useragent"): + self.useragent = useragent + def _init(self): - api_path = self.config_instance("api-path") - if api_path: + if api_path := self.config_instance("api-path"): if api_path[0] == "/": self.api_url = self.root + api_path else: @@ -110,14 +112,12 @@ class WikimediaExtractor(BaseExtractor): data = self.request_json(url, params=params) # ref: https://www.mediawiki.org/wiki/API:Errors_and_warnings - error = data.get("error") - if error: + if error := data.get("error"): self.log.error("%s: %s", error["code"], error["info"]) return # MediaWiki will emit warnings for non-fatal mistakes such as # invalid parameter instead of raising an error - warnings = data.get("warnings") - if warnings: + if warnings := data.get("warnings"): self.log.debug("MediaWiki returned warnings: %s", warnings) try: @@ -187,6 +187,7 @@ BASE_PATTERN = WikimediaExtractor.update({ "root": "https://azurlane.koumakan.jp", "pattern": r"azurlane\.koumakan\.jp", "api-path": "/w/api.php", + "useragent": "Googlebot-Image/1.0", }, })