From 5c9f2780f773be15e9d67f4e1b7bcbebabbc6f03 Mon Sep 17 00:00:00 2001 From: Jules-WinnfieldX Date: Mon, 8 Apr 2024 11:04:33 -0600 Subject: [PATCH] add mime_type checking for pixeldrain in event of noextensionfailure --- cyberdrop_dl/__init__.py | 2 +- .../scraper/crawlers/pixeldrain_crawler.py | 17 +++++++++++++++-- pyproject.toml | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.py index 21b8279c5..3e08c3827 100644 --- a/cyberdrop_dl/__init__.py +++ b/cyberdrop_dl/__init__.py @@ -1 +1 @@ -__version__ = "5.2.19" +__version__ = "5.2.21" diff --git a/cyberdrop_dl/scraper/crawlers/pixeldrain_crawler.py b/cyberdrop_dl/scraper/crawlers/pixeldrain_crawler.py index 6490c85f1..ace652db6 100644 --- a/cyberdrop_dl/scraper/crawlers/pixeldrain_crawler.py +++ b/cyberdrop_dl/scraper/crawlers/pixeldrain_crawler.py @@ -7,6 +7,7 @@ from aiolimiter import AsyncLimiter from yarl import URL +from cyberdrop_dl.clients.errors import NoExtensionFailure from cyberdrop_dl.scraper.crawler import Crawler from cyberdrop_dl.utils.dataclasses.url_objects import ScrapeItem from cyberdrop_dl.utils.utilities import error_handling_wrapper, get_filename_and_ext @@ -48,7 +49,13 @@ async def folder(self, scrape_item: ScrapeItem) -> None: for file in JSON_Resp['files']: link = await self.create_download_link(file['id']) date = await self.parse_datetime(file['date_upload'].replace("T", " ").split(".")[0].strip("Z")) - filename, ext = await get_filename_and_ext(file['name']) + try: + filename, ext = await get_filename_and_ext(JSON_Resp['name']) + except NoExtensionFailure: + if "image" or "video" in file["mime_type"]: + filename, ext = await get_filename_and_ext(JSON_Resp['name'] + "." + file["mime_type"].split("/")[-1]) + else: + raise NoExtensionFailure new_scrape_item = await self.create_scrape_item(scrape_item, link, title, True, None, date) if not await self.check_album_results(link, results): await self.handle_file(link, new_scrape_item, filename, ext) @@ -61,7 +68,13 @@ async def file(self, scrape_item: ScrapeItem) -> None: link = await self.create_download_link(JSON_Resp['id']) date = await self.parse_datetime(JSON_Resp['date_upload'].replace("T", " ").split(".")[0]) - filename, ext = await get_filename_and_ext(JSON_Resp['name']) + try: + filename, ext = await get_filename_and_ext(JSON_Resp['name']) + except NoExtensionFailure: + if "image" or "video" in JSON_Resp["mime_type"]: + filename, ext = await get_filename_and_ext(JSON_Resp['name'] + "." + JSON_Resp["mime_type"].split("/")[-1]) + else: + raise NoExtensionFailure new_scrape_item = await self.create_scrape_item(scrape_item, link, "", False, None, date) await self.handle_file(link, new_scrape_item, filename, ext) diff --git a/pyproject.toml b/pyproject.toml index 622ed67af..c5d8a739b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cyberdrop-dl" -version = "5.2.19" +version = "5.2.21" description = "Bulk downloader for multiple file hosts" authors = ["Jules Winnfield "] readme = "README.md"