[PR #1524] [MERGED] fix: add fallback logic for CDN urls #1426

Closed
opened 2026-02-27 20:02:24 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/1524
Author: @lemon-sh
Created: 8/3/2025
Status: Merged
Merged: 8/8/2025
Merged by: @roderickvd

Base: devHead: cdnurl-fallback


📝 Commits (5)

  • cbd7dec fix: add fallback logic for CDN urls
  • 1750087 mention urls tried count in error, make error type mangling more clear
  • 4ea68fe update changelog
  • dc62125 add a 10 second timeout
  • 7817b50 accept TryInto instead of &str in stream_from_cdn

📊 Changes

4 files changed (+81 additions, -25 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 audio/src/fetch/mod.rs (+39 -18)
📝 core/src/cdn_url.rs (+29 -0)
📝 core/src/spclient.rs (+9 -7)

📄 Description

  • The solution here is to make CdnUrl return all non-expired URLs instead of just the first one. Then, in AudioFileStreaming all URLs are tried and the first working URL is selected for later use.
    • This means that the fallback logic is not implemented for following requests in AudioFileFetch::download_range, but that is also a synchronous function so implementing that would probably require an overhaul of the codebase anyway, unless I'm missing something.
      • This would only become an issue if the URL that worked for the first request stopped working for the following requests.
  • I tried minimizing API breakage, but it seems impossible to implement the fallback logic inside stream_from_cdn, as it is not async (it doesn't actually send the request), so I made it accept the singular URL instead of CdnUrl. It is the responsibility of the caller to implement URL fallback logic by inspecting the result of the streamer.
  • The main issue in this first version of the PR is that it's not impossible to use an arbitrary URL with stream_from_cdn anymore, but there are a few ways this could be fixed.
    • maybe adding a new type for the singular URLs, like SingleCdnUrl?
    • or adding a method to CdnUrl that would select the working URL and discard the rest?
Example log
[...]
[2025-08-03T16:49:40Z INFO  librespot_core::spclient] Resolved "gew4-spclient.spotify.com:443" as spclient access point
[2025-08-03T16:49:40Z INFO  librespot_connect::spirc] active device is <405ad53c8038c055e1b13c844c31f50d8bb4b136> with session <3b615ec204e9964c776ce57aa0896dac>
[2025-08-03T16:49:40Z WARN  librespot_connect::state::context] couldn't load context info because: context is not available. type: Default
[2025-08-03T16:49:40Z INFO  librespot_playback::player] Loading <No Fun> with Spotify URI <spotify:track:5ImCVtO1gvcD1ttdG5SrQT>
[2025-08-03T16:49:41Z WARN  librespot_audio::fetch] Fetching https://audio-akp.spotifycdn.com/audio/[...] failed with error Error { kind: Unavailable, error: hyper_util::client::legacy::Error(Connect, Custom { kind: Other, error: ConnectError("dns error", Os { code: 11001, kind: Uncategorized, message: "No such host is known." }) }) }, trying next
[2025-08-03T16:49:41Z INFO  librespot_playback::player] <No Fun> (411147 ms) loaded

Closes: #1521


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/librespot-org/librespot/pull/1524 **Author:** [@lemon-sh](https://github.com/lemon-sh) **Created:** 8/3/2025 **Status:** ✅ Merged **Merged:** 8/8/2025 **Merged by:** [@roderickvd](https://github.com/roderickvd) **Base:** `dev` ← **Head:** `cdnurl-fallback` --- ### 📝 Commits (5) - [`cbd7dec`](https://github.com/librespot-org/librespot/commit/cbd7decc6c00a78d50fe1d910b0cfe6a7f9d1b9e) fix: add fallback logic for CDN urls - [`1750087`](https://github.com/librespot-org/librespot/commit/1750087af25c027b092391b68d175242beb55522) mention urls tried count in error, make error type mangling more clear - [`4ea68fe`](https://github.com/librespot-org/librespot/commit/4ea68feb6767d6ec2988203291142e354af580a5) update changelog - [`dc62125`](https://github.com/librespot-org/librespot/commit/dc6212501936205c3bc3e8989de8b4771870510f) add a 10 second timeout - [`7817b50`](https://github.com/librespot-org/librespot/commit/7817b50d53f6ccaf60dfea6c5e6a86df30aa9272) accept TryInto<Uri> instead of &str in stream_from_cdn ### 📊 Changes **4 files changed** (+81 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `audio/src/fetch/mod.rs` (+39 -18) 📝 `core/src/cdn_url.rs` (+29 -0) 📝 `core/src/spclient.rs` (+9 -7) </details> ### 📄 Description - The solution here is to make `CdnUrl` return all non-expired URLs instead of just the first one. Then, in `AudioFileStreaming` all URLs are tried and the first working URL is selected for later use. - This means that the fallback logic is not implemented for following requests in `AudioFileFetch::download_range`, but that is also a synchronous function so implementing that would probably require an overhaul of the codebase anyway, unless I'm missing something. - This would only become an issue if the URL that worked for the first request stopped working for the following requests. - I tried minimizing API breakage, but it seems impossible to implement the fallback logic inside `stream_from_cdn`, as it is not async (it doesn't actually send the request), so I made it accept the singular URL instead of `CdnUrl`. It is the responsibility of the caller to implement URL fallback logic by inspecting the result of the streamer. - The main issue in this first version of the PR is that it's not impossible to use an arbitrary URL with `stream_from_cdn` anymore, but there are a few ways this could be fixed. - maybe adding a new type for the singular URLs, like `SingleCdnUrl`? - or adding a method to `CdnUrl` that would select the working URL and discard the rest? <details><summary>Example log</summary> ``` [...] [2025-08-03T16:49:40Z INFO librespot_core::spclient] Resolved "gew4-spclient.spotify.com:443" as spclient access point [2025-08-03T16:49:40Z INFO librespot_connect::spirc] active device is <405ad53c8038c055e1b13c844c31f50d8bb4b136> with session <3b615ec204e9964c776ce57aa0896dac> [2025-08-03T16:49:40Z WARN librespot_connect::state::context] couldn't load context info because: context is not available. type: Default [2025-08-03T16:49:40Z INFO librespot_playback::player] Loading <No Fun> with Spotify URI <spotify:track:5ImCVtO1gvcD1ttdG5SrQT> [2025-08-03T16:49:41Z WARN librespot_audio::fetch] Fetching https://audio-akp.spotifycdn.com/audio/[...] failed with error Error { kind: Unavailable, error: hyper_util::client::legacy::Error(Connect, Custom { kind: Other, error: ConnectError("dns error", Os { code: 11001, kind: Uncategorized, message: "No such host is known." }) }) }, trying next [2025-08-03T16:49:41Z INFO librespot_playback::player] <No Fun> (411147 ms) loaded ``` </details> Closes: #1521 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:02:24 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#1426
No description provided.