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 "steamgriddb",
235 "subscribestar",
236 "sxypix",
237 "szurubooru",
238 "tapas",
239 "tcbscans",
240 "telegraph",
241 "tenor",
242 "thefap",
243 "thehentaiworld",
244 "tiktok",
245 "tmohentai",
246 "toyhouse",
247 "tumblr",
248 "tumblrgallery",
249 "tungsten",
250 "turbo",
251 "twibooru",
252 "twitter",
253 "urlgalleries",
254 "unsplash",
255 "uploadir",
256 "urlshortener",
257 "vanillarock",
258 "vanlifetrader",
259 "vichan",
260 "vipergirls",
261 "vk",
262 "vsco",
263 "wallhaven",
264 "wallpapercave",
265 "warosu",
266 "weasyl",
267 "webmshare",
268 "webtoons",
269 "weebcentral",
270 "weibo",
271 "whitekitten",
272 "whyp",
273 "wikiart",
274 "wikifeet",
275 "wikimedia",
276 "xasiat",
277 "xenforo",
278 "xfolio",
279 "xhamster",
280 "xvideos",
281 "yiffverse",
282 "yourlesbians",
283 "zerochan",
284 "booru",
285 "moebooru",
286 "foolfuuka",
287 "foolslide",
288 "mastodon",
289 "shopify",
290 "lolisafe",
291 "imagehosts",
292 "directlink",
293 "recursive",
294 "oauth",
295 "noop",
296 "ytdl",
297 "generic",
298 ]
299
300
301 def find(url):
302 """Find a suitable extractor for the given URL"""
303 for cls in _list_classes():
304 if match := cls.pattern.match(url):
305 return cls(match)
306 return None
307
308
309 def add(cls):
310 """Add 'cls' to the list of available extractors"""
311 if isinstance(cls.pattern, str):
312 cls.pattern = re_compile(cls.pattern)
313 _cache.append(cls)
314 return cls
315
316
317 def add_module(module):
318 """Add all extractors in 'module' to the list of available extractors"""
319 if classes := _get_classes(module):
320 if isinstance(classes[0].pattern, str):
321 for cls in classes:
322 cls.pattern = re_compile(cls.pattern)
323 _cache.extend(classes)
324 return classes
325
326
327 def extractors():
328 """Yield all available extractor classes"""
329 return sorted(
330 _list_classes(),
331 key=lambda x: x.__name__
332 )
333
334
335 # --------------------------------------------------------------------
336 # internals
337
338
339 def _list_classes():
340 """Yield available extractor classes"""
341 yield from _cache
342
343 for module in _module_iter:
344 yield from add_module(module)
345
346 globals()["_list_classes"] = lambda : _cache
347
348
349 def _modules_internal():
350 globals_ = globals()
351 for module_name in modules:
352 yield __import__(module_name, globals_, None, None, 1)
353
354
355 def _modules_path(path, files):
356 sys.path.insert(0, path)
357 try:
358 return [__import__(name) for name in files]
359 finally:
360 del sys.path[0]
361
362
363 def _get_classes(module):
364 """Return a list of all extractor classes in a module"""
365 return [
366 cls for cls in module.__dict__.values() if (
367 hasattr(cls, "pattern") and cls.__module__ == module.__name__
368 )
369 ]
370
371
372 _cache = []
373 _module_iter = _modules_internal()