Debian Codegraph @

gallery_dl/extractor/adultphotosets.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2026 w43322
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 """Extractors for https://adultphotosets.best/"""
10
11 from .common import Extractor, Message
12 from .. import text
13
14 BASE_PATTERN = r"(?:https?://)?(?:www\.)?adultphotosets\.best"
15 PHOTO_PATTERN = (
16 r"(amateur-photo|hentai-pictures|"
17 r"(?:alternative|artistic|softcore|hardcore|lesbian)-photo-sets)")
18
19
20 class AdultphotosetsExtractor(Extractor):
21 """Base class for adultphotosets extractors"""
22 category = "adultphotosets"
23 root = "https://adultphotosets.best"
24 request_interval = (0.5, 1.5)
25
26 def items(self):
27 data = {"_extractor": AdultphotosetsGalleryExtractor}
28 for url in self.galleries():
29 yield Message.Queue, url, data
30
31 def _pagination(self, url):
32 last = None
33
34 while True:
35 page = self.request(url).text
36
37 for match in AdultphotosetsGalleryExtractor.pattern.finditer(page):
38 if (url := match[0]) != last:
39 yield (last := url)
40
41 nav = text.extr(page, '<span class="page_next"', '</span>')
42 url = text.extr(nav, '<a href="', '"')
43 if not url:
44 break
45 url = text.unescape(url)
46
47
48 class AdultphotosetsGalleryExtractor(AdultphotosetsExtractor):
49 """Extractor for adultphotosets image galleries"""
50 subcategory = "gallery"
51 parent = True
52 directory_fmt = ("{category}", "{title} ({gallery_id})")
53 pattern = rf"{BASE_PATTERN}/(?:{PHOTO_PATTERN}/)?(\d+)-([^/?#]+)\.html"
54 example = "https://adultphotosets.best/hardcore-photo-sets/123-TITLE.html"
55
56 def items(self):
57 page = self.request(self.url).text
58 article = text.extr(page, '<article', '</article>')
59 images = self.images(article)
60 data = self.metadata(page, article)
61 data["count"] = len(images)
62
63 yield Message.Directory, "", data
64 for data["num"], url in enumerate(images, 1):
65 yield Message.Queue, text.unescape(url), data
66
67 def metadata(self, page, article):
68 section, gallery_id, slug = self.groups
69 return {
70 "gallery_id": text.parse_int(gallery_id),
71 "slug" : slug,
72 "section" : section or "",
73 "title" : text.unescape(text.extr(
74 article, '<h2 class="title">', '</h2>')).strip(),
75 "date" : self.parse_datetime_iso(text.extr(
76 article, '<time datetime="', '"')),
77 "uploader" : text.unescape(text.extr(
78 article, "onclick=\"ShowProfile('", "'")),
79 "tags" : text.split_html(text.extr(
80 page, '<div class="tag_list">', '</div>')),
81 "likes" : text.parse_int(text.extr(
82 article, '<span id="ratig-layer-', '</').rpartition(">")[2]),
83 "views" : text.parse_int(text.extr(
84 article, 'title="Views: ', '"')),
85 "comments" : text.parse_int(text.extr(
86 article, 'title="Comments: ', '"')),
87 }
88
89 def images(self, article):
90 if content := text.extr(article, '<!--QuoteEEnd--><br><br>', "\n"):
91 return list(text.extract_iter(content, ' href="', '"'))
92
93 # legacy galleries
94 content = text.extr(
95 article, '<div class="text">', '<div class="story_tools')
96 return [href for href in text.extract_iter(content, ' href="', '"')
97 if not href.startswith(self.root)]
98
99
100 class AdultphotosetsTagExtractor(AdultphotosetsExtractor):
101 """Extractor for adultphotosets tag searches"""
102 subcategory = "tag"
103 pattern = BASE_PATTERN + r"(/tags/([^/?#]+)(?:/page/\d+)?)"
104 example = "https://adultphotosets.best/tags/TAG/"
105
106 def galleries(self):
107 path, tag = self.groups
108 self.kwdict["search_tags"] = text.unquote(tag)
109 return self._pagination(f"{self.root}{path}/")
110
111
112 class AdultphotosetsCategoryExtractor(AdultphotosetsExtractor):
113 """Extractor for adultphotosets image categories"""
114 subcategory = "category"
115 pattern = rf"{BASE_PATTERN}(/{PHOTO_PATTERN}(?:/page/\d+)?)/?$"
116 example = "https://adultphotosets.best/softcore-photo-sets/"
117
118 def galleries(self):
119 path, self.kwdict["section"] = self.groups
120 return self._pagination(f"{self.root}{path}/")
121
122
123 class AdultphotosetsHomeExtractor(AdultphotosetsExtractor):
124 """Extractor for the adultphotosets home listing"""
125 subcategory = "home"
126 pattern = BASE_PATTERN + r"(/page/\d+)?/?$"
127 example = "https://adultphotosets.best/"
128
129 def galleries(self):
130 return self._pagination(f"{self.root}{self.groups[0] or ''}/")