mirror of
https://github.com/ivabus/lonelyradio
synced 2024-11-21 23:55: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]]
|
[[package]]
|
||||||
name = "lonelyradio"
|
name = "lonelyradio"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "lonelyradio"
|
name = "lonelyradio"
|
||||||
description = "TCP radio for singles"
|
description = "TCP radio for singles"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = [ "Ivan Bushchik <ivabus@ivabus.dev>" ]
|
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)
|
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) {
|
async fn stream(mut s: TcpStream) {
|
||||||
let tracklist = walkdir::WalkDir::new(Args::parse().dir)
|
let tracklist = walkdir::WalkDir::new(Args::parse().dir)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -41,10 +56,7 @@ async fn stream(mut s: TcpStream) {
|
||||||
.map(|x| x.into_path())
|
.map(|x| x.into_path())
|
||||||
.collect::<Vec<PathBuf>>();
|
.collect::<Vec<PathBuf>>();
|
||||||
'track: loop {
|
'track: loop {
|
||||||
let mut track = tracklist.choose(&mut thread_rng()).unwrap();
|
let track = pick_track(&tracklist);
|
||||||
while !track.metadata().unwrap().is_file() {
|
|
||||||
track = tracklist.choose(&mut thread_rng()).unwrap()
|
|
||||||
}
|
|
||||||
println!(
|
println!(
|
||||||
"[{}] {} to {}",
|
"[{}] {} to {}",
|
||||||
Local::now().to_rfc3339(),
|
Local::now().to_rfc3339(),
|
||||||
|
|
Loading…
Reference in a new issue