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