Debian Codegraph @

gallery_dl/extractor/__init__.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2015-2025 Mike Fährmann
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation.
8
9 import sys
10 from ..text import re_compile
11
12 modules = [
13 "2ch",
14 "2chan",
15 "2chen",
16 "35photo",
17 "4chan",
18 "4archive",
19 "4chanarchives",
20 "500px",
21 "8chan",
22 "8muses",
23 "adultempire",
24 "adultphotosets",
25 "agnph",
26 "ahottie",
27 "allporncomic",
28 "animepictures",
29 "ao3",
30 "arcalive",
31 "architizer",
32 "arena",
33 "artfight",
34 "artstation",
35 "aryion",
36 "audiochan",
37 "bakashots",
38 "batcave",
39 "bbc",
40 "behance",
41 "bellazon",
42 "bilibili",
43 "blogger",
44 "bluesky",
45 "boosty",
46 "booth",
47 "bunkr",
48 "cara",
49 "catbox",
50 "chevereto",
51 "cien",
52 "civitai",
53 "clonr",
54 "comedywildlifephoto",
55 "comicartfans",
56 "comicvine",
57 "cosmos",
58 "cosplayrule34",
59 "cyberdrop",
60 "cyberfile",
61 "danbooru",
62 "dandadan",
63 "dankefuerslesen",
64 "dcinside",
65 "deviantart",
66 "discord",
67 "dynastyscans",
68 "e621",
69 "eporner",
70 "erome",
71 "everia",
72 "exhentai",
73 "facebook",
74 "fanbox",
75 "fansly",
76 "fantia",
77 "fapello",
78 "fapachi",
79 "fikfap",
80 "filester",
81 "fitnakedgirls",
82 "flickr",
83 "foriio",
84 "framedsc",
85 "furaffinity",
86 "furry34",
87 "ganknow",
88 "gelbooru",
89 "gelbooru_v01",
90 "gelbooru_v02",
91 "girlsreleased",
92 "girlswithmuscle",
93 "gofile",
94 "goonbox",
95 "harvardlawnuremberg",
96 "hatenablog",
97 "hdoujin",
98 "hentai2read",
99 "hentaicosplays",
100 "hentaifoundry",
101 "hentaihand",
102 "hentaihere",
103 "hentainexus",
104 "hiperdex",
105 "hitomi",
106 "hotleak",
107 "idolcomplex",
108 "imagebam",
109 "imagechest",
110 "imagefap",
111 "imagepond",
112 "imageshack",
113 "imdb",
114 "imgbb",
115 "imgbox",
116 "imgpile",
117 "imgth",
118 "imgur",
119 "imhentai",
120 "inkbunny",
121 "instagram",
122 "issuu",
123 "itaku",
124 "iwara",
125 "joyreactor",
126 "jschan",
127 "kabeuchi",
128 "kaliscan",
129 "kagane",
130 "keenspot",
131 "kemono",
132 "khinsider",
133 "kokonotsuba",
134 "komikcast",
135 "koofr",
136 "leakgallery",
137 "leftybooru",
138 "lensdump",
139 "lexica",
140 "lightroom",
141 "listal",
142 "livedoor",
143 "lofter",
144 "luscious",
145 "lynxchan",
146 "madokami",
147 "mangadex",
148 "mangafire",
149 "mangafox",
150 "mangafreak",
151 "mangahere",
152 "manganelo",
153 "mangapark",
154 "mangaread",
155 "mangareader",
156 "mangataro",
157 "mangatown",
158 "mangayi",
159 "mangoxo",
160 "mgrenders",
161 "misskey",
162 "mixdrop",
163 "motherless",
164 "myfigurecollection",
165 "myhentaigallery",
166 "myportfolio",
167 "naverblog",
168 "naverchzzk",
169 "naverwebtoon",
170 "newgrounds",
171 "nhentai",
172 "nijie",
173 "nitter",
174 "nozomi",
175 "nsfwalbum",
176 "nudostar",
177 "okporn",
178 "onlyhaven",
179 "paheal",
180 "patreon",
181 "pawchive",
182 "pexels",
183 "philomena",
184 "pholder",
185 "photovogue",
186 "picarto",
187 "picazor",
188 "pictoa",
189 "piczel",
190 "pillowfort",
191 "pinterest",
192 "pixeldrain",
193 "pixiv",
194 "pixnet",
195 "plurk",
196 "poipiku",
197 "poringa",
198 "pornhub",
199 "pornpics",
200 "pornstarstube",
201 "postmill",
202 "postype",
203 "rawkuma",
204 "reactor",
205 "realbooru",
206 "reddit",
207 "redgifs",
208 "rule34us",
209 "rule34vault",
210 "rule34xyz",
211 "s3ndpics",
212 "sakuhentai",
213 "sankaku",
214 "sankakucomplex",
215 "scatbooru",
216 "schalenetwork",
217 "scrolller",
218 "seiga",
219 "senmanga",
220 "sexcom",
221 "shareimage",
222 "shimmie2",
223 "simplyhentai",
224 "sizebooru",
225 "skeb",
226 "slickpic",
227 "slideshare",
228 "smugmug",
229 "snapchat",
230 "sofurry",
231 "soundgasm",
232 "speakerdeck",
233 "steamgriddb",
234 "subscribestar",
235 "sxypix",
236 "szurubooru",
237 "tapas",
238 "tcbscans",
239 "telegraph",
240 "tenor",
241 "thefap",
242 "thehentaiworld",
243 "tiktok",
244 "tmohentai",
245 "toyhouse",
246 "tumblr",
247 "tumblrgallery",
248 "tungsten",
249 "turbo",
250 "twibooru",
251 "twitter",
252 "urlgalleries",
253 "unsplash",
254 "uploadir",
255 "urlshortener",
256 "vanillarock",
257 "vanlifetrader",
258 "vichan",
259 "vipergirls",
260 "vk",
261 "vsco",
262 "wallhaven",
263 "wallpapercave",
264 "warosu",
265 "weasyl",
266 "webmshare",
267 "webtoons",
268 "weebcentral",
269 "weibo",
270 "whitekitten",
271 "whyp",
272 "wikiart",
273 "wikifeet",
274 "wikimedia",
275 "xasiat",
276 "xenforo",
277 "xfolio",
278 "xhamster",
279 "xvideos",
280 "yiffverse",
281 "yourlesbians",
282 "zerochan",
283 "booru",
284 "moebooru",
285 "foolfuuka",
286 "foolslide",
287 "mastodon",
288 "shopify",
289 "lolisafe",
290 "imagehosts",
291 "directlink",
292 "recursive",
293 "oauth",
294 "noop",
295 "ytdl",
296 "generic",
297 ]
298
299
300 def find(url):
301 """Find a suitable extractor for the given URL"""
302 for cls in _list_classes():
303 if match := cls.pattern.match(url):
304 return cls(match)
305 return None
306
307
308 def add(cls):
309 """Add 'cls' to the list of available extractors"""
310 if isinstance(cls.pattern, str):
311 cls.pattern = re_compile(cls.pattern)
312 _cache.append(cls)
313 return cls
314
315
316 def add_module(module):
317 """Add all extractors in 'module' to the list of available extractors"""
318 if classes := _get_classes(module):
319 if isinstance(classes[0].pattern, str):
320 for cls in classes:
321 cls.pattern = re_compile(cls.pattern)
322 _cache.extend(classes)
323 return classes
324
325
326 def extractors():
327 """Yield all available extractor classes"""
328 return sorted(
329 _list_classes(),
330 key=lambda x: x.__name__
331 )
332
333
334 # --------------------------------------------------------------------
335 # internals
336
337
338 def _list_classes():
339 """Yield available extractor classes"""
340 yield from _cache
341
342 for module in _module_iter:
343 yield from add_module(module)
344
345 globals()["_list_classes"] = lambda : _cache
346
347
348 def _modules_internal():
349 globals_ = globals()
350 for module_name in modules:
351 yield __import__(module_name, globals_, None, None, 1)
352
353
354 def _modules_path(path, files):
355 sys.path.insert(0, path)
356 try:
357 return [__import__(name) for name in files]
358 finally:
359 del sys.path[0]
360
361
362 def _get_classes(module):
363 """Return a list of all extractor classes in a module"""
364 return [
365 cls for cls in module.__dict__.values() if (
366 hasattr(cls, "pattern") and cls.__module__ == module.__name__
367 )
368 ]
369
370
371 _cache = []
372 _module_iter = _modules_internal()