Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: define etags in crawlers

NTFSvolume881270ed46c4
diff --git a/cyberdrop_dl/clients/etag.py b/cyberdrop_dl/clients/etag.py
index d9b344bcb..c1bef5193 100644
--- a/cyberdrop_dl/clients/etag.py
+++ b/cyberdrop_dl/clients/etag.py
@@ -14,38 +14,22 @@ _ETAGS: dict[str, ETag] = {}
@dataclasses.dataclass(slots=True, frozen=True)
class ETag:
- domain: str
value: str
msg: str | None = None
error: int | str = HTTPStatus.NOT_FOUND
-
-for domain, params in {
- "Imgur": [("d835884373f4d6c8f24742ceabe74946", "Image has been removed")],
- "SimpCity": [("65b7753c-528a", "SC Scrape Image")],
- "PixHost": [("5c4fb843-ece", "PixHost Removed Image")],
- "eFukt": [
- ("637be5da-11d2b", "Video removed"),
- ("63a05f27-11d2b", "Video removed"),
- ("5a56b09d-1485eb", "Video removed"),
- ],
- "ImageVenue": [
- ("19fdf2cd6-383c-5a4cd5b6710ed", "Image not found"),
- ("383c-5a4cd5b6710ed", "Image not found"),
- ],
- "SendVid": [
- ("6ab3d9ed-8fb5", "temporarily unavailable", HTTPStatus.SERVICE_UNAVAILABLE),
- ("6ab3db3e-3d0a", "thumbnail temporarily unavailable", HTTPStatus.SERVICE_UNAVAILABLE),
- ],
-}.items():
- for param in params:
- new_etag = ETag(domain, *param)
- if old_tag := _ETAGS.get(new_etag.value):
- raise RuntimeError(f"Duplicated etag: {old_tag = }, {new_etag = }")
- _ETAGS[new_etag.value] = new_etag
+ def __post_init__(self) -> None:
+ object.__setattr__(self, "value", self.value.strip('"'))
def check(headers: Mapping[str, str]) -> None:
e_tag_value = headers.get("ETag", "").strip('"')
if e_tag := _ETAGS.get(e_tag_value):
raise DownloadError(e_tag.error, e_tag.msg)
+
+
+def register(*etags: ETag) -> None:
+ for new_etag in etags:
+ if old_tag := _ETAGS.get(new_etag.value):
+ raise RuntimeError(f"Duplicated etag: {old_tag = }, {new_etag = }")
+ _ETAGS[new_etag.value] = new_etag
diff --git a/cyberdrop_dl/crawlers/efukt.py b/cyberdrop_dl/crawlers/efukt.py
index 3808767bb..565171860 100644
--- a/cyberdrop_dl/crawlers/efukt.py
+++ b/cyberdrop_dl/crawlers/efukt.py
@@ -1,9 +1,11 @@
from __future__ import annotations
import dataclasses
+from http import HTTPStatus
from typing import TYPE_CHECKING, ClassVar, final
from cyberdrop_dl import aio
+from cyberdrop_dl.clients import etag
from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths, URLConfig
from cyberdrop_dl.url_objects import AbsoluteHttpURL
from cyberdrop_dl.utils import css, dates, parse_url
@@ -29,6 +31,13 @@ class Selector:
MEDIA = f"{_IMAGE}, {_VIDEO}"
+etag.register(
+ etag.ETag("637be5da-11d2b", "Video removed", HTTPStatus.GONE),
+ etag.ETag("63a05f27-11d2b", "Video removed", HTTPStatus.GONE),
+ etag.ETag("5a56b09d-1485eb", "Video removed", HTTPStatus.GONE),
+)
+
+
@URLConfig(allow_empty_path=True)
class EfuktCrawler(Crawler):
SUPPORTED_PATHS: ClassVar[SupportedPaths] = {
diff --git a/cyberdrop_dl/crawlers/imagevenue.py b/cyberdrop_dl/crawlers/imagevenue.py
index 59e2e72b5..bb108fd93 100644
--- a/cyberdrop_dl/crawlers/imagevenue.py
+++ b/cyberdrop_dl/crawlers/imagevenue.py
@@ -2,6 +2,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, ClassVar
+from cyberdrop_dl.clients import etag
from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths
from cyberdrop_dl.url_objects import AbsoluteHttpURL
from cyberdrop_dl.utils import css
@@ -13,6 +14,12 @@ if TYPE_CHECKING:
from cyberdrop_dl.url_objects import ScrapeItem
+etag.register(
+ etag.ETag("19fdf2cd6-383c-5a4cd5b6710ed", "Image not found"),
+ etag.ETag("383c-5a4cd5b6710ed", "Image not found"),
+)
+
+
class ImageVenueCrawler(Crawler):
SUPPORTED_PATHS: ClassVar[SupportedPaths] = {
"Image": (
diff --git a/cyberdrop_dl/crawlers/imgur.py b/cyberdrop_dl/crawlers/imgur.py
index 74c86b7de..97c5ca104 100644
--- a/cyberdrop_dl/crawlers/imgur.py
+++ b/cyberdrop_dl/crawlers/imgur.py
@@ -3,6 +3,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Any, ClassVar
from cyberdrop_dl.cache import disk_cached_method
+from cyberdrop_dl.clients import etag
from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths
from cyberdrop_dl.exceptions import ScrapeError
from cyberdrop_dl.url_objects import AbsoluteHttpURL
@@ -16,6 +17,9 @@ _API_ENTRYPOINT = AbsoluteHttpURL("https://api.imgur.com/3/")
_IMAGE_CDN = AbsoluteHttpURL("https://i.imgur.com")
+etag.register(etag.ETag("d835884373f4d6c8f24742ceabe74946", "Image has been removed"))
+
+
class ImgurCrawler(Crawler):
SUPPORTED_PATHS: ClassVar[SupportedPaths] = {
"Album": "/a/<album_id>",
diff --git a/cyberdrop_dl/crawlers/pixhost.py b/cyberdrop_dl/crawlers/pixhost.py
index bee31f5ec..22ce1e63a 100644
--- a/cyberdrop_dl/crawlers/pixhost.py
+++ b/cyberdrop_dl/crawlers/pixhost.py
@@ -2,6 +2,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, ClassVar, final
+from cyberdrop_dl.clients import etag
from cyberdrop_dl.crawlers import Registry
from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths
from cyberdrop_dl.url_objects import AbsoluteHttpURL
@@ -19,6 +20,9 @@ class Selector:
IMAGE = "img.image-img"
+etag.register(etag.ETag("5c4fb843-ece", "PixHost Removed Image"))
+
+
@Registry.database.fix_referer
class PixHostCrawler(Crawler):
SUPPORTED_PATHS: ClassVar[SupportedPaths] = {
diff --git a/cyberdrop_dl/crawlers/sendvid.py b/cyberdrop_dl/crawlers/sendvid.py
index cc835a36e..831579065 100644
--- a/cyberdrop_dl/crawlers/sendvid.py
+++ b/cyberdrop_dl/crawlers/sendvid.py
@@ -1,7 +1,9 @@
from __future__ import annotations
-from typing import TYPE_CHECKING, ClassVar, final
+from http import HTTPStatus
+from typing import TYPE_CHECKING, ClassVar, final, override
+from cyberdrop_dl.clients import etag
from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths
from cyberdrop_dl.exceptions import ScrapeError
from cyberdrop_dl.url_objects import AbsoluteHttpURL
@@ -19,6 +21,12 @@ class Selector:
TITLE = "p.video-title"
+etag.register(
+ etag.ETag("6ab3d9ed-8fb5", "temporarily unavailable", HTTPStatus.SERVICE_UNAVAILABLE),
+ etag.ETag("6ab3db3e-3d0a", "thumbnail temporarily unavailable", HTTPStatus.SERVICE_UNAVAILABLE),
+)
+
+
class SendVidCrawler(Crawler):
SUPPORTED_PATHS: ClassVar[SupportedPaths] = {
"Videos": "/<video_id>",
@@ -37,6 +45,7 @@ class SendVidCrawler(Crawler):
raise ValueError
@classmethod
+ @override
def transform_url(cls, url: AbsoluteHttpURL) -> AbsoluteHttpURL:
url = super().transform_url(url)
match url.parts[1:]:
diff --git a/cyberdrop_dl/crawlers/xenforo/simpcity.py b/cyberdrop_dl/crawlers/xenforo/simpcity.py
index 85cd0108f..7fe51ac88 100644
--- a/cyberdrop_dl/crawlers/xenforo/simpcity.py
+++ b/cyberdrop_dl/crawlers/xenforo/simpcity.py
@@ -2,11 +2,14 @@ from __future__ import annotations
from typing import ClassVar
+from cyberdrop_dl.clients import etag
from cyberdrop_dl.clients.http import HTTPConfig
from cyberdrop_dl.url_objects import AbsoluteHttpURL
from .xenforo import XenforoCrawler
+etag.register(etag.ETag("65b7753c-528a", "SC Scrape Image"))
+
@HTTPConfig(rate_limit=(1, 20))
class SimpCityCrawler(XenforoCrawler, is_debug=True):