Krolyxon
Commit fd371e8

rmptuifd371e8

use mpd's load() to load playlists

Author
krolxon
Date
2024-04-28 19:21 +0530
Parent
7eac9cf
Commit
fd371e896096b03bc5efa7dc59963cbba0c334e7

+15 −24

2 files changed

  1. M src/connection.rs +3 −10
  2. M src/handler.rs +12 −14
M src/connection.rs View
@@ -160,16 +160,9 @@ impl Connection {
160160 }
161161
162162 /// Push all songs of a playlist into queue
163− pub fn push_playlist(&mut self, playlist: &str) -> Result<()> {
164− let songs: Vec<Song> = self.conn.playlist(playlist)?;
165−
166− for song in songs {
167− if self.songs_filenames.contains(&song.file) {
168− let song = self.get_song_with_only_filename(&song.file);
169− self.conn.push(&song)?;
170− self.conn.play()?;
171− }
172− }
163+ pub fn load_playlist(&mut self, playlist: &str) -> Result<()> {
164+ self.conn.load(playlist, ..)?;
165+ self.conn.play()?;
173166 Ok(())
174167 }
175168
M src/handler.rs View
@@ -197,7 +197,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
197197
198198 SelectedTab::Playlists => {
199199 app.conn
200− .push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
200+ .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
201201 }
202202 }
203203 app.conn.update_status();
@@ -330,22 +330,20 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
330330 KeyCode::Char('e') => if app.selected_tab == SelectedTab::Playlists {},
331331
332332 // go to top of list
333− KeyCode::Char('g') => {
334− match app.selected_tab {
335− SelectedTab::Queue => app.queue_list.index = 0,
336− SelectedTab::DirectoryBrowser => app.browser.selected = 0,
337− SelectedTab::Playlists => app.pl_list.index = 0
338− }
339− }
333+ KeyCode::Char('g') => match app.selected_tab {
334+ SelectedTab::Queue => app.queue_list.index = 0,
335+ SelectedTab::DirectoryBrowser => app.browser.selected = 0,
336+ SelectedTab::Playlists => app.pl_list.index = 0,
337+ },
340338
341339 // go to bottom of list
342− KeyCode::Char('G') => {
343− match app.selected_tab {
344− SelectedTab::Queue => app.queue_list.index = app.queue_list.list.len() - 1,
345− SelectedTab::DirectoryBrowser => app.browser.selected = app.browser.filetree.len() - 1,
346− SelectedTab::Playlists => app.pl_list.index = app.pl_list.list.len() - 1
340+ KeyCode::Char('G') => match app.selected_tab {
341+ SelectedTab::Queue => app.queue_list.index = app.queue_list.list.len() - 1,
342+ SelectedTab::DirectoryBrowser => {
343+ app.browser.selected = app.browser.filetree.len() - 1
347344 }
348− }
345+ SelectedTab::Playlists => app.pl_list.index = app.pl_list.list.len() - 1,
346+ },
349347 _ => {}
350348 }
351349 }