From 7aa6d49f3df4b2b8dbbd1b0b958bdefaa228a62c Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Wed, 13 Mar 2019 23:30:50 +0100 Subject: [PATCH] move foreign SpotifyId struct out of Track model --- src/mpris.rs | 2 +- src/spotify.rs | 4 +++- src/track.rs | 7 +++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/mpris.rs b/src/mpris.rs index 9cf7f76..6b8810b 100644 --- a/src/mpris.rs +++ b/src/mpris.rs @@ -25,7 +25,7 @@ fn get_metadata(queue: Arc>) -> HashMap let track = queue.get_current(); hm.insert("mpris:trackid".to_string(), Variant(Box::new( - track.map(|t| format!("spotify:track:{}", t.id.to_base62())).unwrap_or("".to_string()) + track.map(|t| format!("spotify:track:{}", t.id)).unwrap_or("".to_string()) ))); hm.insert("mpris:length".to_string(), Variant(Box::new( track.map(|t| t.duration * 1_000_000).unwrap_or(0) diff --git a/src/spotify.rs b/src/spotify.rs index 1fff69e..68b1ba4 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -3,6 +3,7 @@ use librespot::core::config::SessionConfig; use librespot::core::keymaster::get_token; use librespot::core::keymaster::Token; use librespot::core::session::Session; +use librespot::core::spotify_id::SpotifyId; use librespot::playback::config::PlayerConfig; use librespot::playback::audio_backend; @@ -106,7 +107,8 @@ impl futures::Future for Worker { debug!("message received!"); match cmd { WorkerCommand::Load(track) => { - self.play_task = Box::new(self.player.load(track.id, false, 0)); + let id = SpotifyId::from_base62(&track.id).expect("could not parse id"); + self.play_task = Box::new(self.player.load(id, false, 0)); info!("player loading track: {:?}", track); } WorkerCommand::Play => { diff --git a/src/track.rs b/src/track.rs index e8ac489..9e4dd88 100644 --- a/src/track.rs +++ b/src/track.rs @@ -1,11 +1,10 @@ use std::fmt; -use librespot::core::spotify_id::SpotifyId; use rspotify::spotify::model::track::FullTrack; #[derive(Clone)] pub struct Track { - pub id: SpotifyId, + pub id: String, pub title: String, pub track_number: u32, pub disc_number: i32, @@ -36,7 +35,7 @@ impl Track { }; Track { - id: SpotifyId::from_base62(&track.id).expect("could not load track"), + id: track.id.clone(), title: track.name.clone(), track_number: track.track_number, disc_number: track.disc_number, @@ -69,7 +68,7 @@ impl fmt::Debug for Track { "({} - {} ({}))", self.artists.join(", "), self.title, - self.id.to_base62() + self.id ) } }