Refactor: separate Spotify API from player logic
The separation is not perfect yet, but it's a start and makes the entire codebase much easier to read.
This commit is contained in:
13
src/mpris.rs
13
src/mpris.rs
@@ -47,6 +47,7 @@ fn get_metadata(playable: Option<Playable>, spotify: Spotify) -> Metadata {
|
||||
Some(Playable::Track(track))
|
||||
} else {
|
||||
spotify
|
||||
.api
|
||||
.track(&track.id.unwrap_or_default())
|
||||
.as_ref()
|
||||
.map(|t| Playable::Track(t.into()))
|
||||
@@ -558,7 +559,7 @@ fn run_dbus_server(
|
||||
let uri_type = UriType::from_uri(&uri);
|
||||
match uri_type {
|
||||
Some(UriType::Album) => {
|
||||
if let Some(a) = spotify.album(id) {
|
||||
if let Some(a) = spotify.api.album(id) {
|
||||
if let Some(t) = &Album::from(&a).tracks {
|
||||
queue.clear();
|
||||
let index = queue.append_next(
|
||||
@@ -571,14 +572,14 @@ fn run_dbus_server(
|
||||
}
|
||||
}
|
||||
Some(UriType::Track) => {
|
||||
if let Some(t) = spotify.track(id) {
|
||||
if let Some(t) = spotify.api.track(id) {
|
||||
queue.clear();
|
||||
queue.append(Playable::Track(Track::from(&t)));
|
||||
queue.play(0, false, false)
|
||||
}
|
||||
}
|
||||
Some(UriType::Playlist) => {
|
||||
if let Some(p) = spotify.playlist(id) {
|
||||
if let Some(p) = spotify.api.playlist(id) {
|
||||
let mut playlist = Playlist::from(&p);
|
||||
let spotify = spotify.clone();
|
||||
playlist.load_tracks(spotify);
|
||||
@@ -594,7 +595,7 @@ fn run_dbus_server(
|
||||
}
|
||||
}
|
||||
Some(UriType::Show) => {
|
||||
if let Some(s) = spotify.get_show(id) {
|
||||
if let Some(s) = spotify.api.get_show(id) {
|
||||
let mut show: Show = (&s).into();
|
||||
let spotify = spotify.clone();
|
||||
show.load_all_episodes(spotify);
|
||||
@@ -612,14 +613,14 @@ fn run_dbus_server(
|
||||
}
|
||||
}
|
||||
Some(UriType::Episode) => {
|
||||
if let Some(e) = spotify.episode(id) {
|
||||
if let Some(e) = spotify.api.episode(id) {
|
||||
queue.clear();
|
||||
queue.append(Playable::Episode(Episode::from(&e)));
|
||||
queue.play(0, false, false)
|
||||
}
|
||||
}
|
||||
Some(UriType::Artist) => {
|
||||
if let Some(a) = spotify.artist_top_tracks(id) {
|
||||
if let Some(a) = spotify.api.artist_top_tracks(id) {
|
||||
queue.clear();
|
||||
queue.append_next(a.iter().map(|track| Playable::Track(track.clone())).collect());
|
||||
queue.play(0, false, false)
|
||||
|
||||
Reference in New Issue
Block a user