1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 01:39:28 +02:00

refactor: Introduce SpotifyUri struct (#1538)

* refactor: Introduce SpotifyUri struct

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.

* fix: Don't pass unknown URIs from deprecated player methods

* refactor: remove SpotifyUri::to_base16

This should be deprecated for the same reason to_base62 is, and could unpredictably throw errors -- consumers should match on the inner ID if they need a base62 representation and handle failure appropriately

* refactor: Store original data in SpotifyUri::Unknown

Instead of assuming Unknown has a u128 SpotifyId, store the original data and type that we failed to parse.

* refactor: Remove SpotifyItemType

* refactor: Address review feedback

* test: Add more SpotifyUri tests

* chore: Correctly mark changes as breaking in CHANGELOG.md

* refactor: Respond to review feedback

* chore: Changelog updates
This commit is contained in:
Jay Malhotra 2025-09-11 20:59:53 +01:00 committed by GitHub
parent 0e5531ff54
commit df5f957bdd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 937 additions and 625 deletions

View file

@ -2,10 +2,8 @@ use std::{env, process::exit};
use librespot::{
core::{
authentication::Credentials,
config::SessionConfig,
session::Session,
spotify_id::{SpotifyId, SpotifyItemType},
SpotifyUri, authentication::Credentials, config::SessionConfig, session::Session,
spotify_id::SpotifyId,
},
playback::{
audio_backend,
@ -28,8 +26,9 @@ async fn main() {
}
let credentials = Credentials::with_access_token(&args[1]);
let mut track = SpotifyId::from_base62(&args[2]).unwrap();
track.item_type = SpotifyItemType::Track;
let track = SpotifyUri::Track {
id: SpotifyId::from_base62(&args[2]).unwrap(),
};
let backend = audio_backend::find(None).unwrap();

View file

@ -2,7 +2,8 @@ use std::{env, process::exit};
use librespot::{
core::{
authentication::Credentials, config::SessionConfig, session::Session, spotify_id::SpotifyId,
authentication::Credentials, config::SessionConfig, session::Session,
spotify_uri::SpotifyUri,
},
metadata::{Metadata, Playlist, Track},
};
@ -19,7 +20,7 @@ async fn main() {
}
let credentials = Credentials::with_access_token(&args[1]);
let plist_uri = SpotifyId::from_uri(&args[2]).unwrap_or_else(|_| {
let plist_uri = SpotifyUri::from_uri(&args[2]).unwrap_or_else(|_| {
eprintln!(
"PLAYLIST should be a playlist URI such as: \
\"spotify:playlist:37i9dQZF1DXec50AjHrNTq\""