Debian Codegraph @

gallery_dl/extractor/__init__.py

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