mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 01:52:53 -05:00
Updated Next Song Grabber to grab songs from playlists when playing songs from playlists
This commit is contained in:
parent
fce2927986
commit
359990b36a
5 changed files with 105 additions and 37 deletions
|
@ -109,6 +109,10 @@ pub enum LibraryCommand {
|
|||
AllSongs,
|
||||
GetLibrary,
|
||||
ExternalPlaylist(Uuid),
|
||||
PlaylistSong{
|
||||
list_uuid: Uuid,
|
||||
item_uuid: Uuid
|
||||
},
|
||||
Playlist(Uuid),
|
||||
ImportM3UPlayList(PathBuf),
|
||||
Save,
|
||||
|
@ -122,6 +126,7 @@ pub enum LibraryResponse {
|
|||
AllSongs(Vec<Song>),
|
||||
Library(MusicLibrary),
|
||||
ExternalPlaylist(ExternalPlaylist),
|
||||
PlaylistSong(Song, usize),
|
||||
Playlist(Playlist),
|
||||
ImportM3UPlayList(Uuid, String),
|
||||
Playlists(Vec<(Uuid, String)>),
|
||||
|
|
|
@ -89,6 +89,15 @@ impl Controller {
|
|||
.await
|
||||
.unwrap();
|
||||
}
|
||||
LibraryCommand::PlaylistSong { list_uuid, item_uuid } => {
|
||||
let playlist= library.playlists.query_uuid(&list_uuid).unwrap();
|
||||
let Some((uuid, index)) = playlist.query_uuid(&item_uuid) else { todo!() };
|
||||
let Some((song, _)) = library.query_uuid(uuid) else { todo!() };
|
||||
res_rx
|
||||
.send(LibraryResponse::PlaylistSong(song.clone(), index))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
_ => {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
@ -91,6 +91,8 @@ impl Controller {
|
|||
panic!("This is temporary, handle queueItemTypes at some point")
|
||||
};
|
||||
|
||||
match np_song.location {
|
||||
PlayerLocation::Library => {
|
||||
let (command, tx) =
|
||||
LibraryCommandInput::command(LibraryCommand::AllSongs);
|
||||
// Append next song in library
|
||||
|
@ -99,7 +101,6 @@ impl Controller {
|
|||
else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let (command, tx) = LibraryCommandInput::command(
|
||||
LibraryCommand::Song(np_song.song.uuid),
|
||||
);
|
||||
|
@ -126,7 +127,44 @@ impl Controller {
|
|||
} else {
|
||||
println!("Library Empty");
|
||||
}
|
||||
|
||||
}
|
||||
PlayerLocation::Playlist(uuid) => {
|
||||
let (command, tx) = LibraryCommandInput::command(
|
||||
LibraryCommand::ExternalPlaylist(uuid),
|
||||
);
|
||||
lib_mail.send(command).await.unwrap();
|
||||
let LibraryResponse::ExternalPlaylist(playlist) = tx.recv().await.unwrap() else {
|
||||
unreachable!()
|
||||
};
|
||||
let (command, tx) = LibraryCommandInput::command(
|
||||
LibraryCommand::PlaylistSong { list_uuid: playlist.uuid, item_uuid: np_song.song.uuid }
|
||||
);
|
||||
lib_mail.send(command).await.unwrap();
|
||||
let LibraryResponse::PlaylistSong(_, i) = tx.recv().await.unwrap() else {
|
||||
unreachable!()
|
||||
};
|
||||
if let Some(song) = playlist.tracks.get(i + 49) {
|
||||
let (command, tx) =
|
||||
QueueCommandInput::command(QueueCommand::Append(
|
||||
QueueItem::from_item_type(QueueItemType::Single(
|
||||
QueueSong {
|
||||
song: song.clone(),
|
||||
location: np_song.location,
|
||||
},
|
||||
)),
|
||||
false,
|
||||
));
|
||||
queue_mail.send(command).await.unwrap();
|
||||
let QueueResponse::Empty(Ok(())) = tx.recv().await.unwrap()
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
} else {
|
||||
println!("Playlist Empty");
|
||||
}
|
||||
}
|
||||
_ => todo!()
|
||||
}
|
||||
res_rx
|
||||
.send(PlayerResponse::NowPlaying(Ok(np_song.song.clone())))
|
||||
.await
|
||||
|
|
|
@ -55,7 +55,6 @@ impl Controller {
|
|||
notify_connections
|
||||
.send(ConnectionsNotification::AboutToFinish)
|
||||
.unwrap();
|
||||
println!("About to Finish");
|
||||
}
|
||||
})
|
||||
});
|
||||
|
@ -83,7 +82,6 @@ impl Controller {
|
|||
notify_connections
|
||||
.send(ConnectionsNotification::EOS)
|
||||
.unwrap();
|
||||
println!("End of song");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -335,6 +335,24 @@ impl Playlist {
|
|||
|
||||
(songs, invalid_uuids)
|
||||
}
|
||||
|
||||
pub fn query_uuid(&self, uuid: &Uuid) -> Option<(&Uuid, usize)> {
|
||||
let result = self
|
||||
.tracks
|
||||
.par_iter()
|
||||
.enumerate()
|
||||
.try_for_each(|(i, track)| {
|
||||
if uuid == track {
|
||||
return std::ops::ControlFlow::Break((track, i));
|
||||
}
|
||||
std::ops::ControlFlow::Continue(())
|
||||
});
|
||||
|
||||
match result {
|
||||
std::ops::ControlFlow::Break(song) => Some(song),
|
||||
std::ops::ControlFlow::Continue(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Playlist {
|
||||
|
|
Loading…
Reference in a new issue