1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-24 03:32:33 +01:00
gallery-dl/gallery_dl/extractor/__init__.py
2023-05-26 03:22:23 -04:00

270 lines
4.7 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2015-2023 Mike Fährmann
#
# 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.
import sys
import re
modules = [
"2chan",
"2chen",
"35photo",
"3dbooru",
"4chan",
"4chanarchives",
"500px",
"8chan",
"8muses",
"adultempire",
"architizer",
"artstation",
"aryion",
"bbc",
"bcy",
"behance",
"blogger",
"bunkr",
"catbox",
"comicvine",
"cyberdrop",
"danbooru",
"desktopography",
"deviantart",
"dynastyscans",
"e621",
"erome",
"exhentai",
"fallenangels",
"fanbox",
"fanleaks",
"fantia",
"fapello",
"fapachi",
"flickr",
"furaffinity",
"fuskator",
"gelbooru",
"gelbooru_v01",
"gelbooru_v02",
"gfycat",
"gofile",
"hbrowse",
"hentai2read",
"hentaicosplays",
"hentaifoundry",
"hentaifox",
"hentaihand",
"hentaihere",
"hiperdex",
"hitomi",
"hotleak",
"idolcomplex",
"imagebam",
"imagechest",
"imagefap",
"imgbb",
"imgbox",
"imgth",
"imgur",
"inkbunny",
"instagram",
"issuu",
"itaku",
"itchio",
"jpgfish",
"kabeuchi",
"keenspot",
"kemonoparty",
"khinsider",
"komikcast",
"lensdump",
"lexica",
"lightroom",
"lineblog",
"livedoor",
"luscious",
"lynxchan",
"mangadex",
"mangafox",
"mangahere",
"mangakakalot",
"manganelo",
"mangapark",
"mangaread",
"mangasee",
"mangoxo",
"misskey",
"myhentaigallery",
"myportfolio",
"naver",
"naverwebtoon",
"newgrounds",
"nhentai",
"nijie",
"nitter",
"nozomi",
"nsfwalbum",
"nudecollect",
"paheal",
"patreon",
"philomena",
"photobucket",
"photovogue",
"picarto",
"piczel",
"pillowfort",
"pinterest",
"pixiv",
"pixnet",
"plurk",
"poipiku",
"pornhub",
"pornpics",
"pururin",
"reactor",
"readcomiconline",
"reddit",
"redgifs",
"rule34us",
"sankaku",
"sankakucomplex",
"seiga",
"senmanga",
"sexcom",
"shimmie2",
"simplyhentai",
"skeb",
"slickpic",
"slideshare",
"smugmug",
"soundgasm",
"speakerdeck",
"subscribestar",
"szurubooru",
"tapas",
"tcbscans",
"telegraph",
"toyhouse",
"tsumino",
"tumblr",
"tumblrgallery",
"twibooru",
"twitter",
"unsplash",
"uploadir",
"urlshortener",
"vanillarock",
"vichan",
"vipergirls",
"vk",
"vsco",
"wallhaven",
"wallpapercave",
"warosu",
"weasyl",
"webmshare",
"webtoons",
"weibo",
"wikiart",
"wikifeet",
"xhamster",
"xvideos",
"zerochan",
"booru",
"moebooru",
"foolfuuka",
"foolslide",
"mastodon",
"shopify",
"lolisafe",
"imagehosts",
"directlink",
"recursive",
"oauth",
"test",
"ytdl",
"generic",
]
def find(url):
"""Find a suitable extractor for the given URL"""
for cls in _list_classes():
match = cls.pattern.match(url)
if match:
return cls(match)
return None
def add(cls):
"""Add 'cls' to the list of available extractors"""
cls.pattern = re.compile(cls.pattern)
_cache.append(cls)
return cls
def add_module(module):
"""Add all extractors in 'module' to the list of available extractors"""
classes = _get_classes(module)
for cls in classes:
cls.pattern = re.compile(cls.pattern)
_cache.extend(classes)
return classes
def extractors():
"""Yield all available extractor classes"""
return sorted(
_list_classes(),
key=lambda x: x.__name__
)
# --------------------------------------------------------------------
# internals
def _list_classes():
"""Yield available extractor classes"""
yield from _cache
for module in _module_iter:
yield from add_module(module)
globals()["_list_classes"] = lambda : _cache
def _modules_internal():
globals_ = globals()
for module_name in modules:
yield __import__(module_name, globals_, None, (), 1)
def _modules_path(path, files):
sys.path.insert(0, path)
try:
return [
__import__(name[:-3])
for name in files
if name.endswith(".py")
]
finally:
del sys.path[0]
def _get_classes(module):
"""Return a list of all extractor classes in a module"""
return [
cls for cls in module.__dict__.values() if (
hasattr(cls, "pattern") and cls.__module__ == module.__name__
)
]
_cache = []
_module_iter = _modules_internal()