| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
"""Extractors for https://everia.club/""" |
| 8 |
|
| 9 |
from .common import Extractor, Message |
| 10 |
from .. import text |
| 11 |
|
| 12 |
BASE_PATTERN = r"(?:https?://)?everia\.club" |
| 13 |
|
| 14 |
|
| 15 |
class EveriaExtractor(Extractor): |
| 16 |
category = "everia" |
| 17 |
root = "https://everia.club" |
| 18 |
|
| 19 |
def items(self): |
| 20 |
data = {"_extractor": EveriaPostExtractor} |
| 21 |
for url in self.posts(): |
| 22 |
yield Message.Queue, url, data |
| 23 |
|
| 24 |
def posts(self): |
| 25 |
return self._pagination(self.groups[0]) |
| 26 |
|
| 27 |
def _pagination(self, path, params=None, pnum=1): |
| 28 |
find_posts = text.re(r'thumbnail">\s*<a href="([^"]+)').findall |
| 29 |
|
| 30 |
while True: |
| 31 |
if pnum == 1: |
| 32 |
url = f"{self.root}{path}/" |
| 33 |
else: |
| 34 |
url = f"{self.root}{path}/page/{pnum}/" |
| 35 |
response = self.request(url, params=params, allow_redirects=False) |
| 36 |
|
| 37 |
if response.status_code >= 300: |
| 38 |
return |
| 39 |
|
| 40 |
yield from find_posts(response.text) |
| 41 |
pnum += 1 |
| 42 |
|
| 43 |
|
| 44 |
class EveriaPostExtractor(EveriaExtractor): |
| 45 |
subcategory = "post" |
| 46 |
directory_fmt = ("{category}", "{title}") |
| 47 |
archive_fmt = "{post_url}_{num}" |
| 48 |
pattern = BASE_PATTERN + r"(/\d{4}/\d{2}/\d{2}/[^/?#]+)" |
| 49 |
example = "https://everia.club/0000/00/00/TITLE" |
| 50 |
|
| 51 |
def items(self): |
| 52 |
find_imgs = text.re(r'<img .*?(?:lazy-)?src="([^"]+)').findall |
| 53 |
|
| 54 |
url = self.root + self.groups[0] + "/" |
| 55 |
page = self.request(url).text |
| 56 |
|
| 57 |
data = { |
| 58 |
"title": text.unescape( |
| 59 |
text.extr(page, 'itemprop="headline">', "</h")), |
| 60 |
"tags": list(text.extract_iter(page, 'rel="tag">', "</a>")), |
| 61 |
"post_url": text.unquote(url), |
| 62 |
"post_category": text.extr( |
| 63 |
page, "post-in-category-", " ").capitalize(), |
| 64 |
} |
| 65 |
yield Message.Directory, "", data |
| 66 |
|
| 67 |
data["num"] = 0 |
| 68 |
pages = text.extract_iter(text.extr( |
| 69 |
page, '<div class="page-links', "</div>"), 'href="', '"') |
| 70 |
while True: |
| 71 |
content = text.extr(page, 'itemprop="text">', "</article") |
| 72 |
|
| 73 |
for url in find_imgs(content): |
| 74 |
data["num"] += 1 |
| 75 |
url = text.unquote(url) |
| 76 |
yield Message.Url, url, text.nameext_from_url(url, data) |
| 77 |
|
| 78 |
if not (url := next(pages, None)): |
| 79 |
break |
| 80 |
page = self.request(text.unescape(url)).text |
| 81 |
|
| 82 |
|
| 83 |
class EveriaTagExtractor(EveriaExtractor): |
| 84 |
subcategory = "tag" |
| 85 |
pattern = BASE_PATTERN + r"(/tag/[^/?#]+)" |
| 86 |
example = "https://everia.club/tag/TAG" |
| 87 |
|
| 88 |
|
| 89 |
class EveriaCategoryExtractor(EveriaExtractor): |
| 90 |
subcategory = "category" |
| 91 |
pattern = BASE_PATTERN + r"(/category/[^/?#]+)" |
| 92 |
example = "https://everia.club/category/CATEGORY" |
| 93 |
|
| 94 |
|
| 95 |
class EveriaDateExtractor(EveriaExtractor): |
| 96 |
subcategory = "date" |
| 97 |
pattern = (BASE_PATTERN + |
| 98 |
r"(/\d{4}(?:/\d{2})?(?:/\d{2})?)(?:/page/\d+)?/?$") |
| 99 |
example = "https://everia.club/0000/00/00" |
| 100 |
|
| 101 |
|
| 102 |
class EveriaSearchExtractor(EveriaExtractor): |
| 103 |
subcategory = "search" |
| 104 |
pattern = BASE_PATTERN + r"/(?:page/\d+/)?\?s=([^&#]+)" |
| 105 |
example = "https://everia.club/?s=SEARCH" |
| 106 |
|
| 107 |
def posts(self): |
| 108 |
params = {"s": self.groups[0]} |
| 109 |
return self._pagination("", params) |