use mpd's load() to load playlists

This commit is contained in:
krolxon 2024-04-28 19:21:23 +05:30
parent 7eac9cfbc6
commit fd371e8960
2 changed files with 15 additions and 24 deletions

View File

@ -160,16 +160,9 @@ impl Connection {
} }
/// Push all songs of a playlist into queue /// Push all songs of a playlist into queue
pub fn push_playlist(&mut self, playlist: &str) -> Result<()> { pub fn load_playlist(&mut self, playlist: &str) -> Result<()> {
let songs: Vec<Song> = self.conn.playlist(playlist)?; self.conn.load(playlist, ..)?;
self.conn.play()?;
for song in songs {
if self.songs_filenames.contains(&song.file) {
let song = self.get_song_with_only_filename(&song.file);
self.conn.push(&song)?;
self.conn.play()?;
}
}
Ok(()) Ok(())
} }

View File

@ -197,7 +197,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
SelectedTab::Playlists => { SelectedTab::Playlists => {
app.conn app.conn
.push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
} }
} }
app.conn.update_status(); app.conn.update_status();
@ -330,22 +330,20 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
KeyCode::Char('e') => if app.selected_tab == SelectedTab::Playlists {}, KeyCode::Char('e') => if app.selected_tab == SelectedTab::Playlists {},
// go to top of list // go to top of list
KeyCode::Char('g') => { KeyCode::Char('g') => match app.selected_tab {
match app.selected_tab { SelectedTab::Queue => app.queue_list.index = 0,
SelectedTab::Queue => app.queue_list.index = 0, SelectedTab::DirectoryBrowser => app.browser.selected = 0,
SelectedTab::DirectoryBrowser => app.browser.selected = 0, SelectedTab::Playlists => app.pl_list.index = 0,
SelectedTab::Playlists => app.pl_list.index = 0 },
}
}
// go to bottom of list // go to bottom of list
KeyCode::Char('G') => { KeyCode::Char('G') => match app.selected_tab {
match app.selected_tab { SelectedTab::Queue => app.queue_list.index = app.queue_list.list.len() - 1,
SelectedTab::Queue => app.queue_list.index = app.queue_list.list.len() - 1, SelectedTab::DirectoryBrowser => {
SelectedTab::DirectoryBrowser => app.browser.selected = app.browser.filetree.len() - 1, app.browser.selected = app.browser.filetree.len() - 1
SelectedTab::Playlists => app.pl_list.index = app.pl_list.list.len() - 1
} }
} SelectedTab::Playlists => app.pl_list.index = app.pl_list.list.len() - 1,
},
_ => {} _ => {}
} }
} }