Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: unify chevereto-like thumb to src

NTFSvolume26b4687a4ed6
diff --git a/cyberdrop_dl/crawlers/_chevereto.py b/cyberdrop_dl/crawlers/_chevereto.py
index 5d9163a02..cdb81efee 100644
--- a/cyberdrop_dl/crawlers/_chevereto.py
+++ b/cyberdrop_dl/crawlers/_chevereto.py
@@ -84,11 +84,13 @@ class CheveretoCrawler(Crawler, is_generic=True):
@final
@staticmethod
- def _thumbnail_to_src(url: AbsoluteHttpURL) -> AbsoluteHttpURL:
+ def thumb_to_src(url: AbsoluteHttpURL) -> AbsoluteHttpURL:
new_name = url.name
for trash in (".md.", ".th.", ".fr."):
- new_name = new_name.replace(trash, ".")
- return url.with_name(new_name)
+ new_name = new_name.replace(trash, ".", 1)
+ if new_name != url.name:
+ return url.with_name(new_name)
+ return url
@classmethod
def transform_url(cls, url: AbsoluteHttpURL) -> AbsoluteHttpURL:
@@ -185,7 +187,7 @@ class CheveretoCrawler(Crawler, is_generic=True):
async def direct_file(
self, scrape_item: ScrapeItem, /, url: AbsoluteHttpURL | None = None, assume_ext: str | None = None
) -> None:
- link = self._thumbnail_to_src(url or scrape_item.url)
+ link = self.thumb_to_src(url or scrape_item.url)
await super().direct_file(scrape_item, link, assume_ext)
@error_handling_wrapper
diff --git a/cyberdrop_dl/crawlers/goonbox.py b/cyberdrop_dl/crawlers/goonbox.py
index 10ea1c686..fdca31c9a 100644
--- a/cyberdrop_dl/crawlers/goonbox.py
+++ b/cyberdrop_dl/crawlers/goonbox.py
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING, Any, ClassVar, Self
from cyberdrop_dl import aio
from cyberdrop_dl.crawlers import Registry
+from cyberdrop_dl.crawlers._chevereto import CheveretoCrawler
from cyberdrop_dl.crawlers.crawler import API, Crawler, SupportedDomains, SupportedPaths, auto_task_id
from cyberdrop_dl.url_objects import AbsoluteHttpURL
from cyberdrop_dl.utils import parse_url
@@ -60,7 +61,7 @@ class GoonBoxCrawler(Crawler):
def transform_url(cls, url: AbsoluteHttpURL) -> AbsoluteHttpURL:
url = super().transform_url(url)
if cls.is_subdomain(url):
- return _fix_cdn(_thumb_to_src(url))
+ return _fix_cdn(CheveretoCrawler.thumb_to_src(url))
match url.parts[1:]:
case ["a" | "img" as part, slug, *_]:
@@ -233,10 +234,3 @@ def _fix_cdn(url: AbsoluteHttpURL) -> AbsoluteHttpURL:
def _id(slug: str) -> str:
return slug.rsplit(".", maxsplit=1)[-1]
-
-
-def _thumb_to_src(url: AbsoluteHttpURL) -> AbsoluteHttpURL:
- new_name = url.name
- for trash in (".md.", ".th.", ".fr."):
- new_name = new_name.replace(trash, ".", 1)
- return url.with_name(new_name)
diff --git a/cyberdrop_dl/crawlers/lensdump.py b/cyberdrop_dl/crawlers/lensdump.py
index b4221243e..936438270 100644
--- a/cyberdrop_dl/crawlers/lensdump.py
+++ b/cyberdrop_dl/crawlers/lensdump.py
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Any, ClassVar, Self, override
from cyberdrop_dl import aio
from cyberdrop_dl.clients import etag
+from cyberdrop_dl.crawlers._chevereto import CheveretoCrawler
from cyberdrop_dl.crawlers.crawler import API, Crawler, SupportedDomains, SupportedPaths, auto_task_id
from cyberdrop_dl.exceptions import DownloadError, ScrapeError
from cyberdrop_dl.url_objects import AbsoluteHttpURL
@@ -257,7 +258,7 @@ class LensDumpAPI(API):
async def album_files(self, album: FullAlbum) -> AsyncGenerator[File]:
url = self.ENTRYPOINT / "albums" / album.id / "files"
async for file in self._pager(url):
- file["src_url"] = _thumb_to_src(self.parse_url(file["preview"]))
+ file["src_url"] = CheveretoCrawler.thumb_to_src(self.parse_url(file["preview"]))
yield File.parse(file, album.owner)
async def album_tree(self, album_id: str) -> AriaTree:
@@ -305,10 +306,6 @@ class LensDumpAPI(API):
url = url.update_query(cursor=cursor)
-def _thumb_to_src(url: AbsoluteHttpURL) -> AbsoluteHttpURL:
- return url.with_name(url.name.replace(".th.", ".").replace(".md.", "."))
-
-
def _parse_aria_tree(html: str) -> AriaTree:
data = css.select_text(css.soup(html, parse_only="script"), "[type='application/json'][data-tree-data]")
tree = json.loads(data)