1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 03:02:50 +01:00
gallery-dl/gallery_dl/extractor/__init__.py

202 lines
3.7 KiB
Python
Raw Normal View History

2015-06-28 22:53:52 +02:00
# -*- coding: utf-8 -*-
2014-10-12 21:56:44 +02:00
# Copyright 2015-2021 Mike Fährmann
2015-06-28 22:53:52 +02:00
#
# 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 re
import importlib
modules = [
2017-07-14 08:44:31 +02:00
"2chan",
"35photo",
2015-06-28 22:53:52 +02:00
"3dbooru",
"4chan",
"500px",
"8kun",
2019-06-10 22:17:46 +02:00
"8muses",
"adultempire",
"artstation",
"aryion",
"bcy",
2018-08-01 21:46:55 +02:00
"behance",
"blogger",
"cyberdrop",
2015-06-28 22:53:52 +02:00
"danbooru",
"derpibooru",
2015-10-05 20:29:48 +02:00
"deviantart",
2016-09-22 17:20:57 +02:00
"dynastyscans",
2015-06-28 22:53:52 +02:00
"e621",
"erome",
2016-08-04 18:08:48 +02:00
"exhentai",
2017-02-06 20:05:58 +01:00
"fallenangels",
2017-05-30 17:43:02 +02:00
"flickr",
2020-02-11 19:51:24 +01:00
"furaffinity",
"fuskator",
2016-08-04 18:08:48 +02:00
"gelbooru",
"gelbooru_v01",
"gelbooru_v02",
2017-05-28 17:09:54 +02:00
"gfycat",
2015-11-15 01:30:26 +01:00
"hbrowse",
2016-02-19 15:24:49 +01:00
"hentai2read",
2019-02-05 10:22:52 +01:00
"hentaicafe",
2015-11-14 03:19:44 +01:00
"hentaifoundry",
"hentaifox",
"hentaihand",
"hentaihere",
"hentainexus",
"hiperdex",
2015-10-28 16:24:35 +01:00
"hitomi",
"idolcomplex",
2015-06-28 22:53:52 +02:00
"imagebam",
"imagechest",
2016-08-09 14:05:12 +02:00
"imagefap",
2019-07-30 23:02:21 +02:00
"imgbb",
2015-06-28 22:53:52 +02:00
"imgbox",
2015-10-28 23:26:47 +01:00
"imgth",
2015-10-12 22:34:45 +02:00
"imgur",
"inkbunny",
"instagram",
"issuu",
"kabeuchi",
"keenspot",
"kemonoparty",
2016-04-20 08:34:44 +02:00
"khinsider",
"komikcast",
"lineblog",
"livedoor",
2016-08-01 15:36:56 +02:00
"luscious",
"mangadex",
2017-01-14 19:39:21 +01:00
"mangafox",
2015-11-26 03:06:08 +01:00
"mangahere",
"mangakakalot",
2015-12-08 22:29:34 +01:00
"mangapark",
2015-06-28 22:53:52 +02:00
"mangareader",
2015-11-08 00:03:14 +01:00
"mangastream",
"mangoxo",
"myhentaigallery",
"myportfolio",
"naver",
"newgrounds",
"ngomik",
2015-10-28 12:08:27 +01:00
"nhentai",
2015-06-28 22:53:52 +02:00
"nijie",
"nozomi",
"nsfwalbum",
"paheal",
2019-05-16 23:56:48 +02:00
"patreon",
"photobucket",
"photovogue",
"piczel",
"pillowfort",
2016-09-02 19:11:16 +02:00
"pinterest",
"pixiv",
"pixnet",
"plurk",
"pornhub",
"pururin",
"reactor",
"readcomiconline",
"reddit",
2020-05-10 00:31:42 +02:00
"redgifs",
2015-11-09 02:29:33 +01:00
"sankaku",
"sankakucomplex",
2016-08-09 16:36:30 +02:00
"seiga",
2016-08-02 17:42:22 +02:00
"senmanga",
"sexcom",
"simplyhentai",
2019-06-09 21:59:22 +02:00
"slickpic",
"slideshare",
"smugmug",
"speakerdeck",
"subscribestar",
2019-01-29 17:23:01 +01:00
"tsumino",
2016-02-20 11:29:10 +01:00
"tumblr",
2016-10-06 19:12:07 +02:00
"twitter",
"unsplash",
"vanillarock",
2019-07-22 22:15:36 +02:00
"vsco",
"wallhaven",
2017-08-18 19:52:58 +02:00
"warosu",
"weasyl",
"webtoons",
"weibo",
"wikiart",
"xhamster",
2017-11-02 15:36:53 +01:00
"xvideos",
"yuki",
"booru",
"moebooru",
"foolfuuka",
"foolslide",
"mastodon",
"shopify",
"imagehosts",
2017-05-24 12:51:18 +02:00
"directlink",
2016-10-01 15:54:27 +02:00
"recursive",
"oauth",
"test",
2015-06-28 22:53:52 +02:00
]
2017-02-01 00:53:19 +01:00
2015-10-05 17:52:50 +02:00
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)
2015-11-21 00:30:31 +01:00
return None
2015-06-28 22:53:52 +02:00
2017-02-01 00:53:19 +01:00
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__
)
2017-02-01 00:53:19 +01:00
2015-06-28 22:53:52 +02:00
# --------------------------------------------------------------------
# internals
_cache = []
_module_iter = iter(modules)
2017-02-01 00:53:19 +01:00
def _list_classes():
"""Yield all available extractor classes"""
2016-08-23 16:36:39 +02:00
yield from _cache
2015-10-05 18:10:18 +02:00
2015-06-28 22:53:52 +02:00
for module_name in _module_iter:
module = importlib.import_module("."+module_name, __package__)
yield from add_module(module)
2015-11-20 19:54:07 +01:00
globals()["_list_classes"] = lambda : _cache
2017-02-01 00:53:19 +01:00
2015-11-20 19:54:07 +01:00
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__
2015-11-20 19:54:07 +01:00
)
]