Debian Codegraph @

gallery_dl/extractor/imgth.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 """Extractors for https://imgth.com/"""
10
11 from .common import GalleryExtractor
12 from .. import text
13
14
15 class ImgthGalleryExtractor(GalleryExtractor):
16 """Extractor for image galleries from imgth.com"""
17 category = "imgth"
18 root = "https://imgth.com"
19 pattern = r"(?:https?://)?(?:www\.)?imgth\.com/gallery/(\d+)"
20 example = "https://imgth.com/gallery/123/TITLE"
21
22 def __init__(self, match):
23 self.gallery_id = gid = match[1]
24 url = f"{self.root}/gallery/{gid}/g/"
25 GalleryExtractor.__init__(self, match, url)
26
27 def metadata(self, page):
28 extr = text.extract_from(page)
29 return {
30 "gallery_id": text.parse_int(self.gallery_id),
31 "title": text.unescape(extr("<h1>", "</h1>")),
32 "count": text.parse_int(extr(
33 "total of images in this gallery: ", " ")),
34 "date" : self.parse_datetime(
35 extr("created on ", " by <")
36 .replace("th, ", " ", 1).replace("nd, ", " ", 1)
37 .replace("st, ", " ", 1), "%B %d %Y at %H:%M"),
38 "user" : text.unescape(extr(">", "<")),
39 }
40
41 def images(self, page):
42 pnum = 0
43
44 while True:
45 thumbs = text.extr(page, '<ul class="thumbnails">', '</ul>')
46 for url in text.extract_iter(thumbs, '<img src="', '"'):
47 path = url.partition("/thumbs/")[2]
48 yield (f"{self.root}/images/{path}", None)
49
50 if '<li class="next">' not in page:
51 return
52
53 pnum += 1
54 url = f"{self.root}/gallery/{self.gallery_id}/g/page/{pnum}"
55 page = self.request(url).text