From 6320f30379cd5e2065e4871250641b43d04898cf Mon Sep 17 00:00:00 2001 From: Nathan Thomas Date: Wed, 12 Mar 2025 11:30:30 -0700 Subject: [PATCH] Fix typing issues in SoundCloud client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix parameter names in get_downloadable to match parent class - Fix typing in _get_playlist responses: list[tuple[list[dict], int]] - Replace iterator logic with explicit for loop to extract tracks 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- streamrip/client/soundcloud.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/streamrip/client/soundcloud.py b/streamrip/client/soundcloud.py index f10ec7c..557e561 100644 --- a/streamrip/client/soundcloud.py +++ b/streamrip/client/soundcloud.py @@ -100,25 +100,26 @@ class SoundcloudClient(Client): item["id"] = self._get_custom_id(item) return [resp] - async def get_downloadable(self, item_info: str, _) -> SoundcloudDownloadable: + async def get_downloadable(self, item_id: str, quality: int = 0) -> SoundcloudDownloadable: # We have `get_metadata` overwrite the "id" field so that it contains # some extra information we need to download soundcloud tracks - # item_id is the soundcloud ID of the track + # item_id is the soundcloud ID of the track that contains + # additional info needed for download # download_url is either the url that points to an mp3 download or "" # if download_url == '_non_streamable' then we raise an exception - infos: list[str] = item_info.split("|") + infos: list[str] = item_id.split("|") logger.debug(f"{infos=}") assert len(infos) == 2, infos - item_id, download_info = infos - assert re.match(r"\d+", item_id) is not None + track_id, download_info = infos + assert re.match(r"\d+", track_id) is not None if download_info == self.NON_STREAMABLE: - raise NonStreamableError(item_info) + raise NonStreamableError(item_id) if download_info == self.ORIGINAL_DOWNLOAD: - resp_json, status = await self._api_request(f"tracks/{item_id}/download") + resp_json, status = await self._api_request(f"tracks/{track_id}/download") assert status == 200 return SoundcloudDownloadable( self.session, @@ -126,7 +127,7 @@ class SoundcloudClient(Client): ) if download_info == self.NOT_RESOLVED: - raise NotImplementedError(item_info) + raise NotImplementedError(item_id) # download_info contains mp3 stream url resp_json, status = await self._request(download_info) @@ -181,11 +182,15 @@ class SoundcloudClient(Client): ] # (list of track metadata, status code) - responses: list[tuple[list, int]] = await asyncio.gather(*requests) + responses: list[tuple[list[dict], int]] = await asyncio.gather(*requests) assert all(status == 200 for _, status in responses) - remaining_tracks = list(itertools.chain(*[resp for resp, _ in responses])) + # Extract all tracks from each response + remaining_tracks: list = [] + for resp, _ in responses: + # Add all tracks from this response + remaining_tracks.extend(resp) # Insert the new metadata into the original response track_map: dict[str, dict] = {track["id"]: track for track in remaining_tracks}