Krolyxon
Commit c047f63

rmptuic047f63

add entire directory to playlists

Author
krolxon
Date
2024-04-29 21:16 +0530
Parent
38ebdf9
Commit
c047f63cd1c727c36c61acacba073eb03b7f8617

+44 −15

1 file changed

  1. M src/handler.rs +44 −15
M src/handler.rs View
@@ -1,4 +1,5 @@
1−use std::time::Duration;
1+use crate::browser::FileExtension;
2+use std::{path::Path, time::Duration};
23
34 use crate::{
45 app::{App, AppResult, SelectedTab},
@@ -118,35 +119,63 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
118119
119120 KeyCode::Enter => {
120121 let pl_index = app.append_list.index;
121− let pl_name = app.append_list.list.get(pl_index).unwrap();
122+ let pl_name = &app.append_list.list.get(pl_index).unwrap();
122123
123124 let s_index: usize;
124− let mut short_path: String = String::new();
125125 match app.selected_tab {
126126 SelectedTab::Queue => {
127127 s_index = app.queue_list.index;
128− short_path = app.queue_list.list.get(s_index).unwrap().to_string();
128+ let short_path = app.queue_list.list.get(s_index).unwrap().to_string();
129+
130+ if let Some(full_path) = app.conn.get_full_path(&short_path) {
131+ let song = app.conn.get_song_with_only_filename(&full_path);
132+
133+ if pl_name.to_string() == "Current Playlist" {
134+ app.conn.conn.push(&song)?;
135+ app.update_queue();
136+ } else {
137+ app.conn.add_to_playlist(pl_name, &song)?;
138+ }
139+ }
129140 }
130141
131142 SelectedTab::DirectoryBrowser => {
132143 let (t, f) = app.browser.filetree.get(app.browser.selected).unwrap();
133144 if t == "file" {
134− short_path = f.to_string();
145+ let short_path = f;
146+ if let Some(full_path) = app.conn.get_full_path(short_path) {
147+ let song = app.conn.get_song_with_only_filename(&full_path);
148+
149+ if pl_name.to_string() == "Current Playlist" {
150+ app.conn.conn.push(&song)?;
151+ app.update_queue();
152+ } else {
153+ app.conn.add_to_playlist(pl_name, &song)?;
154+ }
155+ }
156+ } else if t == "directory" {
157+ for (t, f) in app.conn.conn.listfiles(f)?.iter() {
158+ // dir_vec.push((t, f));
159+ if t == "file"
160+ && Path::new(&f).has_extension(&[
161+ "mp3", "ogg", "flac", "m4a", "wav", "aac", "opus", "ape",
162+ "wma", "mpc", "aiff", "dff", "mp2", "mka",
163+ ])
164+ {
165+ let full_path = app.conn.get_full_path(&f).unwrap_or_default();
166+ let song = app.conn.get_song_with_only_filename(&full_path);
167+ if pl_name.to_string() == "Current Playlist" {
168+ app.conn.conn.push(&song)?;
169+ } else {
170+ app.conn.add_to_playlist(pl_name, &song)?;
171+ }
172+ }
173+ }
135174 }
136175 }
137176 _ => {}
138177 }
139178
140− if let Some(full_path) = app.conn.get_full_path(&short_path) {
141− let song = app.conn.get_song_with_only_filename(&full_path);
142−
143− if pl_name == "Current Playlist" {
144− app.conn.conn.push(&song)?;
145− app.update_queue();
146− } else {
147− app.conn.add_to_playlist(pl_name, &song)?;
148− }
149− }
150179 // hide the playlist popup
151180 app.playlist_popup = false;
152181 app.append_list.index = 0;