Skip to content

Commit 5b35df1

Browse files
authored
use track's id of linked_from if exists (#286)
Resolves #285 Resolves #282 Spotify uses [Track Relinking](https://developer.spotify.com/documentation/web-api/concepts/track-relinking) to re-link a track to a different version of the same track if it's unavailable in user's market while the other version is available. Because of this relinking process, the linked track's ID is returned by the Spotify APIs instead of the original track's ID. This makes starting a playback in a context (e.g album, playlist, etc) with the linked track's ID failed because Spotify cannot find a track with that ID in the context. This PR updates the track conversion code to use the original track's ID if it's relinked.
1 parent b3b0271 commit 5b35df1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

spotify_player/src/state/model.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,12 @@ impl Track {
254254
/// tries to convert from a `rspotify_model::SimplifiedTrack` into `Track`
255255
pub fn try_from_simplified_track(track: rspotify_model::SimplifiedTrack) -> Option<Self> {
256256
if track.is_playable.unwrap_or(true) {
257+
let id = match track.linked_from {
258+
Some(d) => d.id,
259+
None => track.id?,
260+
};
257261
Some(Self {
258-
id: track.id?,
262+
id,
259263
name: track.name,
260264
artists: from_simplified_artists_to_artists(track.artists),
261265
album: None,
@@ -271,8 +275,12 @@ impl Track {
271275
/// tries to convert from a `rspotify_model::FullTrack` into `Track`
272276
pub fn try_from_full_track(track: rspotify_model::FullTrack) -> Option<Self> {
273277
if track.is_playable.unwrap_or(true) {
278+
let id = match track.linked_from {
279+
Some(d) => d.id,
280+
None => track.id?,
281+
};
274282
Some(Self {
275-
id: track.id?,
283+
id,
276284
name: track.name,
277285
artists: from_simplified_artists_to_artists(track.artists),
278286
album: Album::try_from_simplified_album(track.album),

0 commit comments

Comments
 (0)