2022-06-30 16:27:44 +02:00
|
|
|
# -*- 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.
|
|
|
|
|
2023-09-03 15:03:47 +02:00
|
|
|
"""Extractors for https://jpg1.su/"""
|
2023-05-25 18:58:51 +02:00
|
|
|
|
2022-06-30 16:27:44 +02:00
|
|
|
from .common import Extractor, Message
|
|
|
|
from .. import text
|
|
|
|
|
2023-09-03 15:03:47 +02:00
|
|
|
BASE_PATTERN = r"(?:https?://)?jpe?g\d?\.(?:su|pet|fish(?:ing)?|church)"
|
2022-06-30 16:27:44 +02:00
|
|
|
|
|
|
|
|
2023-05-25 18:58:51 +02:00
|
|
|
class JpgfishExtractor(Extractor):
|
|
|
|
"""Base class for jpgfish extractors"""
|
|
|
|
category = "jpgfish"
|
2023-09-03 15:03:47 +02:00
|
|
|
root = "https://jpg1.su"
|
2022-08-26 12:28:19 +02:00
|
|
|
directory_fmt = ("{category}", "{user}", "{album}",)
|
2023-05-25 22:58:42 +02:00
|
|
|
archive_fmt = "{id}"
|
2022-06-30 16:27:44 +02:00
|
|
|
|
|
|
|
def _pagination(self, url):
|
2023-05-25 22:58:42 +02:00
|
|
|
while url:
|
2022-07-31 16:58:40 +02:00
|
|
|
page = self.request(url).text
|
|
|
|
|
2023-05-25 22:58:42 +02:00
|
|
|
for item in text.extract_iter(
|
|
|
|
page, '<div class="list-item-image ', 'image-container'):
|
|
|
|
yield text.extract(item, '<a href="', '"')[0]
|
|
|
|
|
|
|
|
url = text.extract(
|
|
|
|
page, '<a data-pagination="next" href="', '" ><')[0]
|
2022-06-30 16:27:44 +02:00
|
|
|
|
|
|
|
|
2023-05-25 18:58:51 +02:00
|
|
|
class JpgfishImageExtractor(JpgfishExtractor):
|
|
|
|
"""Extractor for jpgfish Images"""
|
2022-07-31 16:58:40 +02:00
|
|
|
subcategory = "image"
|
2023-05-25 22:58:42 +02:00
|
|
|
pattern = BASE_PATTERN + r"/img/((?:[^/?#]+\.)?(\w+))"
|
2022-07-31 16:58:40 +02:00
|
|
|
test = (
|
2023-09-03 15:03:47 +02:00
|
|
|
("https://jpg1.su/img/funnymeme.LecXGS", {
|
2023-05-25 22:58:42 +02:00
|
|
|
"pattern": r"https://simp3\.jpg\.church/images/funnymeme\.jpg",
|
|
|
|
"content": "098e5e9b17ad634358426e0ffd1c93871474d13c",
|
|
|
|
"keyword": {
|
|
|
|
"album": "",
|
|
|
|
"extension": "jpg",
|
|
|
|
"filename": "funnymeme",
|
|
|
|
"id": "LecXGS",
|
|
|
|
"url": "https://simp3.jpg.church/images/funnymeme.jpg",
|
|
|
|
"user": "exearco",
|
|
|
|
},
|
2022-08-26 12:28:19 +02:00
|
|
|
}),
|
2023-05-25 22:58:42 +02:00
|
|
|
("https://jpg.church/img/auCruA", {
|
2022-08-26 12:28:19 +02:00
|
|
|
"pattern": r"https://simp2\.jpg\.church/hannahowo_00457\.jpg",
|
2023-05-25 22:58:42 +02:00
|
|
|
"keyword": {"album": "401-500"},
|
2022-08-26 12:28:19 +02:00
|
|
|
}),
|
2023-09-03 15:03:47 +02:00
|
|
|
("https://jpeg.pet/img/funnymeme.LecXGS"),
|
2023-07-13 23:21:01 +02:00
|
|
|
("https://jpg.pet/img/funnymeme.LecXGS"),
|
2023-06-03 15:49:56 +02:00
|
|
|
("https://jpg.fishing/img/funnymeme.LecXGS"),
|
|
|
|
("https://jpg.fish/img/funnymeme.LecXGS"),
|
|
|
|
("https://jpg.church/img/funnymeme.LecXGS"),
|
2022-07-31 16:58:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2023-05-25 18:58:51 +02:00
|
|
|
JpgfishExtractor.__init__(self, match)
|
2023-05-25 22:58:42 +02:00
|
|
|
self.path, self.image_id = match.groups()
|
2022-07-31 16:58:40 +02:00
|
|
|
|
2022-08-26 12:28:19 +02:00
|
|
|
def items(self):
|
2023-05-25 22:58:42 +02:00
|
|
|
url = "{}/img/{}".format(self.root, self.path)
|
|
|
|
extr = text.extract_from(self.request(url).text)
|
|
|
|
|
|
|
|
image = {
|
|
|
|
"id" : self.image_id,
|
|
|
|
"url" : extr('<meta property="og:image" content="', '"'),
|
|
|
|
"album": text.extract(extr(
|
|
|
|
"Added to <a", "/a>"), ">", "<")[0] or "",
|
|
|
|
"user" : extr('username: "', '"'),
|
|
|
|
}
|
|
|
|
|
|
|
|
text.nameext_from_url(image["url"], image)
|
2022-08-26 12:28:19 +02:00
|
|
|
yield Message.Directory, image
|
|
|
|
yield Message.Url, image["url"], image
|
2022-07-31 16:58:40 +02:00
|
|
|
|
|
|
|
|
2023-05-25 18:58:51 +02:00
|
|
|
class JpgfishAlbumExtractor(JpgfishExtractor):
|
|
|
|
"""Extractor for jpgfish Albums"""
|
2022-07-31 16:58:40 +02:00
|
|
|
subcategory = "album"
|
|
|
|
pattern = BASE_PATTERN + r"/a(?:lbum)?/([^/?#]+)(/sub)?"
|
|
|
|
test = (
|
2023-09-03 15:03:47 +02:00
|
|
|
("https://jpg1.su/album/CDilP/?sort=date_desc&page=1", {
|
2022-07-31 16:58:40 +02:00
|
|
|
"count": 2,
|
|
|
|
}),
|
2023-06-03 15:49:56 +02:00
|
|
|
("https://jpg.fishing/a/gunggingnsk.N9OOI", {
|
2022-07-31 16:58:40 +02:00
|
|
|
"count": 114,
|
|
|
|
}),
|
2023-06-03 15:49:56 +02:00
|
|
|
("https://jpg.fish/a/101-200.aNJ6A/", {
|
2022-07-31 16:58:40 +02:00
|
|
|
"count": 100,
|
|
|
|
}),
|
|
|
|
("https://jpg.church/a/hannahowo.aNTdH/sub", {
|
|
|
|
"count": 606,
|
|
|
|
}),
|
2023-09-03 15:03:47 +02:00
|
|
|
("https://jpeg.pet/album/CDilP/?sort=date_desc&page=1"),
|
2023-07-13 23:21:01 +02:00
|
|
|
("https://jpg.pet/album/CDilP/?sort=date_desc&page=1"),
|
2022-07-31 16:58:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2023-05-25 18:58:51 +02:00
|
|
|
JpgfishExtractor.__init__(self, match)
|
2023-05-25 22:58:42 +02:00
|
|
|
self.album, self.sub_albums = match.groups()
|
2022-07-31 16:58:40 +02:00
|
|
|
|
2022-08-26 12:28:19 +02:00
|
|
|
def items(self):
|
2022-07-31 16:58:40 +02:00
|
|
|
url = "{}/a/{}".format(self.root, self.album)
|
2023-05-25 18:58:51 +02:00
|
|
|
data = {"_extractor": JpgfishImageExtractor}
|
2023-05-25 22:58:42 +02:00
|
|
|
|
|
|
|
if self.sub_albums:
|
|
|
|
albums = self._pagination(url + "/sub")
|
2022-07-31 16:58:40 +02:00
|
|
|
else:
|
2023-05-25 22:58:42 +02:00
|
|
|
albums = (url,)
|
|
|
|
|
|
|
|
for album in albums:
|
|
|
|
for image in self._pagination(album):
|
2022-08-26 12:28:19 +02:00
|
|
|
yield Message.Queue, image, data
|
2022-07-31 16:58:40 +02:00
|
|
|
|
|
|
|
|
2023-05-25 18:58:51 +02:00
|
|
|
class JpgfishUserExtractor(JpgfishExtractor):
|
|
|
|
"""Extractor for jpgfish Users"""
|
2022-06-30 16:27:44 +02:00
|
|
|
subcategory = "user"
|
2022-07-31 16:58:40 +02:00
|
|
|
pattern = BASE_PATTERN + r"/(?!img|a(?:lbum)?)([^/?#]+)(/albums)?"
|
|
|
|
test = (
|
2023-09-03 15:03:47 +02:00
|
|
|
("https://jpg1.su/exearco", {
|
2022-07-31 16:58:40 +02:00
|
|
|
"count": 3,
|
|
|
|
}),
|
|
|
|
("https://jpg.church/exearco/albums", {
|
|
|
|
"count": 1,
|
|
|
|
}),
|
2023-09-03 15:03:47 +02:00
|
|
|
("https://jpeg.pet/exearco"),
|
2023-07-13 23:21:01 +02:00
|
|
|
("https://jpg.pet/exearco"),
|
2023-06-03 15:49:56 +02:00
|
|
|
("https://jpg.fishing/exearco"),
|
|
|
|
("https://jpg.fish/exearco"),
|
|
|
|
("https://jpg.church/exearco"),
|
2022-07-31 16:58:40 +02:00
|
|
|
)
|
2022-06-30 16:27:44 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2023-05-25 18:58:51 +02:00
|
|
|
JpgfishExtractor.__init__(self, match)
|
2023-05-25 22:58:42 +02:00
|
|
|
self.user, self.albums = match.groups()
|
2022-06-30 16:27:44 +02:00
|
|
|
|
2022-07-31 16:58:40 +02:00
|
|
|
def items(self):
|
2022-06-30 16:27:44 +02:00
|
|
|
url = "{}/{}".format(self.root, self.user)
|
2023-05-25 22:58:42 +02:00
|
|
|
|
|
|
|
if self.albums:
|
2022-07-31 16:58:40 +02:00
|
|
|
url += "/albums"
|
2023-05-25 18:58:51 +02:00
|
|
|
data = {"_extractor": JpgfishAlbumExtractor}
|
2022-07-31 16:58:40 +02:00
|
|
|
else:
|
2023-05-25 18:58:51 +02:00
|
|
|
data = {"_extractor": JpgfishImageExtractor}
|
2023-05-25 22:58:42 +02:00
|
|
|
|
|
|
|
for url in self._pagination(url):
|
|
|
|
yield Message.Queue, url, data
|