From a82a71c5b8f9d6ee55f77b2fa7eab8d44437f89d Mon Sep 17 00:00:00 2001 From: ghostdanser <5584730+sjbrownrigg@users.noreply.github.com> Date: Thu, 13 Aug 2026 12:18:01 +0100 Subject: [PATCH 1/5] Fix crash when Tidal returns 404 logger.warning("TIDAL: track not found", resp) passes an argument to a message with no format placeholder, so logging raises TypeError: not all arguments converted during string formatting as soon as the record is actually formatted. A 404 from the API -- an unavailable or region-restricted item, or a bad id -- therefore crashed with a traceback from inside logging instead of reporting the NonStreamableError on the next line. Add the placeholder and log the URL, which is the useful part. Co-Authored-By: Claude Opus 5 --- streamrip/client/tidal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamrip/client/tidal.py b/streamrip/client/tidal.py index 92455d20..fac8f46b 100644 --- a/streamrip/client/tidal.py +++ b/streamrip/client/tidal.py @@ -353,7 +353,7 @@ async def _api_request(self, path: str, params=None, base: str = BASE) -> dict: async with self.rate_limiter: async with self.session.get(f"{base}/{path}", params=params) as resp: if resp.status == 404: - logger.warning("TIDAL: track not found", resp) + logger.warning("TIDAL: item not found (404): %s", resp.url) raise NonStreamableError("TIDAL: Track not found") resp.raise_for_status() return await resp.json() From 6f2d5895d17336b106a5572f7e80384b5bc46d5e Mon Sep 17 00:00:00 2001 From: ghostdanser <5584730+sjbrownrigg@users.noreply.github.com> Date: Thu, 13 Aug 2026 12:25:51 +0100 Subject: [PATCH 2/5] Fix Tidal share links ending in /u Tidal's share sheet produces urls like https://tidal.com/album/152697662/u URL_REGEX takes the last path segment as the item id, which it has to do because Qobuz album urls look like //album//. So the trailing "/u" was parsed as the id, streamrip requested album "u", and the API returned 404. Strip that suffix before matching. It is specific to tidal.com urls, so Qobuz and Deezer paths are untouched. Combined with the 404 handler in the previous commit, the failure was particularly hard to diagnose: the id was silently wrong, and the 404 it caused crashed inside logging rather than reporting itself. Adds a regression test covering the /u, /u/ and /browse/.../u forms. Co-Authored-By: Claude Opus 5 --- streamrip/rip/parse_url.py | 7 +++++++ tests/test_parse_url.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/streamrip/rip/parse_url.py b/streamrip/rip/parse_url.py index bdfa0b03..172214ba 100644 --- a/streamrip/rip/parse_url.py +++ b/streamrip/rip/parse_url.py @@ -20,6 +20,7 @@ URL_REGEX = re.compile( r"https?://(?:www|open|play|listen)?\.?(qobuz|tidal|deezer)\.com?(?:(?:/(album|artist|track|playlist|video|label))|(?:\/[-\w]+?))+\/([-\w]+)", ) +TIDAL_SHARE_SUFFIX_REGEX = re.compile(r"^(https?://[^/]*tidal\.com/.+?)/u/?$") SOUNDCLOUD_URL_REGEX = re.compile(r"https://soundcloud.com/[-\w:/]+") LASTFM_URL_REGEX = re.compile(r"https://www.last.fm/user/\w+/playlists/\w+") QOBUZ_INTERPRETER_URL_REGEX = re.compile( @@ -54,6 +55,12 @@ async def into_pending( class GenericURL(URL): @classmethod def from_str(cls, url: str) -> URL | None: + # Tidal's share sheet produces links ending in "/u". URL_REGEX takes + # the last path segment as the item id -- it has to, because Qobuz + # album urls look like //album// -- so that suffix + # would be parsed as an id of "u" and the API would 404. + url = TIDAL_SHARE_SUFFIX_REGEX.sub(r"\1", url) + generic_url = URL_REGEX.match(url) if generic_url is None: return None diff --git a/tests/test_parse_url.py b/tests/test_parse_url.py index 9048cd64..87f67779 100644 --- a/tests/test_parse_url.py +++ b/tests/test_parse_url.py @@ -51,6 +51,28 @@ def test_tidal_track_url(self): self.assertEqual(groups[1], "track") # media_type self.assertEqual(groups[2], "3083287") # item_id + def test_tidal_share_url_with_u_suffix(self): + """Test that Tidal share links ending in /u parse to the real item id. + + The share sheet appends "/u", which would otherwise be taken as the + item id and 404 against the API. + """ + for url in ( + "https://tidal.com/album/152697662/u", + "https://tidal.com/album/152697662/u/", + "https://tidal.com/browse/album/152697662/u", + ): + with self.subTest(url=url): + result = parse_url(url) + + self.assertIsNotNone(result) + self.assertIsInstance(result, GenericURL) + self.assertEqual(result.source, "tidal") + + groups = result.match.groups() + self.assertEqual(groups[1], "album") # media_type + self.assertEqual(groups[2], "152697662") # item_id + def test_deezer_track_url(self): """Test that Deezer track URLs are matched correctly.""" url = "https://www.deezer.com/track/4195713" From 7bfef4c1168b719a549680001f3d6cbea4a66109 Mon Sep 17 00:00:00 2001 From: ghostdanser <5584730+sjbrownrigg@users.noreply.github.com> Date: Thu, 13 Aug 2026 12:30:29 +0100 Subject: [PATCH 3/5] Don't drop Tidal tracks that have no lyrics get_metadata() fetches lyrics for tracks, and the lyrics endpoint 404s for any track nobody has written lyrics for -- which is a lot of them. _api_request turns a 404 into NonStreamableError, but the lyrics fetch only caught TypeError, so that error escaped get_metadata(). PendingTrack.resolve() understandably treats a NonStreamableError from get_metadata() as "this track cannot be streamed" and skips it. The result was that a track was dropped from an album download for the sole reason that it had no lyrics: WARNING TIDAL: item not found (404): .../tracks/152697671/lyrics ERROR Track 152697671 not available for stream on tidal Catch NonStreamableError alongside TypeError. Lyrics are optional metadata and must not decide whether audio gets downloaded. Co-Authored-By: Claude Opus 5 --- streamrip/client/tidal.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/streamrip/client/tidal.py b/streamrip/client/tidal.py index fac8f46b..67084dba 100644 --- a/streamrip/client/tidal.py +++ b/streamrip/client/tidal.py @@ -124,7 +124,12 @@ async def get_metadata(self, item_id: str, media_type: str) -> dict: item["lyrics"] = resp.get("lyrics") or "" else: item["lyrics"] = resp.get("subtitles") or resp.get("lyrics") or "" - except TypeError as e: + except (NonStreamableError, TypeError) as e: + # Lyrics are optional. The endpoint 404s for any track that + # has none, which _api_request turns into NonStreamableError + # -- previously that escaped get_metadata() and the caller + # dropped the track as unstreamable, so a track was skipped + # for the sole reason that nobody had written lyrics for it. logger.warning(f"Failed to get lyrics for {item_id}: {e}") logger.debug(item) From cbb41d7034b32bdea232ab55e17e2f786571e033 Mon Sep 17 00:00:00 2001 From: ghostdanser <5584730+sjbrownrigg@users.noreply.github.com> Date: Thu, 13 Aug 2026 13:20:53 +0100 Subject: [PATCH 4/5] Don't warn about tracks that simply have no lyrics Most tracks have no lyrics, so the lyrics endpoint 404s constantly. That produced two warnings per track -- one from the 404 handler and one from the lyrics handler -- for something entirely normal: WARNING TIDAL: item not found (404): .../tracks/152697671/lyrics WARNING Failed to get lyrics for 152697671: TIDAL: Track not found "Not found" is the expected answer here, not a problem. Worse, the noise makes a real failure indistinguishable from the routine case. Add ItemNotFoundError, a subclass of NonStreamableError raised for 404 so existing handlers are unaffected, and let callers tell "does not exist" from "failed to fetch": - The 404 in _api_request now logs at debug. Callers that care report it themselves at the right level, so it was duplicated anyway. - A 404 fetching lyrics logs at debug: nothing was expected. - Any other lyrics failure still warns, because lyrics that should have been there and could not be fetched is worth knowing about. Verified against three tracks known to have no lyrics: no warning-level output at all, and a simulated non-404 lyrics failure still warns while leaving the track downloadable. Co-Authored-By: Claude Opus 5 --- streamrip/client/tidal.py | 20 ++++++++++++-------- streamrip/exceptions.py | 9 +++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/streamrip/client/tidal.py b/streamrip/client/tidal.py index 67084dba..7f175e91 100644 --- a/streamrip/client/tidal.py +++ b/streamrip/client/tidal.py @@ -9,7 +9,7 @@ import aiohttp from ..config import Config -from ..exceptions import NonStreamableError +from ..exceptions import ItemNotFoundError, NonStreamableError from .client import Client from .downloadable import TidalDownloadable @@ -124,12 +124,13 @@ async def get_metadata(self, item_id: str, media_type: str) -> dict: item["lyrics"] = resp.get("lyrics") or "" else: item["lyrics"] = resp.get("subtitles") or resp.get("lyrics") or "" + except ItemNotFoundError: + # Most tracks simply have no lyrics. That is the expected + # answer, not a problem worth reporting. + logger.debug("No lyrics available for track %s", item_id) except (NonStreamableError, TypeError) as e: - # Lyrics are optional. The endpoint 404s for any track that - # has none, which _api_request turns into NonStreamableError - # -- previously that escaped get_metadata() and the caller - # dropped the track as unstreamable, so a track was skipped - # for the sole reason that nobody had written lyrics for it. + # Lyrics that should have been there but could not be + # fetched -- worth knowing about. logger.warning(f"Failed to get lyrics for {item_id}: {e}") logger.debug(item) @@ -358,7 +359,10 @@ async def _api_request(self, path: str, params=None, base: str = BASE) -> dict: async with self.rate_limiter: async with self.session.get(f"{base}/{path}", params=params) as resp: if resp.status == 404: - logger.warning("TIDAL: item not found (404): %s", resp.url) - raise NonStreamableError("TIDAL: Track not found") + # Logged at debug, not warning: some callers ask for + # optional things (lyrics) where a 404 is the normal + # answer. Callers that do care log it themselves. + logger.debug("TIDAL: item not found (404): %s", resp.url) + raise ItemNotFoundError(f"TIDAL: item not found: {resp.url}") resp.raise_for_status() return await resp.json() diff --git a/streamrip/exceptions.py b/streamrip/exceptions.py index 687b1a14..e1c5d522 100644 --- a/streamrip/exceptions.py +++ b/streamrip/exceptions.py @@ -66,5 +66,14 @@ def print_msg(self, item) -> str: return " ".join(base_msg) +class ItemNotFoundError(NonStreamableError): + """The API returned 404 for an item. + + A subclass of NonStreamableError so existing handlers are unaffected, but + distinguishable for callers fetching something optional -- "this does not + exist" and "this failed to download" deserve different log levels. + """ + + class ConversionError(Exception): """ConversionError.""" From 38208a8ae8773fc31035d949027f19f31decd62b Mon Sep 17 00:00:00 2001 From: ghostdanser <5584730+sjbrownrigg@users.noreply.github.com> Date: Mon, 14 Sep 2026 09:43:01 +0100 Subject: [PATCH 5/5] Never let a failed lyrics fetch abort the track Lyrics are optional, but only a 404 from the lyrics endpoint was contained. Any other request failure -- the 401 in #959, a timeout, a 5xx -- escaped get_metadata() and failed the whole track, so an album could come back with nothing but cover.jpg. The lyrics block now also catches aiohttp.ClientError and asyncio.TimeoutError, logging a warning and carrying on without lyrics. A failure of the track request itself is unaffected and still raises. One side effect worth stating: a rate-limited (429) lyrics call now costs the lyrics rather than the track. --- streamrip/client/tidal.py | 11 ++++- tests/test_tidal_lyrics_failure.py | 72 ++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 tests/test_tidal_lyrics_failure.py diff --git a/streamrip/client/tidal.py b/streamrip/client/tidal.py index 7f175e91..c39f6a33 100644 --- a/streamrip/client/tidal.py +++ b/streamrip/client/tidal.py @@ -128,9 +128,16 @@ async def get_metadata(self, item_id: str, media_type: str) -> dict: # Most tracks simply have no lyrics. That is the expected # answer, not a problem worth reporting. logger.debug("No lyrics available for track %s", item_id) - except (NonStreamableError, TypeError) as e: + except ( + NonStreamableError, + TypeError, + aiohttp.ClientError, + asyncio.TimeoutError, + ) as e: # Lyrics that should have been there but could not be - # fetched -- worth knowing about. + # fetched -- worth knowing about, never worth the track. Any + # request failure counts: a 401 from the lyrics endpoint used + # to escape here and abort the whole download (#959). logger.warning(f"Failed to get lyrics for {item_id}: {e}") logger.debug(item) diff --git a/tests/test_tidal_lyrics_failure.py b/tests/test_tidal_lyrics_failure.py new file mode 100644 index 00000000..451a4a6c --- /dev/null +++ b/tests/test_tidal_lyrics_failure.py @@ -0,0 +1,72 @@ +"""Lyrics are optional: failing to fetch them must never cost the track. + +Issue #959: a 401 from the lyrics endpoint escaped get_metadata() and every +track in the album was reported as a download error, with only cover.jpg +written. A 404 was already contained; any other request failure was not. +""" + +import asyncio +from unittest.mock import AsyncMock, MagicMock + +import aiohttp +import pytest + +from streamrip.client.tidal import TidalClient +from streamrip.exceptions import ItemNotFoundError + +TRACK = {"id": 1, "title": "t", "album": {"id": 2}} + + +def _client(*, lyrics_error=None, track_error=None): + client = TidalClient.__new__(TidalClient) + client.global_config = MagicMock() + client.global_config.session.conversion.enabled = False + client.config = MagicMock() + + async def request(path, params=None, base=None): + if path.endswith("/lyrics"): + if lyrics_error: + raise lyrics_error + return {"lyrics": "la la"} + if track_error: + raise track_error + return dict(TRACK) + + client._api_request = AsyncMock(side_effect=request) + return client + + +def _http_error(status): + return aiohttp.ClientResponseError( + MagicMock(real_url="https://tidal.com/v1/tracks/1/lyrics"), + (), + status=status, + message="Unauthorized", + ) + + +@pytest.mark.asyncio +async def test_lyrics_401_does_not_abort_track(caplog): + item = await _client(lyrics_error=_http_error(401)).get_metadata("1", "track") + assert item["title"] == "t" + assert "Failed to get lyrics" in caplog.text + + +@pytest.mark.asyncio +async def test_lyrics_timeout_does_not_abort_track(): + item = await _client(lyrics_error=asyncio.TimeoutError()).get_metadata("1", "track") + assert item["title"] == "t" + + +@pytest.mark.asyncio +async def test_no_lyrics_is_still_quiet(caplog): + item = await _client(lyrics_error=ItemNotFoundError("x")).get_metadata("1", "track") + assert item["title"] == "t" + assert "Failed to get lyrics" not in caplog.text + + +@pytest.mark.asyncio +async def test_track_request_failure_still_raises(): + """Only the optional lyrics call is contained -- real failures still surface.""" + with pytest.raises(aiohttp.ClientResponseError): + await _client(track_error=_http_error(401)).get_metadata("1", "track")