Skip to content

Commit 0c4ff8e

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents e87864e + 2e13ab2 commit 0c4ff8e

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

spotify_player/src/event/popup.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn handle_command_for_context_browsing_list_popup(
282282
uris.len(),
283283
|_, _| {},
284284
|ui: &mut UIStateGuard, id: usize| -> Result<()> {
285-
let uri = uris[id].clone();
285+
let uri = crate::utils::parse_uri(&uris[id]);
286286
let context_id = match context_type {
287287
rspotify_model::Type::Playlist => ContextId::Playlist(PlaylistId::from_uri(&uri)?),
288288
rspotify_model::Type::Artist => ContextId::Artist(ArtistId::from_uri(&uri)?),
@@ -400,7 +400,9 @@ fn handle_command_for_action_list_popup(
400400
TrackAction::BrowseAlbum => {
401401
if let Some(ref album) = track.album {
402402
let uri = album.id.uri();
403-
let context_id = ContextId::Album(AlbumId::from_uri(&uri)?);
403+
let context_id = ContextId::Album(AlbumId::from_uri(
404+
&crate::utils::parse_uri(&uri),
405+
)?);
404406
ui.create_new_page(PageState::Context {
405407
id: None,
406408
context_page_type: ContextPageType::Browsing(context_id),

spotify_player/src/state/player.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,21 @@ impl PlayerState {
6262
pub fn playing_context_id(&self) -> Option<ContextId> {
6363
match self.playback {
6464
Some(ref playback) => match playback.context {
65-
Some(ref context) => match context._type {
66-
rspotify_model::Type::Playlist => Some(ContextId::Playlist(
67-
PlaylistId::from_uri(&context.uri).expect("invalid playing context URI"),
68-
)),
69-
rspotify_model::Type::Album => Some(ContextId::Album(
70-
AlbumId::from_uri(&context.uri).expect("invalid playing context URI"),
71-
)),
72-
rspotify_model::Type::Artist => Some(ContextId::Artist(
73-
ArtistId::from_uri(&context.uri).expect("invalid playing context URI"),
74-
)),
75-
_ => None,
76-
},
65+
Some(ref context) => {
66+
let uri = crate::utils::parse_uri(&context.uri);
67+
match context._type {
68+
rspotify_model::Type::Playlist => {
69+
Some(ContextId::Playlist(PlaylistId::from_uri(&uri).ok()?))
70+
}
71+
rspotify_model::Type::Album => {
72+
Some(ContextId::Album(AlbumId::from_uri(&uri).ok()?))
73+
}
74+
rspotify_model::Type::Artist => {
75+
Some(ContextId::Artist(ArtistId::from_uri(&uri).ok()?))
76+
}
77+
_ => None,
78+
}
79+
}
7780
None => None,
7881
},
7982
None => None,

spotify_player/src/utils.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use tui::widgets::*;
24
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
35

@@ -65,3 +67,16 @@ pub fn get_track_album_image_url(track: &rspotify::model::FullTrack) -> Option<&
6567
Some(&track.album.images[0].url)
6668
}
6769
}
70+
71+
pub fn parse_uri(uri: &str) -> Cow<str> {
72+
let parts = uri.split(':').collect::<Vec<_>>();
73+
// The below URI probably has a format of `spotify:user:{user_id}:{type}:{id}`,
74+
// but `rspotify` library expects to receive an URI of format `spotify:{type}:{id}`.
75+
// We have to modify the URI to a corresponding format.
76+
// See: https://github.com/aome510/spotify-player/issues/57#issuecomment-1160868626
77+
if parts.len() == 5 {
78+
Cow::Owned([parts[0], parts[3], parts[4]].join(":"))
79+
} else {
80+
Cow::Borrowed(uri)
81+
}
82+
}

0 commit comments

Comments
 (0)