From 24e70b956b2750f6413cbd3c6b76733900609f80 Mon Sep 17 00:00:00 2001 From: HornyQT <144567058+HornyQT@users.noreply.github.com> Date: Sat, 25 May 2024 14:44:34 +0200 Subject: [PATCH] [pixeldrain] add support for single file album download --- docs/supportedsites.md | 2 +- gallery_dl/extractor/pixeldrain.py | 31 ++++++++++++++++++++++-- test/results/pixeldrain.py | 39 ++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/docs/supportedsites.md b/docs/supportedsites.md index 7b32fe05..d0de7c56 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -652,7 +652,7 @@ Consider all listed sites to potentially be NSFW. pixeldrain https://pixeldrain.com/ - Albums, Files + Albums, Files, Singlefilefromalbums diff --git a/gallery_dl/extractor/pixeldrain.py b/gallery_dl/extractor/pixeldrain.py index 5cfdc43f..61113ebc 100644 --- a/gallery_dl/extractor/pixeldrain.py +++ b/gallery_dl/extractor/pixeldrain.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Mike Fährmann +# Copyright 2023-2024 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 @@ -53,13 +53,40 @@ 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+)$" example = "https://pixeldrain.com/l/abcdefgh" def __init__(self, match): diff --git a/test/results/pixeldrain.py b/test/results/pixeldrain.py index a0c41a93..6c6dbb3e 100644 --- a/test/results/pixeldrain.py +++ b/test/results/pixeldrain.py @@ -89,4 +89,43 @@ __tests__ = ( "mime_type" : str, }, +{ + "#url" : "https://pixeldrain.com/l/zQ7XpWfM#item=0", + "#category": ("", "pixeldrain", "singlefilefromalbums"), + "#class" : pixeldrain.PixeldrainSinglefilefromalbumsExtractor, + "#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, + }, +}, + )