aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/everia.py
blob: ce2980023dcb2329c4dae94f8f2dd5466124f290 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# -*- 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://everia.club"""

from .common import Extractor, Message
from .. import text

BASE_PATTERN = r"(?:https?://)?everia\.club"


class EveriaExtractor(Extractor):
    category = "everia"
    root = "https://everia.club"

    def items(self):
        data = {"_extractor": EveriaPostExtractor}
        for url in self.posts():
            yield Message.Queue, url, data

    def posts(self):
        return self._pagination(self.groups[0])

    def _pagination(self, path, params=None, pnum=1):
        find_posts = text.re(r'thumbnail">\s*<a href="([^"]+)').findall

        while True:
            if pnum == 1:
                url = f"{self.root}{path}/"
            else:
                url = f"{self.root}{path}/page/{pnum}/"
            response = self.request(url, params=params, allow_redirects=False)

            if response.status_code >= 300:
                return

            yield from find_posts(response.text)
            pnum += 1


class EveriaPostExtractor(EveriaExtractor):
    subcategory = "post"
    directory_fmt = ("{category}", "{title}")
    archive_fmt = "{post_url}_{num}"
    pattern = rf"{BASE_PATTERN}(/\d{{4}}/\d{{2}}/\d{{2}}/[^/?#]+)"
    example = "https://everia.club/0000/00/00/TITLE"

    def items(self):
        url = self.root + self.groups[0] + "/"
        page = self.request(url).text
        content = text.extr(page, 'itemprop="text">', "<h3")
        urls = text.re(r'img.*?lazy-src="([^"]+)').findall(content)

        data = {
            "title": text.unescape(
                text.extr(page, 'itemprop="headline">', "</h")),
            "tags": list(text.extract_iter(page, 'rel="tag">', "</a>")),
            "post_url": text.unquote(url),
            "post_category": text.extr(
                page, "post-in-category-", " ").capitalize(),
            "count": len(urls),
        }

        yield Message.Directory, "", data
        for data["num"], url in enumerate(urls, 1):
            url = text.unquote(url)
            yield Message.Url, url, text.nameext_from_url(url, data)


class EveriaTagExtractor(EveriaExtractor):
    subcategory = "tag"
    pattern = rf"{BASE_PATTERN}(/tag/[^/?#]+)"
    example = "https://everia.club/tag/TAG"


class EveriaCategoryExtractor(EveriaExtractor):
    subcategory = "category"
    pattern = rf"{BASE_PATTERN}(/category/[^/?#]+)"
    example = "https://everia.club/category/CATEGORY"


class EveriaDateExtractor(EveriaExtractor):
    subcategory = "date"
    pattern = (rf"{BASE_PATTERN}"
               rf"(/\d{{4}}(?:/\d{{2}})?(?:/\d{{2}})?)(?:/page/\d+)?/?$")
    example = "https://everia.club/0000/00/00"


class EveriaSearchExtractor(EveriaExtractor):
    subcategory = "search"
    pattern = rf"{BASE_PATTERN}/(?:page/\d+/)?\?s=([^&#]+)"
    example = "https://everia.club/?s=SEARCH"

    def posts(self):
        params = {"s": self.groups[0]}
        return self._pagination("", params)