[pixeldrain] integrate into 'album' extractor

pull/5667/head
Mike Fährmann 4 months ago
parent 24e70b956b
commit 154a890399
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -652,7 +652,7 @@ Consider all listed sites to potentially be NSFW.
<tr>
<td>pixeldrain</td>
<td>https://pixeldrain.com/</td>
<td>Albums, Files, Singlefilefromalbums</td>
<td>Albums, Files</td>
<td></td>
</tr>
<tr>

@ -53,45 +53,19 @@ class PixeldrainFileExtractor(PixeldrainExtractor):
yield Message.Url, file["url"], file
class PixeldrainSinglefilefromalbumsExtractor(PixeldrainExtractor):
"""Extractor for pixeldrain file from albums"""
subcategory = "singlefilefromalbums"
filename_fmt = "{filename[:230]} ({id}).{extension}"
pattern = BASE_PATTERN + r"/(?:l)/(\w+)#item=(\d+)"
example = "https://pixeldrain.com/l/abcdefgh#item=0"
def __init__(self, match):
Extractor.__init__(self, match)
self.album_id = match.group(1)
self.file_number = int(match.group(2))
def items(self):
url = "{}/api/list/{}".format(self.root, self.album_id)
album = self.request(url).json()
file = album["files"][self.file_number]
file["url"] = "{}/api/file/{}?download".format(self.root, file["id"])
file["date"] = self.parse_datetime(file["date_upload"])
del album
text.nameext_from_url(file["name"], file)
yield Message.Directory, file
yield Message.Url, file["url"], file
class PixeldrainAlbumExtractor(PixeldrainExtractor):
"""Extractor for pixeldrain albums"""
subcategory = "album"
directory_fmt = ("{category}",
"{album[date]:%Y-%m-%d} {album[title]} ({album[id]})")
filename_fmt = "{num:>03} {filename[:230]} ({id}).{extension}"
pattern = BASE_PATTERN + r"/(?:l|api/list)/(\w+)$"
pattern = BASE_PATTERN + r"/(?:l|api/list)/(\w+)(?:#item=(\d+))?"
example = "https://pixeldrain.com/l/abcdefgh"
def __init__(self, match):
Extractor.__init__(self, match)
self.album_id = match.group(1)
self.file_index = match.group(2)
def items(self):
url = "{}/api/list/{}".format(self.root, self.album_id)
@ -101,11 +75,20 @@ class PixeldrainAlbumExtractor(PixeldrainExtractor):
album["count"] = album["file_count"]
album["date"] = self.parse_datetime(album["date_created"])
if self.file_index:
idx = text.parse_int(self.file_index)
try:
files = (files[idx],)
except LookupError:
files = ()
else:
idx = 0
del album["files"]
del album["file_count"]
yield Message.Directory, {"album": album}
for num, file in enumerate(files, 1):
for num, file in enumerate(files, idx+1):
file["album"] = album
file["num"] = num
file["url"] = url = "{}/api/file/{}?download".format(

@ -91,41 +91,10 @@ __tests__ = (
{
"#url" : "https://pixeldrain.com/l/zQ7XpWfM#item=0",
"#category": ("", "pixeldrain", "singlefilefromalbums"),
"#class" : pixeldrain.PixeldrainSinglefilefromalbumsExtractor,
"#category": ("", "pixeldrain", "album"),
"#class" : pixeldrain.PixeldrainAlbumExtractor,
"#urls" : "https://pixeldrain.com/api/file/jW9E6s4h?download",
"#sha1_content": "0c8768055e4e20e7c7259608b67799171b691140",
"file" : {
"abuse_reporter_name" : "",
"abuse_type" : "",
"allow_video_player" : True,
"availability" : "",
"availability_message": "",
"bandwidth_used" : int,
"bandwidth_used_paid" : 0,
"can_download" : True,
"can_edit" : False,
"date" : "dt:2023-11-22 16:33:27",
"date_last_view" : r"re:\d+-\d+-\d+T\d+:\d+:\d+\.\d+Z",
"date_upload" : "2023-11-22T16:33:27.744Z",
"delete_after_date" : "0001-01-01T00:00:00Z",
"delete_after_downloads": 0,
"download_speed_limit": 0,
"downloads" : int,
"extension" : "png",
"filename" : "test-テスト-\"&>",
"hash_sha256" : "eb359cd8f02a7d6762f9863798297ff6a22569c5c87a9d38c55bdb3a3e26003f",
"id" : "jW9E6s4h",
"mime_type" : "image/png",
"name" : "test-テスト-\"&>.png",
"show_ads" : True,
"size" : 182,
"success" : True,
"thumbnail_href" : "/file/jW9E6s4h/thumbnail",
"url" : "https://pixeldrain.com/api/file/jW9E6s4h?download",
"views" : int,
},
},
)

Loading…
Cancel
Save