-
-
Notifications
You must be signed in to change notification settings - Fork 872
/
__init__.py
199 lines (176 loc) · 3.83 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# -*- coding: utf-8 -*-
# Copyright 2015-2019 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
modules = [
"2chan",
"35photo",
"3dbooru",
"4chan",
"500px",
"8muses",
"adultempire",
"artstation",
"behance",
"blogger",
"bobx",
"danbooru",
"deviantart",
"dynastyscans",
"e621",
"erolord",
"exhentai",
"fallenangels",
"flickr",
"fuskator",
"gelbooru",
"gfycat",
"hbrowse",
"hentai2read",
"hentaicafe",
"hentaifoundry",
"hentaifox",
"hentaihere",
"hentainexus",
"hitomi",
"hypnohub",
"idolcomplex",
"imagebam",
"imagefap",
"imgbb",
"imgbox",
"imgth",
"imgur",
"instagram",
"issuu",
"keenspot",
"khinsider",
"kissmanga",
"komikcast",
"konachan",
"lineblog",
"livedoor",
"luscious",
"mangadex",
"mangafox",
"mangahere",
"mangapanda",
"mangapark",
"mangareader",
"mangastream",
"mangoxo",
"myportfolio",
"naver",
"newgrounds",
"ngomik",
"nhentai",
"nijie",
"nozomi",
"nsfwalbum",
"paheal",
"patreon",
"photobucket",
"piczel",
"pinterest",
"pixiv",
"pixnet",
"plurk",
"pornhub",
"pururin",
"reactor",
"readcomiconline",
"realbooru",
"reddit",
"rule34",
"safebooru",
"sankaku",
"sankakucomplex",
"seiga",
"senmanga",
"sexcom",
"simplyhentai",
"slickpic",
"slideshare",
"smugmug",
"tsumino",
"tumblr",
"twitter",
"vanillarock",
"vsco",
"wallhaven",
"warosu",
"weibo",
"wikiart",
"xhamster",
"xvideos",
"yandere",
"yaplog",
"yuki",
"foolfuuka",
"foolslide",
"mastodon",
"shopify",
"imagehosts",
"directlink",
"recursive",
"oauth",
"test",
]
def find(url):
"""Find a suitable extractor for the given URL"""
for cls in _list_classes():
match = cls.pattern.match(url)
if match and cls not in _blacklist:
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__
)
class blacklist():
"""Context Manager to blacklist extractor modules"""
def __init__(self, categories, extractors=None):
self.extractors = extractors or []
for cls in _list_classes():
if cls.category in categories:
self.extractors.append(cls)
def __enter__(self):
_blacklist.update(self.extractors)
def __exit__(self, etype, value, traceback):
_blacklist.clear()
# --------------------------------------------------------------------
# internals
_cache = []
_blacklist = set()
_module_iter = iter(modules)
def _list_classes():
"""Yield all available extractor classes"""
yield from _cache
for module_name in _module_iter:
module = importlib.import_module("."+module_name, __package__)
yield from add_module(module)
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__
)
]