mirror of
https://github.com/ivabus/lonelyradio
synced 2024-11-21 15:45:09 +03:00
0.1.2: fix track picking
Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
d32aceb82c
commit
5bfe7364c2
3 changed files with 18 additions and 6 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -320,7 +320,7 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
|||
|
||||
[[package]]
|
||||
name = "lonelyradio"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "lonelyradio"
|
||||
description = "TCP radio for singles"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = [ "Ivan Bushchik <ivabus@ivabus.dev>" ]
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -33,6 +33,21 @@ fn is_not_hidden(entry: &DirEntry) -> bool {
|
|||
entry.file_name().to_str().map(|s| entry.depth() == 0 || !s.starts_with('.')).unwrap_or(false)
|
||||
}
|
||||
|
||||
// Recursively finding music file
|
||||
fn pick_track(tracklist: &Vec<PathBuf>) -> &PathBuf {
|
||||
let mut track = tracklist.choose(&mut thread_rng()).unwrap();
|
||||
while !track.metadata().unwrap().is_file() {
|
||||
track = pick_track(tracklist)
|
||||
}
|
||||
// Skipping "images" (covers)
|
||||
while "jpgjpegpngwebp"
|
||||
.contains(&track.extension().unwrap().to_str().unwrap().to_ascii_lowercase())
|
||||
{
|
||||
track = pick_track(tracklist)
|
||||
}
|
||||
track
|
||||
}
|
||||
|
||||
async fn stream(mut s: TcpStream) {
|
||||
let tracklist = walkdir::WalkDir::new(Args::parse().dir)
|
||||
.into_iter()
|
||||
|
@ -41,10 +56,7 @@ async fn stream(mut s: TcpStream) {
|
|||
.map(|x| x.into_path())
|
||||
.collect::<Vec<PathBuf>>();
|
||||
'track: loop {
|
||||
let mut track = tracklist.choose(&mut thread_rng()).unwrap();
|
||||
while !track.metadata().unwrap().is_file() {
|
||||
track = tracklist.choose(&mut thread_rng()).unwrap()
|
||||
}
|
||||
let track = pick_track(&tracklist);
|
||||
println!(
|
||||
"[{}] {} to {}",
|
||||
Local::now().to_rfc3339(),
|
||||
|
|
Loading…
Reference in a new issue