1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00
gallery-dl/gallery_dl/extractor/__init__.py

120 lines
2.5 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
2016-09-08 07:56:52 +02:00
# Copyright 2015,2016 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
2015-10-05 18:10:18 +02:00
from .. import config
2015-06-28 22:53:52 +02:00
modules = [
"pixiv",
"3dbooru",
"4chan",
"8chan",
"batoto",
"danbooru",
2015-10-05 20:29:48 +02:00
"deviantart",
2016-09-26 21:58:18 +02:00
"dokireader",
2016-09-22 17:20:57 +02:00
"dynastyscans",
2015-06-28 22:53:52 +02:00
"e621",
2016-08-04 18:08:48 +02:00
"exhentai",
"gelbooru",
2017-01-10 00:05:08 +01:00
"gomanga",
2015-11-15 01:30:26 +01:00
"hbrowse",
2016-02-19 15:24:49 +01:00
"hentai2read",
2016-08-06 13:24:40 +02:00
"hentaibox",
2015-11-14 03:19:44 +01:00
"hentaifoundry",
"hentaihere",
2015-10-28 16:24:35 +01:00
"hitomi",
2015-06-28 22:53:52 +02:00
"imagebam",
2016-08-09 14:05:12 +02:00
"imagefap",
2015-06-28 22:53:52 +02:00
"imgbox",
"imgchili",
2015-10-28 23:26:47 +01:00
"imgth",
2015-10-12 22:34:45 +02:00
"imgur",
2016-12-29 16:41:08 +01:00
"jaiminisbox",
2016-04-20 08:34:44 +02:00
"khinsider",
2016-12-15 16:17:07 +01:00
"kisscomic",
2015-11-07 13:28:07 +01:00
"kissmanga",
2015-11-06 13:24:43 +01:00
"konachan",
2016-08-01 15:36:56 +02:00
"luscious",
2017-01-14 19:39:21 +01:00
"mangafox",
2015-11-26 03:06:08 +01:00
"mangahere",
2015-11-25 22:05:26 +01:00
"mangamint",
2015-11-08 00:02:37 +01:00
"mangapanda",
2015-12-08 22:29:34 +01:00
"mangapark",
2015-06-28 22:53:52 +02:00
"mangareader",
2015-11-15 03:40:17 +01:00
"mangashare",
2015-11-08 00:03:14 +01:00
"mangastream",
2015-10-28 12:08:27 +01:00
"nhentai",
2015-06-28 22:53:52 +02:00
"nijie",
2016-09-02 19:11:16 +02:00
"pinterest",
2015-10-08 20:43:52 +02:00
"powermanga",
"readcomiconline",
2016-12-20 16:30:25 +01:00
"readcomics",
2016-09-17 18:12:37 +02:00
"rule34",
2015-11-06 13:52:40 +01:00
"safebooru",
2015-11-09 02:29:33 +01:00
"sankaku",
2016-08-09 16:36:30 +02:00
"seiga",
2016-08-02 17:42:22 +02:00
"senmanga",
2016-10-25 15:25:25 +02:00
"sensescans",
2015-11-13 00:21:50 +01:00
"spectrumnexus",
2016-02-20 11:29:10 +01:00
"tumblr",
2016-10-06 19:12:07 +02:00
"twitter",
2016-10-19 13:15:41 +02:00
"whentai",
2016-10-26 23:10:41 +02:00
"worldthree",
2015-06-28 22:53:52 +02:00
"yandere",
2017-01-13 00:03:12 +01:00
"yomanga",
"yonkouprod",
"imagehosts",
2016-10-01 15:54:27 +02:00
"recursive",
"test",
2015-06-28 22:53:52 +02:00
]
2015-10-05 17:52:50 +02:00
def find(url):
"""Find suitable extractor for the given url"""
2015-11-21 03:12:36 +01:00
for pattern, klass in _list_patterns():
2016-08-23 16:36:39 +02:00
match = pattern.match(url)
2015-06-28 22:53:52 +02:00
if match:
2015-11-21 00:30:31 +01:00
return klass(match)
return None
2015-06-28 22:53:52 +02:00
def extractors():
"""Yield all available extractor classes"""
return sorted(
set(klass for _, klass in _list_patterns()),
key=lambda x: x.__name__
)
2015-06-28 22:53:52 +02:00
# --------------------------------------------------------------------
# internals
_cache = []
_module_iter = iter(modules)
def _list_patterns():
"""Yield all available (pattern, class) tuples"""
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__)
tuples = [
2016-08-23 16:36:39 +02:00
(re.compile(pattern), klass)
for klass in _get_classes(module)
for pattern in klass.pattern
]
_cache.extend(tuples)
2016-08-23 16:36:39 +02:00
yield from tuples
2015-11-20 19:54:07 +01:00
def _get_classes(module):
"""Return a list of all extractor classes in a module"""
return [
klass for klass in module.__dict__.values() if (
2015-11-21 00:30:31 +01:00
hasattr(klass, "pattern") and klass.__module__ == module.__name__
2015-11-20 19:54:07 +01:00
)
]