Skip to content

Bulk asynchronous downloader for multiple file hosts

feat: add support for single file URLs (GoFile) (#1439)

NTFSvolumeaf0424f7d79e
diff --git a/cyberdrop_dl/crawlers/gofile.py b/cyberdrop_dl/crawlers/gofile.py
index 62958baae..319932525 100644
--- a/cyberdrop_dl/crawlers/gofile.py
+++ b/cyberdrop_dl/crawlers/gofile.py
@@ -86,6 +86,10 @@ class FolderResponse(Response):
class GoFileCrawler(Crawler):
SUPPORTED_PATHS: ClassVar[SupportedPaths] = {
"Folder / File": "/d/<content_id>",
+ "Direct link": (
+ "/download/<content_id>/<filename>",
+ "/download/web/<content_id>/<filename>",
+ ),
"**NOTE**": (
"Use `password` as a query param to download password protected folders",
"ex: https://gofile.io/d/ABC654?password=1234",
@@ -116,11 +120,22 @@ class GoFileCrawler(Crawler):
match scrape_item.url.parts[1:]:
case ["d", content_id]:
return await self.folder(scrape_item, content_id)
+ case ["download", "web", file_id, _]:
+ return await self.single_file(scrape_item, file_id)
+ case ["download", file_id, _]:
+ return await self.single_file(scrape_item, file_id)
case _:
raise ValueError
@error_handling_wrapper
- async def folder(self, scrape_item: ScrapeItem, content_id: str) -> None:
+ async def single_file(self, scrape_item: ScrapeItem, file_id: str) -> None:
+ url = await self._get_redirect_url(scrape_item.url)
+ scrape_item.url = url.with_fragment(file_id)
+ assert "d" in url.parts
+ return await self.folder(scrape_item, url.name, file_id)
+
+ @error_handling_wrapper
+ async def folder(self, scrape_item: ScrapeItem, content_id: str, single_file_id: str | None = None) -> None:
is_first_page: bool = True
async for folder in self._folder_pager(content_id, scrape_item.url.query.get("password")):
@@ -138,7 +153,15 @@ class GoFileCrawler(Crawler):
scrape_item.url = scrape_item.url.with_query(None)
is_first_page = False
- self._handle_children(scrape_item, folder["children"])
+ children = folder["children"]
+ if single_file_id:
+ file = children.get(single_file_id)
+ if not file:
+ continue
+
+ children = {single_file_id: file}
+
+ self._handle_children(scrape_item, children)
def _handle_children(self, scrape_item: ScrapeItem, children: dict[str, Node]) -> None:
def get_website_url(node: Node) -> AbsoluteHttpURL:
diff --git a/tests/crawlers/test_cases/gofile.py b/tests/crawlers/test_cases/gofile.py
index 8042d638b..10fb651ce 100644
--- a/tests/crawlers/test_cases/gofile.py
+++ b/tests/crawlers/test_cases/gofile.py
@@ -23,15 +23,7 @@ TEST_CASES = [
"referer": "https://gofile.io/d/0272Cc#386c2d54-548a-4fd1-abde-6f7c91b25a5d",
"album_id": "0272Cc",
"datetime": 1759603311,
- },
- {
- "url": "ANY",
- "filename": "Boeboe - Drift (Bass Boosted).mp4",
- "download_folder": r"re:CDL_test \(GoFile\)/folder_B",
- "referer": "https://gofile.io/d/OP2VyC#229e787c-22e2-4f77-90a5-eb9802788aad",
- "album_id": "OP2VyC",
- "datetime": 1759603323,
- },
+ }
],
),
("https://gofile.io/d/tZeyhP?password=wrong_password", []),
@@ -47,4 +39,17 @@ TEST_CASES = [
},
],
),
+ (
+ "https://store6.gofile.io/download/69b4c1e4-a80a-45d5-ad76-061e48105bd0/MORE_IN90.mp4",
+ [
+ {
+ "url": "https://store3.gofile.io/download/web/69b4c1e4-a80a-45d5-ad76-061e48105bd0/MORE_IN90.mp4",
+ "filename": "MORE_IN90.mp4",
+ "download_folder": r"re:01 \(GoFile\)",
+ "referer": "https://gofile.io/d/9d83784e-2be6-472c-909f-0377704cfde3#69b4c1e4-a80a-45d5-ad76-061e48105bd0",
+ "album_id": "9d83784e-2be6-472c-909f-0377704cfde3",
+ "datetime": 1701541586,
+ },
+ ],
+ ),
]