Debian Codegraph @

gallery_dl/extractor/eporner.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
6
7 """Extractors for https://www.eporner.com/"""
8
9 from .common import GalleryExtractor
10 from .. import text
11
12
13 class EpornerGalleryExtractor(GalleryExtractor):
14 """Extractor for image galleries from eporner.com"""
15 category = "eporner"
16 root = "https://www.eporner.com"
17 pattern = (r"(?:https?://)?(?:www\.)?eporner\.com"
18 r"/gallery/(\w+)(?:/([\w-]+))?")
19 example = "https://www.eporner.com/gallery/GID/SLUG/"
20
21 def __init__(self, match):
22 url = f"{self.root}/gallery/{match[1]}/{match[2]}/"
23 GalleryExtractor.__init__(self, match, url)
24
25 def metadata(self, page):
26 if page.find("Age Verification<", 0, 240) >= 0:
27 raise self.exc.AuthRequired("Age Verification", "gallery")
28 title = text.extr(page, "<title>", " - EPORNER</title>")
29 if title.endswith(" Photo Gallery"):
30 title = title[:-14]
31
32 return {
33 "gallery_id": self.groups[0],
34 "title" : text.unescape(title),
35 "slug" : text.extr(
36 page, "/gallery/", '/"').rpartition("/")[2],
37 "description": text.unescape(text.extr(
38 page, 'name="description" content="', '"')),
39 "tags": text.extr(
40 page, 'EP.ads.keywords = "', '"').split(","),
41 }
42
43 def images(self, page):
44 album = text.extr(
45 page, 'class="photosgrid gallerygrid"', 'id="relatedgalleries"')
46
47 results = []
48 for url in text.extract_iter(album, ' src="', '"'):
49 url, _, ext = url.rpartition(".")
50 # Preview images have a resolution suffix.
51 # E.g. "11208293-image-3_296x1000.jpg".
52 # The same name, but without the suffix, leads to the full image.
53 url = url[:url.rfind("_")]
54 name = url[url.rfind("/")+1:]
55 results.append((f"{url}.{ext}", {"id": name[:name.find("-")]}))
56 return results