[PR #1538] [MERGED] refactor: Introduce SpotifyUri struct #1432

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

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/1538
Author: @SapiensAnatis
Created: 8/14/2025
Status: Merged
Merged: 9/11/2025
Merged by: @photovoltex

Base: devHead: chore/uri-refactor


📝 Commits (10+)

  • fea16c2 refactor: Introduce SpotifyUri struct
  • 569e3f0 fix: Don't pass unknown URIs from deprecated player methods
  • aaa970f refactor: remove SpotifyUri::to_base16
  • c16310c refactor: Store original data in SpotifyUri::Unknown
  • 4b7a1d7 refactor: Remove SpotifyItemType
  • 46d3eb9 refactor: Address review feedback
  • 5224eae test: Add more SpotifyUri tests
  • ff7ddcd chore: Correctly mark changes as breaking in CHANGELOG.md
  • 501697c refactor: Respond to review feedback
  • 1a25fb1 chore: Changelog updates

📊 Changes

23 files changed (+937 additions, -625 deletions)

View changed files

📝 CHANGELOG.md (+25 -0)
📝 connect/src/spirc.rs (+4 -4)
📝 connect/src/state/context.rs (+5 -3)
📝 connect/src/state/tracks.rs (+4 -4)
📝 core/src/lib.rs (+2 -0)
📝 core/src/spclient.rs (+3 -3)
📝 core/src/spotify_id.rs (+23 -405)
core/src/spotify_uri.rs (+583 -0)
📝 examples/play.rs (+5 -6)
📝 examples/playlist_tracks.rs (+3 -2)
📝 metadata/src/album.rs (+11 -7)
📝 metadata/src/artist.rs (+14 -10)
📝 metadata/src/audio/item.rs (+14 -18)
📝 metadata/src/episode.rs (+10 -6)
📝 metadata/src/image.rs (+2 -2)
📝 metadata/src/lib.rs (+4 -4)
📝 metadata/src/playlist/annotation.rs (+20 -6)
📝 metadata/src/playlist/item.rs (+3 -3)
📝 metadata/src/playlist/list.rs (+25 -12)
📝 metadata/src/show.rs (+10 -6)

...and 3 more files

📄 Description

Contributes to #1266

Introduces a new SpotifyUri struct which is layered on top of the existing SpotifyId, but has the capability to support URIs that do not confirm to the canonical base62 encoded format. This allows it to describe URIs like spotify:local, spotify:genre and others that SpotifyId cannot represent.

Changed the internal player state to use these URIs as much as possible, such that the player could in the future accept a URI of the type spotify:local, as a means of laying the groundwork for local file support.


I know #1266 is not a very good issue for my first one on the project, but I would really like to implement local file support and it doesn't seem like that will be possible for the player to handle without hacks unless we change the way we store the track URI. This is because local files URIs are of the form spotify:local:{artist}:{album_title}:{track_title}:{duration_in_seconds} which cannot be represented under a u128 inside SpotifyId like the base62 names that all official tracks have.

I have opened this PR to show what the proposed refactor in #1266 would involve, particularly with regard to the breaking changes I have had to make. So there are probably some things that can be polished more and tests added, but I wanted to get some feedback on the overall direction first. If the proposed change is too radical I will not be offended if you decide to close this PR 🙂

p.s. I have put all the changelogs etc. as 0.7.0 but it sounds like that is coming soon so just to be clear I have no expectation of this making it into the upcoming release


🔄 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/1538 **Author:** [@SapiensAnatis](https://github.com/SapiensAnatis) **Created:** 8/14/2025 **Status:** ✅ Merged **Merged:** 9/11/2025 **Merged by:** [@photovoltex](https://github.com/photovoltex) **Base:** `dev` ← **Head:** `chore/uri-refactor` --- ### 📝 Commits (10+) - [`fea16c2`](https://github.com/librespot-org/librespot/commit/fea16c2f07798a232839ef669ffa5334890032d6) refactor: Introduce SpotifyUri struct - [`569e3f0`](https://github.com/librespot-org/librespot/commit/569e3f0f0cb47824a2c6d615bd977e74e82a86dd) fix: Don't pass unknown URIs from deprecated player methods - [`aaa970f`](https://github.com/librespot-org/librespot/commit/aaa970f778beefea294437bee388e73b3eab9528) refactor: remove SpotifyUri::to_base16 - [`c16310c`](https://github.com/librespot-org/librespot/commit/c16310cf83205cbba3f377f536ba0651a9c59397) refactor: Store original data in SpotifyUri::Unknown - [`4b7a1d7`](https://github.com/librespot-org/librespot/commit/4b7a1d7b516a1b6a8106bbafac741c741db703bb) refactor: Remove SpotifyItemType - [`46d3eb9`](https://github.com/librespot-org/librespot/commit/46d3eb92f8d160465fcb8bde43acc2443a4d650a) refactor: Address review feedback - [`5224eae`](https://github.com/librespot-org/librespot/commit/5224eaef6b0aca986558f3bb259734a9425ef9f5) test: Add more SpotifyUri tests - [`ff7ddcd`](https://github.com/librespot-org/librespot/commit/ff7ddcd3842c336e3fb050db61d2f59a485102c6) chore: Correctly mark changes as breaking in CHANGELOG.md - [`501697c`](https://github.com/librespot-org/librespot/commit/501697c7d4c695239ab893216f7f03006737dd95) refactor: Respond to review feedback - [`1a25fb1`](https://github.com/librespot-org/librespot/commit/1a25fb190fa6bb6019f3f44c5a34ab6a0a439fa5) chore: Changelog updates ### 📊 Changes **23 files changed** (+937 additions, -625 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+25 -0) 📝 `connect/src/spirc.rs` (+4 -4) 📝 `connect/src/state/context.rs` (+5 -3) 📝 `connect/src/state/tracks.rs` (+4 -4) 📝 `core/src/lib.rs` (+2 -0) 📝 `core/src/spclient.rs` (+3 -3) 📝 `core/src/spotify_id.rs` (+23 -405) ➕ `core/src/spotify_uri.rs` (+583 -0) 📝 `examples/play.rs` (+5 -6) 📝 `examples/playlist_tracks.rs` (+3 -2) 📝 `metadata/src/album.rs` (+11 -7) 📝 `metadata/src/artist.rs` (+14 -10) 📝 `metadata/src/audio/item.rs` (+14 -18) 📝 `metadata/src/episode.rs` (+10 -6) 📝 `metadata/src/image.rs` (+2 -2) 📝 `metadata/src/lib.rs` (+4 -4) 📝 `metadata/src/playlist/annotation.rs` (+20 -6) 📝 `metadata/src/playlist/item.rs` (+3 -3) 📝 `metadata/src/playlist/list.rs` (+25 -12) 📝 `metadata/src/show.rs` (+10 -6) _...and 3 more files_ </details> ### 📄 Description Contributes to #1266 Introduces a new `SpotifyUri` struct which is layered on top of the existing `SpotifyId`, but has the capability to support URIs that do not confirm to the canonical base62 encoded format. This allows it to describe URIs like `spotify:local`, `spotify:genre` and others that `SpotifyId` cannot represent. Changed the internal player state to use these URIs as much as possible, such that the player could in the future accept a URI of the type `spotify:local`, as a means of laying the groundwork for local file support. --- I know #1266 is not a very good issue for my first one on the project, but I would really like to implement local file support and it doesn't seem like that will be possible for the player to handle without hacks unless we change the way we store the track URI. This is because local files URIs are of the form `spotify:local:{artist}:{album_title}:{track_title}:{duration_in_seconds}` which cannot be represented under a `u128` inside `SpotifyId` like the base62 names that all official tracks have. I have opened this PR to show what the proposed refactor in #1266 would involve, particularly with regard to the breaking changes I have had to make. So there are probably some things that can be polished more and tests added, but I wanted to get some feedback on the overall direction first. If the proposed change is too radical I will not be offended if you decide to close this PR :slightly_smiling_face: p.s. I have put all the changelogs etc. as 0.7.0 but it sounds like that is coming soon so just to be clear I have no expectation of this making it into the upcoming release --- <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:25 +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#1432
No description provided.