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-05 17:52:50 +02: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",
|
|
|
|
"imagebam",
|
|
|
|
"imgbox",
|
|
|
|
"imgchili",
|
2015-10-12 22:34:45 +02:00
|
|
|
"imgur",
|
2015-06-28 22:53:52 +02:00
|
|
|
"mangareader",
|
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",
|
|
|
|
"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-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
|