aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/zzup.py
blob: 20454b4103529172ad18cd2474a3400c162da79d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

"""Extractors for https://zzup.com/"""

from .common import GalleryExtractor
from .. import text


class ZzupGalleryExtractor(GalleryExtractor):
    category = "zzup"
    directory_fmt = ("{category}", "{title}")
    filename_fmt = "{num:>03}.{extension}"
    archive_fmt = "{slug}_{num}"
    root = "https://zzup.com"
    pattern = (r"(?:https?://)?(up\.|w+\.)?zzup\.com(/(?:viewalbum|content)"
               r"/[\w=]+/([^/?#]+)/[\w=]+)/(?:index|page-\d+)\.html")
    example = "https://zzup.com/content/xyz=/12345_TITLE/123=/index.html"

    def __init__(self, match):
        subdomain, path, self.slug = match.groups()
        if subdomain == "up.":
            self.root = "https://up.zzup.com"
            self.images = self.images_v2
        url = "{}{}/index.html".format(self.root, path)
        GalleryExtractor.__init__(self, match, url)

    def metadata(self, page):
        return {
            "slug" : self.slug,
            "title": text.unescape(text.extr(
                page, "<title>", "</title>"))[:-11],
        }

    def images(self, page):
        path = text.extr(page, 'class="picbox"><a target="_blank" href="', '"')
        count = text.parse_int(text.extr(path, "-pics-", "-mirror"))
        page = self.request(self.root + path).text
        url = self.root + text.extr(page, '\n<a href="', '"')
        p1, _, p2 = url.partition("/image0")
        ufmt = p1 + "/image{:>05}" + p2[4:]
        return [(ufmt.format(num), None) for num in range(1, count + 1)]

    def images_v2(self, page):
        results = []

        while True:
            for path in text.extract_iter(
                    page, ' class="picbox"><a target="_blank" href="', '"'):
                results.append(("{}/showimage/{}/zzup.com.jpg".format(
                    self.root, "/".join(path.split("/")[2:-2])), None))

            pos = page.find("glyphicon-arrow-right")
            if pos < 0:
                break
            path = text.rextract(page, ' href="', '"', pos)[0]
            page = self.request(text.urljoin(self.gallery_url, path)).text

        return results