Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

httpapi: fix play directory

+27 -27
+1
Cargo.lock
··· 5749 5749 "md5", 5750 5750 "owo-colors 4.1.0", 5751 5751 "queryst", 5752 + "rand", 5752 5753 "reqwest", 5753 5754 "rockbox-graphql", 5754 5755 "rockbox-library",
+7 -7
crates/graphql/src/schema/playback.rs
··· 236 236 for file in fs::read_dir(&path)? { 237 237 let file = file?; 238 238 239 - if file.metadata()?.is_file() 240 - && !AUDIO_EXTENSIONS.iter().any(|ext| { 239 + if file.metadata()?.is_file() { 240 + if !AUDIO_EXTENSIONS.iter().any(|ext| { 241 241 file.path() 242 242 .to_string_lossy() 243 243 .ends_with(&format!(".{}", ext)) 244 - }) 245 - { 246 - continue; 244 + }) { 245 + continue; 246 + } 247 + 248 + tracks.push(file.path().to_string_lossy().to_string()); 247 249 } 248 - 249 - tracks.push(file.path().to_string_lossy().to_string()); 250 250 } 251 251 } 252 252 }
+1
crates/server/Cargo.toml
··· 11 11 md5 = "0.7.0" 12 12 owo-colors = "4.0.0" 13 13 queryst = "3.0.0" 14 + rand = "0.8.5" 14 15 reqwest = {version = "0.12.7", features = ["blocking", "rustls-tls"], default-features = false} 15 16 rockbox-graphql = {path = "../graphql"} 16 17 rockbox-library = {path = "../library"}
+17 -20
crates/server/src/handlers/playlists.rs
··· 3 3 types::{DeleteTracks, InsertTracks, NewPlaylist, StatusCode}, 4 4 }; 5 5 use anyhow::Error; 6 + use rand::seq::SliceRandom; 7 + use rockbox_graphql::read_files; 6 8 use rockbox_library::repo; 7 - use rockbox_sys::{self as rb, types::playlist_amount::PlaylistAmount}; 9 + use rockbox_sys::{ 10 + self as rb, types::playlist_amount::PlaylistAmount, PLAYLIST_INSERT_LAST, 11 + PLAYLIST_INSERT_LAST_SHUFFLED, 12 + }; 8 13 9 14 pub async fn create_playlist( 10 15 _ctx: &Context, ··· 138 143 139 144 pub async fn insert_tracks(_ctx: &Context, req: &Request, res: &mut Response) -> Result<(), Error> { 140 145 let req_body = req.body.as_ref().unwrap(); 141 - let tracklist: InsertTracks = serde_json::from_str(&req_body).unwrap(); 146 + let mut tracklist: InsertTracks = serde_json::from_str(&req_body).unwrap(); 142 147 let amount = rb::playlist::amount(); 143 148 144 149 if let Some(dir) = &tracklist.directory { 145 - if amount == 0 { 146 - let status = rb::playlist::create(dir, None); 147 - if status == -1 { 148 - res.set_status(500); 149 - res.text("Failed to create playlist"); 150 - return Ok(()); 151 - } 152 - } 153 - rb::playlist::insert_directory(dir, tracklist.position, true, true); 154 - if tracklist.shuffle.unwrap_or(false) { 155 - let random_seed = rb::system::current_tick() as i32; 156 - rb::playlist::shuffle(random_seed, 0); 157 - } 150 + tracklist.tracks = read_files(dir.clone()).await?; 158 151 } 159 152 160 153 if tracklist.tracks.is_empty() { ··· 182 175 return Ok(()); 183 176 } 184 177 185 - rb::playlist::insert_tracks( 186 - tracklist.tracks.iter().map(|t| t.as_str()).collect(), 187 - tracklist.position, 188 - tracklist.tracks.len() as i32, 189 - ); 178 + let mut tracks: Vec<&str> = tracklist.tracks.iter().map(|t| t.as_str()).collect(); 179 + let position = match tracklist.position { 180 + PLAYLIST_INSERT_LAST_SHUFFLED => { 181 + tracks.shuffle(&mut rand::thread_rng()); 182 + PLAYLIST_INSERT_LAST 183 + } 184 + _ => tracklist.position, 185 + }; 186 + rb::playlist::insert_tracks(tracks, position, tracklist.tracks.len() as i32); 190 187 191 188 res.text(&tracklist.position.to_string()); 192 189
+1
webui/rockbox/src/Components/Files/ContextMenu/ContextMenuWithData.tsx
··· 81 81 variables: { 82 82 path, 83 83 shuffle: true, 84 + recurse: true, 84 85 }, 85 86 }); 86 87 };