Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
fix: update query hashes (Twitch) (#176)
NTFSvolume21a4f0b35996
diff --git a/cyberdrop_dl/crawlers/twitch.py b/cyberdrop_dl/crawlers/twitch.pyindex b27cb115f..1f987655b 100644--- a/cyberdrop_dl/crawlers/twitch.py+++ b/cyberdrop_dl/crawlers/twitch.py@@ -12,7 +12,7 @@ from cyberdrop_dl.url_objects import AbsoluteHttpURLfrom cyberdrop_dl.utils import error_handling_wrapper, parse_urlif TYPE_CHECKING:- from collections.abc import Generator+ from collections.abc import Generator, Mappingfrom cyberdrop_dl.url_objects import ScrapeItemfrom cyberdrop_dl.utils import m3u8@@ -68,20 +68,20 @@ class TwitchCrawler(Crawler):def __post_init__(self) -> None:self.api = TwitchAPI(self)- async def _get_m3u8(+ async def _request_m3u8(self,url: AbsoluteHttpURL,/,- headers: dict[str, str] | None = None,- media_type: Literal["video", "audio", "subtitles"] | None = None,+ headers: Mapping[str, str] | None = None,+ media_type: Literal["video", "audio", "subtitle"] | None = None,) -> m3u8.M3U8:- m3u8_obj = await super()._get_m3u8(url, headers=headers, media_type=media_type)+ m3u8_obj = await super()._request_m3u8(url, headers=headers, media_type=media_type)# Some formats are "hidden" unless the user is logged in (1080p+ resolutions)# We can extract and parse them manually, bypasing the logging requirement- for data in m3u8_obj.data.get("session_data", ()):- if data.get("data_id") == "com.amazon.ivs.unavailable-media":- unavailable_media = json.loads(base64.b64decode(data["value"]))+ for data in m3u8_obj.session_data:+ if data.data_id == "com.amazon.ivs.unavailable-media" and data.value:+ unavailable_media = json.loads(base64.b64decode(data.value))_parse_unavailable_media(m3u8_obj, unavailable_media)break@@ -145,9 +145,6 @@ class TwitchCrawler(Crawler):returnclip = await self.api.clip(slug)- if not clip:- raise ScrapeError(404)-title: str = clip.get("title") or "clip"scrape_item.uploaded_at = self.parse_iso_date(clip["createdAt"])access_token: dict[str, str] = clip["playbackAccessToken"]@@ -213,7 +210,10 @@ class TwitchAPI:},"45111672eea2e507f8ba44d101a61862f9c56b11dee09a15634cb75cb9b9084d",)- return resp["data"]["video"]+ video = resp["data"]["video"]+ if video is None:+ raise ScrapeError(404)+ return videoasync def collection(self, collection_id: str) -> dict[str, Any]:resp = await self._request(@@ -223,7 +223,10 @@ class TwitchAPI:},"016e1e4ccee0eb4698eb3bf1a04dc1c077fb746c78c82bac9a8f0289658fbd1a",)- return resp["data"]["collection"]+ col = resp["data"]["collection"]+ if col is None:+ raise ScrapeError(404)+ return colasync def clip(self, slug: str) -> dict[str, Any]:resp = await self._request(@@ -231,9 +234,12 @@ class TwitchAPI:{"slug": slug,},- "1844261bb449fa51e6167040311da4a7a5f1c34fe71c71a3e0c4f551bc30c698",+ "0a02bb974443b576f5579aab0fef1d4b7f44e58a8a256f0c5adfead0db70640f",)- return resp["data"]["clip"]+ clip = resp["data"]["clip"]+ if clip is None:+ raise ScrapeError(404)+ return clipasync def access_token(self, video_id: str) -> dict[str, str]:resp = await self._request(diff --git a/tests/crawlers/test_cases/twitch.py b/tests/crawlers/test_cases/twitch.pyindex 26f524321..06ebfd49f 100644--- a/tests/crawlers/test_cases/twitch.py+++ b/tests/crawlers/test_cases/twitch.py@@ -75,15 +75,6 @@ TEST_CASES = [}],),- ( # Unavailable media (4K)- "https://www.twitch.tv/videos/2662839277",- [- {- "url": "ANY",- "filename": "Hanging out! [2662839277][avc1][60fps][4K].mp4",- }- ],- ),("https://www.twitch.tv/collections/3d4MEgywDhcOUg?filter=collections",[