[chevereto] add generic extractors (#4664)
- support jpgfish - support pixl.li / pixl.is (#3179, #4357)
This commit is contained in:
@@ -28,6 +28,7 @@ modules = [
|
||||
"blogger",
|
||||
"bunkr",
|
||||
"catbox",
|
||||
"chevereto",
|
||||
"comicvine",
|
||||
"cyberdrop",
|
||||
"danbooru",
|
||||
@@ -73,7 +74,6 @@ modules = [
|
||||
"issuu",
|
||||
"itaku",
|
||||
"itchio",
|
||||
"jpgfish",
|
||||
"jschan",
|
||||
"kabeuchi",
|
||||
"keenspot",
|
||||
|
||||
105
gallery_dl/extractor/chevereto.py
Normal file
105
gallery_dl/extractor/chevereto.py
Normal file
@@ -0,0 +1,105 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2023 Mike Fährmann
|
||||
#
|
||||
# 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 Chevereto galleries"""
|
||||
|
||||
from .common import BaseExtractor, Message
|
||||
from .. import text
|
||||
|
||||
|
||||
class CheveretoExtractor(BaseExtractor):
|
||||
"""Base class for chevereto extractors"""
|
||||
basecategory = "chevereto"
|
||||
directory_fmt = ("{category}", "{user}", "{album}",)
|
||||
archive_fmt = "{id}"
|
||||
|
||||
def __init__(self, match):
|
||||
BaseExtractor.__init__(self, match)
|
||||
self.path = match.group(match.lastindex)
|
||||
|
||||
def _pagination(self, url):
|
||||
while url:
|
||||
page = self.request(url).text
|
||||
|
||||
for item in text.extract_iter(
|
||||
page, '<div class="list-item-image ', 'image-container'):
|
||||
yield text.extr(item, '<a href="', '"')
|
||||
|
||||
url = text.extr(page, '<a data-pagination="next" href="', '" ><')
|
||||
|
||||
|
||||
BASE_PATTERN = CheveretoExtractor.update({
|
||||
"jpgfish": {
|
||||
"root": "https://jpg2.su",
|
||||
"pattern": r"jpe?g\d?\.(?:su|pet|fish(?:ing)?|church)",
|
||||
},
|
||||
"pixl": {
|
||||
"root": "https://pixl.li",
|
||||
"pattern": r"pixl\.(?:li|is)",
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
class CheveretoImageExtractor(CheveretoExtractor):
|
||||
"""Extractor for chevereto Images"""
|
||||
subcategory = "image"
|
||||
pattern = BASE_PATTERN + r"(/im(?:g|age)/[^/?#]+)"
|
||||
example = "https://jpg2.su/img/TITLE.ID"
|
||||
|
||||
def items(self):
|
||||
url = self.root + self.path
|
||||
extr = text.extract_from(self.request(url).text)
|
||||
|
||||
image = {
|
||||
"id" : self.path.rpartition(".")[2],
|
||||
"url" : extr('<meta property="og:image" content="', '"'),
|
||||
"album": text.extr(extr("Added to <a", "/a>"), ">", "<"),
|
||||
"user" : extr('username: "', '"'),
|
||||
}
|
||||
|
||||
text.nameext_from_url(image["url"], image)
|
||||
yield Message.Directory, image
|
||||
yield Message.Url, image["url"], image
|
||||
|
||||
|
||||
class CheveretoAlbumExtractor(CheveretoExtractor):
|
||||
"""Extractor for chevereto Albums"""
|
||||
subcategory = "album"
|
||||
pattern = BASE_PATTERN + r"(/a(?:lbum)?/[^/?#]+(?:/sub)?)"
|
||||
example = "https://jpg2.su/album/TITLE.ID"
|
||||
|
||||
def items(self):
|
||||
url = self.root + self.path
|
||||
data = {"_extractor": CheveretoImageExtractor}
|
||||
|
||||
if self.path.endswith("/sub"):
|
||||
albums = self._pagination(url)
|
||||
else:
|
||||
albums = (url,)
|
||||
|
||||
for album in albums:
|
||||
for image in self._pagination(album):
|
||||
yield Message.Queue, image, data
|
||||
|
||||
|
||||
class CheveretoUserExtractor(CheveretoExtractor):
|
||||
"""Extractor for chevereto Users"""
|
||||
subcategory = "user"
|
||||
pattern = BASE_PATTERN + r"(/(?!img|image|a(?:lbum)?)[^/?#]+(?:/albums)?)"
|
||||
example = "https://jpg2.su/USER"
|
||||
|
||||
def items(self):
|
||||
url = self.root + self.path
|
||||
|
||||
if self.path.endswith("/albums"):
|
||||
data = {"_extractor": CheveretoAlbumExtractor}
|
||||
else:
|
||||
data = {"_extractor": CheveretoImageExtractor}
|
||||
|
||||
for url in self._pagination(url):
|
||||
yield Message.Queue, url, data
|
||||
@@ -1,105 +0,0 @@
|
||||
# -*- 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://jpg1.su/"""
|
||||
|
||||
from .common import Extractor, Message
|
||||
from .. import text
|
||||
|
||||
BASE_PATTERN = r"(?:https?://)?jpe?g\d?\.(?:su|pet|fish(?:ing)?|church)"
|
||||
|
||||
|
||||
class JpgfishExtractor(Extractor):
|
||||
"""Base class for jpgfish extractors"""
|
||||
category = "jpgfish"
|
||||
root = "https://jpg1.su"
|
||||
directory_fmt = ("{category}", "{user}", "{album}",)
|
||||
archive_fmt = "{id}"
|
||||
|
||||
def _pagination(self, url):
|
||||
while url:
|
||||
page = self.request(url).text
|
||||
|
||||
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]
|
||||
|
||||
|
||||
class JpgfishImageExtractor(JpgfishExtractor):
|
||||
"""Extractor for jpgfish Images"""
|
||||
subcategory = "image"
|
||||
pattern = BASE_PATTERN + r"/img/((?:[^/?#]+\.)?(\w+))"
|
||||
example = "https://jpg1.su/img/TITLE.ID"
|
||||
|
||||
def __init__(self, match):
|
||||
JpgfishExtractor.__init__(self, match)
|
||||
self.path, self.image_id = match.groups()
|
||||
|
||||
def items(self):
|
||||
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)
|
||||
yield Message.Directory, image
|
||||
yield Message.Url, image["url"], image
|
||||
|
||||
|
||||
class JpgfishAlbumExtractor(JpgfishExtractor):
|
||||
"""Extractor for jpgfish Albums"""
|
||||
subcategory = "album"
|
||||
pattern = BASE_PATTERN + r"/a(?:lbum)?/([^/?#]+)(/sub)?"
|
||||
example = "https://jpg1.su/album/TITLE.ID"
|
||||
|
||||
def __init__(self, match):
|
||||
JpgfishExtractor.__init__(self, match)
|
||||
self.album, self.sub_albums = match.groups()
|
||||
|
||||
def items(self):
|
||||
url = "{}/a/{}".format(self.root, self.album)
|
||||
data = {"_extractor": JpgfishImageExtractor}
|
||||
|
||||
if self.sub_albums:
|
||||
albums = self._pagination(url + "/sub")
|
||||
else:
|
||||
albums = (url,)
|
||||
|
||||
for album in albums:
|
||||
for image in self._pagination(album):
|
||||
yield Message.Queue, image, data
|
||||
|
||||
|
||||
class JpgfishUserExtractor(JpgfishExtractor):
|
||||
"""Extractor for jpgfish Users"""
|
||||
subcategory = "user"
|
||||
pattern = BASE_PATTERN + r"/(?!img|a(?:lbum)?)([^/?#]+)(/albums)?"
|
||||
example = "https://jpg1.su/USER"
|
||||
|
||||
def __init__(self, match):
|
||||
JpgfishExtractor.__init__(self, match)
|
||||
self.user, self.albums = match.groups()
|
||||
|
||||
def items(self):
|
||||
url = "{}/{}".format(self.root, self.user)
|
||||
|
||||
if self.albums:
|
||||
url += "/albums"
|
||||
data = {"_extractor": JpgfishAlbumExtractor}
|
||||
else:
|
||||
data = {"_extractor": JpgfishImageExtractor}
|
||||
|
||||
for url in self._pagination(url):
|
||||
yield Message.Queue, url, data
|
||||
Reference in New Issue
Block a user