Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: add giphy support (#154)
NTFSvolume0de05ee102d0
diff --git a/.gitignore b/.gitignoreindex 6a55d8b00..fff8a6ad5 100644--- a/.gitignore+++ b/.gitignore@@ -7,6 +7,7 @@*.log*.profiling*.csv+*.jsonl.coverage.config.yamldebug_run.testdiff --git a/cyberdrop_dl/crawlers/giphy.py b/cyberdrop_dl/crawlers/giphy.pynew file mode 100644index 000000000..25e32a467--- /dev/null+++ b/cyberdrop_dl/crawlers/giphy.py@@ -0,0 +1,48 @@+from __future__ import annotations++from typing import TYPE_CHECKING, ClassVar++from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths+from cyberdrop_dl.data_structures.url_objects import AbsoluteHttpURL+from cyberdrop_dl.utils.utilities import error_handling_wrapper++if TYPE_CHECKING:+ from cyberdrop_dl.data_structures.url_objects import ScrapeItem+++class GiPhyCrawler(Crawler):+ SUPPORTED_PATHS: ClassVar[SupportedPaths] = {+ "Gif": "/gifs/<slug>-<gif-id>",+ "Direct Link": "https://media*.giphy.com/media/<gif_id>",+ }+ DOMAIN: ClassVar[str] = "giphy"+ PRIMARY_URL: ClassVar[AbsoluteHttpURL] = AbsoluteHttpURL("https://giphy.com")++ async def fetch(self, scrape_item: ScrapeItem) -> None:+ match scrape_item.url.parts[1:]:+ case ["gifs", slug]:+ gif_id = slug.rpartition("-")[-1]+ return await self.gif(scrape_item, gif_id)+ case _:+ raise ValueError++ @classmethod+ def transform_url(cls, url: AbsoluteHttpURL) -> AbsoluteHttpURL:+ url = super().transform_url(url)+ match url.parts[1:]:+ case ["media", *_, gif_id, _] if cls.is_subdomain(url):+ return cls.PRIMARY_URL / "gifs" / gif_id+ case _:+ return url++ @error_handling_wrapper+ async def gif(self, scrape_item: ScrapeItem, gif_id: str) -> None:+ if await self.check_complete_from_referer(scrape_item.url):+ return++ api_url = (self.PRIMARY_URL / "services/oembed").with_query(url=str(scrape_item.url))+ resp: dict[str, str] = await self.request_json(api_url)+ title = resp["title"].partition(f" by {resp['author_name']}")[0].removesuffix(" GIF")+ src = self.parse_url(resp["url"])+ filename = self.create_custom_filename(title, src.suffix, file_id=gif_id)+ await self.handle_file(src, scrape_item, resp["title"], src.suffix, custom_filename=filename)diff --git a/tests/crawlers/test_cases/giphy.py b/tests/crawlers/test_cases/giphy.pynew file mode 100644index 000000000..3e378e6d2--- /dev/null+++ b/tests/crawlers/test_cases/giphy.py@@ -0,0 +1,35 @@+DOMAIN = "giphy"+TEST_CASES = [+ (+ "https://giphy.com/gifs/grandma-grandmother-offline-granny-B3s64Jh73fIk7qYLB5",+ [+ {+ "url": "https://media2.giphy.com/media/B3s64Jh73fIk7qYLB5/giphy.gif",+ "filename": "Work Vintage [B3s64Jh73fIk7qYLB5].gif",+ "debrid_link": None,+ "original_filename": "Work Vintage GIF by Offline Granny! - Find & Share on GIPHY",+ "referer": "https://giphy.com/gifs/grandma-grandmother-offline-granny-B3s64Jh73fIk7qYLB5",+ "album_id": None,+ "uploaded_at": None,+ "download_folder": "re:Loose Files (Giphy)",+ }+ ],+ 1,+ ),+ (+ "https://media2.giphy.com/media/B3s64Jh73fIk7qYLB5/giphy.gif",+ [+ {+ "url": "https://media2.giphy.com/media/B3s64Jh73fIk7qYLB5/giphy.gif",+ "filename": "Work Vintage [B3s64Jh73fIk7qYLB5].gif",+ "debrid_link": None,+ "original_filename": "Work Vintage GIF by Offline Granny! - Find & Share on GIPHY",+ "referer": "https://giphy.com/gifs/B3s64Jh73fIk7qYLB5",+ "album_id": None,+ "uploaded_at": None,+ "download_folder": "re:Loose Files (Giphy)",+ }+ ],+ 1,+ ),+]