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

72 lines
1.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
2015-06-28 22:53:52 +02:00
# Copyright 2015 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 re
import importlib
2015-10-05 18:10:18 +02:00
from .. import config
2015-06-28 22:53:52 +02:00
modules = [
"pixiv",
2015-10-31 16:50:20 +01:00
"exhentai",
2015-06-28 22:53:52 +02:00
"gelbooru",
"3dbooru",
"4chan",
"8chan",
"batoto",
"danbooru",
2015-10-05 20:29:48 +02:00
"deviantart",
2015-06-28 22:53:52 +02:00
"e621",
2015-10-28 16:24:35 +01:00
"hitomi",
2015-06-28 22:53:52 +02:00
"imagebam",
"imgbox",
"imgchili",
2015-10-28 23:26:47 +01:00
"imgth",
2015-10-12 22:34:45 +02:00
"imgur",
2015-11-07 13:28:07 +01:00
"kissmanga",
2015-11-06 13:24:43 +01:00
"konachan",
2015-11-08 00:02:37 +01:00
"mangapanda",
2015-06-28 22:53:52 +02:00
"mangareader",
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",
2015-10-08 20:43:52 +02:00
"powermanga",
2015-06-28 22:53:52 +02:00
"redhawkscans",
2015-11-06 13:52:40 +01:00
"safebooru",
2015-11-09 02:29:33 +01:00
"sankaku",
2015-11-13 00:21:50 +01:00
"spectrumnexus",
2015-06-28 22:53:52 +02:00
"yandere",
]
2015-10-05 17:52:50 +02:00
def find(url):
2015-06-28 22:53:52 +02:00
"""Find extractor suitable for handling the given url"""
for pattern, module, klass in _list_patterns():
match = re.match(pattern, url)
if match:
2015-10-05 17:52:50 +02:00
return klass(match), module.info
2015-11-06 13:21:53 +01:00
return None, None
2015-06-28 22:53:52 +02:00
# --------------------------------------------------------------------
# internals
_cache = []
_module_iter = iter(modules)
def _list_patterns():
"""Yield all available (pattern, module, klass) tuples"""
for entry in _cache:
yield entry
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__)
klass = getattr(module, module.info["extractor"])
2015-10-05 18:10:18 +02:00
userpatterns = config.get(("extractor", module_name, "pattern"), default=[])
for pattern in userpatterns + module.info["pattern"]:
2015-06-28 22:53:52 +02:00
etuple = (pattern, module, klass)
_cache.append(etuple)
yield etuple