From c7a42880abe3802c48cc7bbb93fcadd13ee58f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 21 Jan 2024 00:21:40 +0100 Subject: [PATCH] [wikimedia] support fandom wikis (#1443, #2677, #3378) Wikis hosted on fandom.com are just wikimedia instances and support its API. --- docs/supportedsites.md | 6 ++ gallery_dl/extractor/wikimedia.py | 9 +++ test/results/fandom.py | 92 +++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 test/results/fandom.py diff --git a/docs/supportedsites.md b/docs/supportedsites.md index c6756c6a..54771eff 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -1523,6 +1523,12 @@ Consider all listed sites to potentially be NSFW. Articles + + Fandom + https://www.fandom.com/ + Articles + + Super Mario Wiki https://www.mariowiki.com/ diff --git a/gallery_dl/extractor/wikimedia.py b/gallery_dl/extractor/wikimedia.py index 49843111..1eafc296 100644 --- a/gallery_dl/extractor/wikimedia.py +++ b/gallery_dl/extractor/wikimedia.py @@ -25,6 +25,10 @@ class WikimediaExtractor(BaseExtractor): BaseExtractor.__init__(self, match) path = match.group(match.lastindex) + if self.category == "fandom": + self.category = \ + "fandom-" + self.root.partition(".")[0].rpartition("/")[2] + if path.startswith("wiki/"): path = path[5:] self.api_path = "/w/api.php" @@ -158,6 +162,11 @@ BASE_PATTERN = WikimediaExtractor.update({ "root": "https://www.mediawiki.org", "pattern": r"(?:www\.)?mediawiki\.org", }, + "fandom": { + "root": None, + "pattern": r"[\w-]+\.fandom\.com", + "api-path": "/api.php", + }, "mariowiki": { "root": "https://www.mariowiki.com", "pattern": r"(?:www\.)?mariowiki\.com", diff --git a/test/results/fandom.py b/test/results/fandom.py new file mode 100644 index 00000000..40d82e93 --- /dev/null +++ b/test/results/fandom.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- + +# 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 +# published by the Free Software Foundation. + +from gallery_dl.extractor import wikimedia + + +__tests__ = ( +{ + "#url" : "https://www.fandom.com/wiki/Title", + "#comment" : "for scripts/supportedsites.py", + "#category": ("wikimedia", "fandom-www", "article"), + "#class" : wikimedia.WikimediaArticleExtractor, +}, + +{ + "#url" : "https://mushishi.fandom.com/wiki/Yahagi", + "#category": ("wikimedia", "fandom-mushishi", "article"), + "#class" : wikimedia.WikimediaArticleExtractor, + "#urls" : "https://static.wikia.nocookie.net/mushi-shi/images/f/f8/Yahagi.png/revision/latest?cb=20150128052255", + + "bitdepth" : 8, + "canonicaltitle": "File:Yahagi.png", + "comment" : "", + "commonmetadata": { + "ResolutionUnit": 3, + "XResolution" : "3779/100", + "YResolution" : "3779/100", + }, + "date" : "dt:2015-01-28 05:22:55", + "descriptionshorturl": "https://mushishi.fandom.com/index.php?curid=2595", + "descriptionurl": "https://mushishi.fandom.com/wiki/File:Yahagi.png", + "extension" : "png", + "extmetadata" : { + "DateTime": { + "hidden": "", + "source": "mediawiki-metadata", + "value": "2015-01-28T05:22:55Z", + }, + "ObjectName": { + "hidden": "", + "source": "mediawiki-metadata", + "value": "Yahagi", + }, + }, + "filename" : "Yahagi", + "height" : 410, + "metadata" : { + "bitDepth" : 8, + "colorType" : "truecolour", + "duration" : 0, + "frameCount": 0, + "loopCount" : 1, + "metadata" : [ + { + "name" : "XResolution", + "value": "3779/100", + }, + { + "name" : "YResolution", + "value": "3779/100", + }, + { + "name" : "ResolutionUnit", + "value": 3, + }, + { + "name" : "_MW_PNG_VERSION", + "value": 1, + }, + ], + }, + "mime" : "image/png", + "page" : "Yahagi", + "sha1" : "e3078a97976215323dbabb0c86b7acc55b512d16", + "size" : 429912, + "timestamp" : "2015-01-28T05:22:55Z", + "url" : "https://static.wikia.nocookie.net/mushi-shi/images/f/f8/Yahagi.png/revision/latest?cb=20150128052255", + "user" : "ITHYRIAL", + "userid" : 4637089, + "width" : 728, +}, + +{ + "#url" : "https://projectsekai.fandom.com/wiki/Project_SEKAI_Wiki", + "#category": ("wikimedia", "fandom-projectsekai", "article"), + "#class" : wikimedia.WikimediaArticleExtractor, +}, + +)