Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
fix: handle deleted videos (TubeCorporate) (#59)
NTFSvolumebf0bfd31ba42
diff --git a/cyberdrop_dl/crawlers/_tubecorporate.py b/cyberdrop_dl/crawlers/_tubecorporate.pyindex 7820d51a6..1bad4736d 100644--- a/cyberdrop_dl/crawlers/_tubecorporate.py+++ b/cyberdrop_dl/crawlers/_tubecorporate.py@@ -1,7 +1,8 @@from __future__ import annotationsimport base64-from typing import TYPE_CHECKING, Any, ClassVar+import dataclasses+from typing import TYPE_CHECKING, Any, ClassVar, Finalfrom cyberdrop_dl.crawlers.crawler import Crawler, SupportedPathsfrom cyberdrop_dl.exceptions import ScrapeError@@ -10,6 +11,16 @@ from cyberdrop_dl.utils.utilities import error_handling_wrapperif TYPE_CHECKING:from cyberdrop_dl.data_structures.url_objects import AbsoluteHttpURL, ScrapeItem+_FORMATS: Final = "_sd.mp4", "_hq.mp4", "_hd.mp4", "_fhd.mp4"++[email protected](slots=True)+class Video:+ title: str+ thumb: AbsoluteHttpURL+ post_date: str+ src: AbsoluteHttpURL+class TubeCorporateCrawler(Crawler, is_abc=True):SUPPORTED_PATHS: ClassVar[SupportedPaths] = {@@ -18,6 +29,7 @@ class TubeCorporateCrawler(Crawler, is_abc=True):"/embed/<video_id>/...",)}+ # DEFAULT_TRIM_URLS: ClassVar[bool] = Falsedef __init_subclass__(cls, **kwargs: Any) -> None:domains = cls.PRIMARY_URL.host, *cls.SUPPORTED_DOMAINS@@ -29,7 +41,7 @@ class TubeCorporateCrawler(Crawler, is_abc=True):async def fetch(self, scrape_item: ScrapeItem) -> None:match scrape_item.url.parts[1:]:- case ["videos" | "embed", video_id, *_]:+ case ["videos" | "video" | "embed", video_id, *_]:return await self.video(scrape_item, video_id)case _:raise ValueError@@ -39,50 +51,81 @@ class TubeCorporateCrawler(Crawler, is_abc=True):if await self.check_complete_from_referer(scrape_item):return- api_url = self._get_api_url(scrape_item, video_id)- video = _choose_best_format(await self.request_json(api_url))- video_info = await self._get_video_info(scrape_item, video_id)- scrape_item.possible_datetime = self.parse_iso_date(video_info["post_date"])-- decoded_url = _decode_base64(video["video_url"])- link = self.parse_url(decoded_url, relative_to=scrape_item.url.origin(), trim=False)- filename, ext = self.get_filename_and_ext(video_id + ".mp4")- custom_filename = self.create_custom_filename(video_info["title"], ext, file_id=video_id)+ video = await self._request_video(scrape_item.url.origin(), video_id)+ scrape_item.possible_datetime = self.parse_iso_date(video.post_date)+ ext = ".mp4"+ custom_filename = self.create_custom_filename(video.title, ext, file_id=video_id)return await self.handle_file(scrape_item.url,scrape_item,- filename,+ video.title,ext,custom_filename=custom_filename,- debrid_link=link,- metadata=video_info,+ debrid_link=video.src,+ metadata=video,+ referer=scrape_item.url.with_host(video.src.host),+ )++ async def _request_video(self, origin: AbsoluteHttpURL, video_id: str) -> Video:+ async with self.request(+ (origin / "api/videofile.php").with_query(+ video_id=video_id,+ lifetime=8_640_000,+ )+ ) as resp:+ origin = resp.url.origin() # May have been a redirect. We need the real origin as referer+ src = _select_best_src(_parse_formats(await resp.json()))++ mil_index = int(1e6 * (int(video_id) // 1e6))+ k_index = 1_000 * (int(video_id) // 1_000)+ lifetime = 86_400++ info_url = origin / f"api/json/video/{lifetime}/{mil_index}/{k_index}/{video_id}.json"++ video: dict[str, Any] = (await self.request_json(info_url))["video"]++ return Video(+ title=video["title"],+ thumb=self.parse_url(video["thumbsrc"]),+ post_date=video["post_date"],+ src=self.parse_url(src, origin, trim=False),)- async def _get_video_info(self, scrape_item: ScrapeItem, video_id: str) -> dict[str, str]:- json_url = self._get_json_url(scrape_item, video_id)- video_info: dict[str, dict[str, str]] = await self.request_json(json_url)- return video_info["video"]- def _get_json_url(self, scrape_item: ScrapeItem, video_id: str) -> AbsoluteHttpURL:- slug = f"{int(1e6 * (int(video_id) // 1e6))}/{1000 * (int(video_id) // 1000)}"- return scrape_item.url.with_path(f"api/json/video/86400/{slug}/{video_id}.json")+def _parse_formats(formats: list[dict[str, str]] | dict[str, str]) -> list[dict[str, str]]:+ if isinstance(formats, list):+ return formats++ if formats.get("error"):+ error = formats["msg"]+ if "not_found" in error:+ error = 404+ elif "private" in error:+ error = 403++ raise ScrapeError(error)++ raise ScrapeError(422, f"Expected list response, got {formats = !r}")- def _get_api_url(self, scrape_item: ScrapeItem, video_id: str) -> AbsoluteHttpURL:- query = {"video_id": video_id, "lifetime": "8640000"}- return scrape_item.url.with_path("api/videofile.php").with_query(query)+def _select_best_src(formats: list[dict[str, str]]) -> str:+ if len(formats) == 1:+ best = formats[0]+ else:+ try:+ best = max(formats, key=lambda f: _FORMATS.index(f["format"]))+ except ValueError:+ unknown = tuple(name for f in formats if (name := f["format"]) not in _FORMATS)+ raise ScrapeError(422, f"Video has unknown formats: {unknown}") from None-def _choose_best_format(formats: list[dict[str, str]]) -> dict[str, str]:- if len(formats) > 1:- raise ScrapeError(422, "More than one format found")- return formats[0]+ return _decode_url(best["video_url"])-def _decode_base64(text: str) -> str:+def _decode_url(url: str) -> str:return base64.b64decode(- text.translate(- text.maketrans(+ url.translate(+ str.maketrans({"\u0405": "S","\u0406": "I",diff --git a/cyberdrop_dl/crawlers/vidara.py b/cyberdrop_dl/crawlers/vidara.pyindex f3cef8722..e148e928e 100644--- a/cyberdrop_dl/crawlers/vidara.py+++ b/cyberdrop_dl/crawlers/vidara.py@@ -16,6 +16,7 @@ class VidaraCrawler(Crawler):DOMAIN: ClassVar[str] = "vidara"PRIMARY_URL: ClassVar[AbsoluteHttpURL] = AbsoluteHttpURL("https://vidara.to")create_db_path = staticmethod(DBPathBuilder.path_qs_frag)+ _DOWNLOAD_SLOTS: ClassVar[int | None] = 2async def fetch(self, scrape_item: ScrapeItem) -> None:match scrape_item.url.parts[1:]:diff --git a/tests/crawlers/test_cases/fuxxx.py b/tests/crawlers/test_cases/fuxxx.pyindex b84799334..cc48ee6c1 100644--- a/tests/crawlers/test_cases/fuxxx.py+++ b/tests/crawlers/test_cases/fuxxx.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Meets Majiik - Sweeet Vee [1675249].mp4","referer": "https://fuxxx.com/videos/1675249/meets-majiik-sweeet-vee","download_folder": r"re:Loose Files (FuXXX)",- "datetime": 1756107098,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/hclips.py b/tests/crawlers/test_cases/hclips.pyindex fb122c3df..624c59033 100644--- a/tests/crawlers/test_cases/hclips.py+++ b/tests/crawlers/test_cases/hclips.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Dark chocolate gal teases great ass and flashes puffy tits [7410809].mp4","referer": "https://hclips.com/videos/7410809/dark-chocolate-gal-teases-great-ass-and-flashes-puffy-tits","download_folder": r"re:Loose Files (HClips)",- "datetime": 1582288202,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/hdzog.py b/tests/crawlers/test_cases/hdzog.pyindex 502712079..357533bcf 100644--- a/tests/crawlers/test_cases/hdzog.py+++ b/tests/crawlers/test_cases/hdzog.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Lesbian Sucking Big Natural Boobs 8 [874501].mp4","referer": "https://hdzog.com/videos/874501/lesbian-sucking-big-natural-boobs-8","download_folder": r"re:Loose Files (HDZog)",- "datetime": 1559367356,+ "datetime": int,}],),@@ -20,7 +20,6 @@ TEST_CASES = ["filename": "Horny Adult Clip Big Tits Unbelievable Will Enslaves Your Mind [2826355].mp4","referer": "https://hdzog.tube/videos/2826355/horny-adult-clip-big-tits-unbelievable-will-enslaves-your-mind","download_folder": r"re:Loose Files (HDZog)",- "datetime": 1709260272,}],),diff --git a/tests/crawlers/test_cases/hotmovs.py b/tests/crawlers/test_cases/hotmovs.pyindex cc9abc939..b0efbfd33 100644--- a/tests/crawlers/test_cases/hotmovs.py+++ b/tests/crawlers/test_cases/hotmovs.py@@ -6,21 +6,9 @@ TEST_CASES = [{"url": "https://hotmovs.com/videos/9741037/farewell-deep-kiss","filename": "Farewell Deep Kiss [9741037].mp4",- "referer": "https://hotmovs.com/videos/9741037/farewell-deep-kiss",+ "referer": "https://txxxporn.tube/videos/9741037/farewell-deep-kiss","download_folder": r"re:Loose Files \(HotMovs\)",- "datetime": 1612831801,- }- ],- ),- (- "https://hotmovs.tube/videos/11433543/the-river-ohana/",- [- {- "url": "https://hotmovs.tube/videos/11433543/the-river-ohana",- "filename": "The River - Ohana [11433543].mp4",- "referer": "https://hotmovs.tube/videos/11433543/the-river-ohana",- "download_folder": r"re:Loose Files \(HotMovs\)",- "datetime": 1689472937,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/inporn.py b/tests/crawlers/test_cases/inporn.pyindex 50fb14230..c76a3a4ca 100644--- a/tests/crawlers/test_cases/inporn.py+++ b/tests/crawlers/test_cases/inporn.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Stepson Fucked His Stepmom During A Storm [1979593].mp4","referer": "https://inporn.com/video/1979593/stepson-fucked-his-stepmom-during-a-storm","download_folder": r"re:Loose Files (InPorn)",- "datetime": 1733240381,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/pornzog.py b/tests/crawlers/test_cases/pornzog.pyindex bad0d951c..9a45f22a0 100644--- a/tests/crawlers/test_cases/pornzog.py+++ b/tests/crawlers/test_cases/pornzog.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Allison Hopwood Aka Ravenrose [7927427].mp4","referer": r"re:https://privatehomeclips.com/embed/7927427","download_folder": r"re:Loose Files \(HClips\)",- "datetime": 1630990922,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/tubepornclassic.py b/tests/crawlers/test_cases/tubepornclassic.pyindex d5b286618..d8bdd8c71 100644--- a/tests/crawlers/test_cases/tubepornclassic.py+++ b/tests/crawlers/test_cases/tubepornclassic.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Selen - Pomeriggio al Cinema (Remastered) [1076392].mp4","referer": "https://tubepornclassic.com/videos/1076392/selen-pomeriggio-al-cinema-remastered","download_folder": r"re:Loose Files (TubePornClassic)",- "datetime": 1591599001,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/txxx.py b/tests/crawlers/test_cases/txxx.pyindex f1e63f66c..d6f24f2c1 100644--- a/tests/crawlers/test_cases/txxx.py+++ b/tests/crawlers/test_cases/txxx.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Naughty Hitomi Okubo is cheating on her partner [8497861].mp4","referer": "https://txxx.com/videos/8497861/naughty-hitomi-okubo-is-cheating-on-her-partner","download_folder": r"re:Loose Files (TXXX)",- "datetime": 1557778709,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/upornia.py b/tests/crawlers/test_cases/upornia.pyindex 98da84dfb..2ea7d50f1 100644--- a/tests/crawlers/test_cases/upornia.py+++ b/tests/crawlers/test_cases/upornia.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Masturbating Each Others Pussies With Jade Kimiko And Syren Demer [6241829].mp4","referer": "https://upornia.com/videos/6241829/masturbating-each-others-pussies-with-jade-kimiko-and-syren-demer","download_folder": r"re:Loose Files (UPornia)",- "datetime": 1765697722,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/vjav.py b/tests/crawlers/test_cases/vjav.pyindex beb38974d..ed9372be7 100644--- a/tests/crawlers/test_cases/vjav.py+++ b/tests/crawlers/test_cases/vjav.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Huntb-645 Costume Part-time Job Is Erotic Cheerleader A [733791].mp4","referer": "https://vjav.com/videos/733791/huntb-645-costume-part-time-job-is-erotic-cheerleader-a","download_folder": r"re:Loose Files (VJav)",- "datetime": 1696791000,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/voyeurhit.py b/tests/crawlers/test_cases/voyeurhit.pyindex 814772573..5413ef370 100644--- a/tests/crawlers/test_cases/voyeurhit.py+++ b/tests/crawlers/test_cases/voyeurhit.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Nylon Panty Dance schoolgirls (18+) [328607].mp4","referer": "https://voyeurhit.com/videos/328607/nylon-panty-dance-schoolgirls","download_folder": r"re:Loose Files (VoyeurHit)",- "datetime": 1571730603,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/vxxx.py b/tests/crawlers/test_cases/vxxx.pyindex 7b93b1da3..abd572b62 100644--- a/tests/crawlers/test_cases/vxxx.py+++ b/tests/crawlers/test_cases/vxxx.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Ebony teen Romy Indy Has A Dirty Side And Wants Dick (18+) [235983].mp4","referer": "https://vxxx.com/video-235983","download_folder": r"re:Loose Files (VXXX)",- "datetime": 1638526705,+ "datetime": int,}],),diff --git a/tests/crawlers/test_cases/xmilf.py b/tests/crawlers/test_cases/xmilf.pyindex 856f534db..660762281 100644--- a/tests/crawlers/test_cases/xmilf.py+++ b/tests/crawlers/test_cases/xmilf.py@@ -8,7 +8,7 @@ TEST_CASES = ["filename": "Big Boob Stepmother Tries Porn [1561649].mp4","referer": "https://xmilf.com/video/1561649/big-boob-stepmother-tries-porn","download_folder": r"re:Loose Files (XMilf)",- "datetime": 1764172954,+ "datetime": int,}],),