1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 12:12:34 +01:00
gallery-dl/scripts/supportedsites.py

287 lines
8.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Generate a reStructuredText document with all supported sites"""
import sys
2019-02-20 19:25:41 +01:00
import collections
import util
from gallery_dl import extractor
CATEGORY_MAP = {
2017-07-15 15:01:30 +02:00
"2chan" : "Futaba Channel",
"35photo" : "35PHOTO",
"adultempire" : "Adult Empire",
2017-07-15 15:01:30 +02:00
"archivedmoe" : "Archived.Moe",
"archiveofsins" : "Archive of Sins",
"artstation" : "ArtStation",
"b4k" : "arch.b4k.co",
"bobx" : "BobX",
"deviantart" : "DeviantArt",
"dokireader" : "Doki Reader",
"dynastyscans" : "Dynasty Reader",
"e621" : "e621",
"erolord" : "EroLord.com",
"e-hentai" : "E-Hentai",
"exhentai" : "ExHentai",
"fallenangels" : "Fallen Angels Scans",
"fashionnova" : "Fashion Nova",
"hbrowse" : "HBrowse",
"hentai2read" : "Hentai2Read",
"hentaicafe" : "Hentai Cafe",
"hentaifoundry" : "Hentai Foundry",
"hentaifox" : "HentaiFox",
"hentaihere" : "HentaiHere",
"hitomi" : "Hitomi.la",
"idolcomplex" : "Idol Complex",
"imagebam" : "ImageBam",
"imagefap" : "ImageFap",
2019-07-30 23:02:21 +02:00
"imgbb" : "ImgBB",
"imgbox" : "imgbox",
"imgth" : "imgth",
"imgur" : "imgur",
"jaiminisbox" : "Jaimini's Box",
"kireicake" : "Kirei Cake",
"kissmanga" : "KissManga",
"lineblog" : "LINE BLOG",
"livedoor" : "livedoor Blog",
"mangadex" : "MangaDex",
"mangafox" : "Manga Fox",
"mangahere" : "Manga Here",
"mangapark" : "MangaPark",
"mangastream" : "Manga Stream",
"myportfolio" : "Adobe Portfolio",
"nhentai" : "nhentai",
"nijie" : "nijie",
"nozomi" : "Nozomi.la",
"nsfwalbum" : "NSFWalbum.com",
2017-07-15 15:01:30 +02:00
"nyafuu" : "Nyafuu Archive",
"paheal" : "rule #34",
"powermanga" : "PowerManga",
"readcomiconline": "Read Comic Online",
2017-07-24 10:50:40 +02:00
"rbt" : "RebeccaBlackTech",
"rule34" : "Rule 34",
"sankaku" : "Sankaku Channel",
"sankakucomplex" : "Sankaku Complex",
"seaotterscans" : "Sea Otter Scans",
"seiga" : "Niconico Seiga",
"senmanga" : "Sen Manga",
"sensescans" : "Sense-Scans",
"sexcom" : "Sex.com",
"simplyhentai" : "Simply Hentai",
2019-06-09 21:59:22 +02:00
"slickpic" : "SlickPic",
"slideshare" : "SlideShare",
"smugmug" : "SmugMug",
2017-07-24 10:50:40 +02:00
"thebarchive" : "The /b/ Archive",
"vanillarock" : "もえぴりあ",
2019-07-22 22:15:36 +02:00
"vsco" : "VSCO",
"wikiart" : "WikiArt.org",
"worldthree" : "World Three",
"xhamster" : "xHamster",
"xvideos" : "XVideos",
"yaplog" : "yaplog!",
"yuki" : "yuki.la 4chan archive",
}
SUBCATEGORY_MAP = {
2019-02-20 19:25:41 +01:00
"artwork": "Artwork Listings",
"artists": "",
"doujin" : "Doujin",
"gallery": "Galleries",
"image" : "individual Images",
"issue" : "Comic-Issues",
"manga" : "Manga",
2017-06-28 17:39:07 +02:00
"me" : "pixiv.me Links",
2018-08-31 17:40:44 +02:00
"media" : "Media Timelines",
2018-05-04 10:03:20 +02:00
"path" : "Images from Users and Folders",
"pinit" : "pin.it Links",
"popular": "Popular Images",
"recent" : "Recent Images",
"search" : "Search Results",
"stash" : "Sta.sh",
"status" : "Images from Statuses",
"tag" : "Tag-Searches",
"user" : "User Profiles",
"work" : "Individual Images",
"related-pin" : "related Pins",
"related-board": "",
}
AUTH_MAP = {
2019-01-09 14:21:19 +01:00
"danbooru" : "Optional",
"deviantart" : "Optional (OAuth)",
"e-hentai" : "Optional",
"exhentai" : "Optional",
"flickr" : "Optional (OAuth)",
"idolcomplex": "Optional",
"imgbb" : "Optional",
"instagram" : "Optional",
"mangoxo" : "Optional",
"newgrounds" : "Optional",
"nijie" : "Required",
"pixiv" : "Required",
"reddit" : "Optional (OAuth)",
"sankaku" : "Optional",
"seiga" : "Required",
2018-05-10 18:58:05 +02:00
"smugmug" : "Optional (OAuth)",
"tsumino" : "Optional",
"tumblr" : "Optional (OAuth)",
2019-04-07 23:06:57 +02:00
"twitter" : "Optional",
"wallhaven" : ("Optional (`API Key "
"<configuration.rst#extractorwallhavenapi-key>`__)"),
}
IGNORE_LIST = (
2019-02-20 19:25:41 +01:00
"directlink",
"oauth",
2019-02-20 19:25:41 +01:00
"recursive",
"test",
)
2019-02-20 19:25:41 +01:00
def domain(cls):
"""Return the web-domain related to an extractor class"""
url = sys.modules[cls.__module__].__doc__.split()[-1]
if url.startswith("http"):
return url
2019-02-20 19:25:41 +01:00
if hasattr(cls, "root") and cls.root:
return cls.root + "/"
2018-09-28 12:39:05 +02:00
2019-02-20 19:25:41 +01:00
if hasattr(cls, "https"):
scheme = "https" if cls.https else "http"
netloc = cls.__doc__.split()[-1]
return "{}://{}/".format(scheme, netloc)
2019-02-20 19:25:41 +01:00
test = next(cls._get_tests(), None)
if test:
url = test[0]
return url[:url.find("/", 8)+1]
2019-02-20 19:25:41 +01:00
return ""
2019-02-20 19:25:41 +01:00
def category_text(cls):
"""Return a human-readable representation of a category"""
c = cls.category
return CATEGORY_MAP.get(c) or c.capitalize()
2018-09-28 12:39:05 +02:00
2019-02-20 19:25:41 +01:00
def subcategory_text(cls):
"""Return a human-readable representation of a subcategory"""
sc = cls.subcategory
if sc in SUBCATEGORY_MAP:
return SUBCATEGORY_MAP[sc]
sc = sc.capitalize()
return sc if sc.endswith("s") else sc + "s"
2019-02-20 19:25:41 +01:00
def category_key(cls):
"""Generate sorting keys by category"""
key = category_text(cls).lower()
if cls.__module__.endswith(".imagehosts"):
key = "zz" + key
return key
2019-02-20 19:25:41 +01:00
def subcategory_key(cls):
"""Generate sorting keys by subcategory"""
if cls.subcategory == "issue":
2019-02-20 19:25:41 +01:00
return "A"
return cls.subcategory
2017-07-15 15:01:30 +02:00
2019-02-20 19:25:41 +01:00
def build_extractor_list():
"""Generate a sorted list of lists of extractor classes"""
extractors = collections.defaultdict(list)
2019-02-20 19:25:41 +01:00
# get lists of extractor classes grouped by category
for extr in extractor.extractors():
2019-01-09 14:21:19 +01:00
if not extr.category or extr.category in IGNORE_LIST:
continue
2019-02-20 19:25:41 +01:00
extractors[extr.category].append(extr)
2019-02-20 19:25:41 +01:00
# sort extractor lists with the same category
for extrlist in extractors.values():
extrlist.sort(key=subcategory_key)
# ugly hack to add e-hentai.org
eh = []
for extr in extractors["exhentai"]:
class eh_extr(extr):
category = "e-hentai"
root = "https://e-hentai.org"
eh.append(eh_extr)
extractors["e-hentai"] = eh
2019-02-20 19:25:41 +01:00
# sort lists by category
return sorted(
extractors.values(),
key=lambda lst: category_key(lst[0]),
)
# define table columns
COLUMNS = (
("Site", 20,
lambda x: category_text(x[0])),
("URL" , 35,
lambda x: domain(x[0])),
("Capabilities", 50,
lambda x: ", ".join(subcategory_text(extr) for extr in x
if subcategory_text(extr))),
("Authentication", 16,
lambda x: AUTH_MAP.get(x[0].category, "")),
)
2019-01-09 14:21:19 +01:00
2019-02-20 19:25:41 +01:00
def write_output(fobj, columns, extractors):
2019-02-20 19:25:41 +01:00
def pad(output, col, category=None):
size = col[1]
output = output if isinstance(output, str) else col[2](output)
2019-02-20 19:25:41 +01:00
if len(output) > size:
sub = "|{}-{}|".format(category, col[0][0])
subs.append((sub, output))
output = sub
2019-02-20 19:25:41 +01:00
return output + " " * (size - len(output))
2019-02-20 19:25:41 +01:00
w = fobj.write
subs = []
2019-02-20 19:25:41 +01:00
# caption
w("Supported Sites\n")
w("===============\n")
w("Unless otherwise known, assume all sites to be NSFW\n\n")
2019-02-20 19:25:41 +01:00
# table head
sep = " ".join("=" * c[1] for c in columns) + "\n"
w(sep)
w(" ".join(pad(c[0], c) for c in columns).strip() + "\n")
w(sep)
2019-02-20 19:25:41 +01:00
# table body
for lst in extractors:
w(" ".join(
pad(col[2](lst), col, lst[0].category)
for col in columns
).strip())
w("\n")
2019-02-20 19:25:41 +01:00
# table bottom
w(sep)
w("\n")
2019-02-20 19:25:41 +01:00
# substitutions
for sub, value in subs:
w(".. {} replace:: {}\n".format(sub, value))
outfile = sys.argv[1] if len(sys.argv) > 1 else "supportedsites.rst"
with open(util.path("docs", outfile), "w") as file:
2019-02-20 19:25:41 +01:00
write_output(file, COLUMNS, build_extractor_list())