0.1.4: logging things

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2024-01-29 11:35:48 +03:00
parent 84d4a9e65d
commit 4f63fcd5d2
No known key found for this signature in database
GPG key ID: 2F16FBF3262E090C
4 changed files with 24 additions and 11 deletions

2
Cargo.lock generated
View file

@ -320,7 +320,7 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "lonelyradio"
version = "0.1.3"
version = "0.1.4"
dependencies = [
"chrono",
"clap",

View file

@ -1,7 +1,7 @@
[package]
name = "lonelyradio"
description = "TCP radio for singles"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
authors = [ "Ivan Bushchik <ivabus@ivabus.dev>" ]
@ -10,7 +10,7 @@ repository = "https://github.com/ivabus/lonelyradio"
[dependencies]
rand = "0.8.5"
clap = { version = "4.4.18", features = [ "derive" ] }
tokio = { version = "1.35.1", features = [ "io-util", "net", "rt-multi-thread", "rt", "macros" ] }
tokio = { version = "1.35.1", features = [ "fs", "io-util", "net", "rt-multi-thread", "rt", "macros" ] }
walkdir = "2.4.0"
symphonia = { version = "0.5.3", features = [ "all-codecs", "all-formats", "pcm", "symphonia-codec-pcm" ] }
samplerate = "0.2.4"

View file

@ -15,10 +15,10 @@ cargo build -r
## Run
```
lonelyradio [-a <ADDRESS:PORT>] <MUSIC_FOLDER>
lonelyradio [-a <ADDRESS:PORT>] <MUSIC_FOLDER> [-p]
```
All files (recursively) will be shuffled and played back.
All files (recursively) will be shuffled and played back. Public log will be displayed to stderr, private to stdout.
### Clients

View file

@ -19,11 +19,15 @@ struct Args {
dir: PathBuf,
#[arg(short, default_value = "0.0.0.0:5894")]
address: String,
#[arg(short, long)]
public_log: bool,
}
#[tokio::main]
async fn main() {
let listener = TcpListener::bind(Args::parse().address).await.unwrap();
loop {
let (socket, _) = listener.accept().await.unwrap();
tokio::spawn(stream(socket));
@ -49,6 +53,7 @@ fn pick_track(tracklist: &Vec<PathBuf>) -> &PathBuf {
}
async fn stream(mut s: TcpStream) {
let args = Args::parse();
let tracklist = walkdir::WalkDir::new(Args::parse().dir)
.into_iter()
.filter_entry(is_not_hidden)
@ -61,9 +66,19 @@ async fn stream(mut s: TcpStream) {
"[{}] {} to {}:{}",
Local::now().to_rfc3339(),
track.to_str().unwrap(),
s.peer_addr().unwrap().ip().to_string(),
s.peer_addr().unwrap().ip(),
s.peer_addr().unwrap().port()
);
if args.public_log {
eprintln!(
"[{}] {} to {}\nc",
Local::now().to_rfc3339(),
track.to_str().unwrap(),
s.peer_addr().unwrap().port()
);
}
let file = Box::new(std::fs::File::open(track).unwrap());
let mut hint = Hint::new();
hint.with_extension(track.extension().unwrap().to_str().unwrap());
@ -123,13 +138,11 @@ async fn stream(mut s: TcpStream) {
if result.is_err() {
// Socket error -> stop
return;
} else {
if result.unwrap() == 0 {
} else if result.unwrap() == 0 {
// If socket cannot accept data -> stop
return;
}
}
}
continue;
}
_ => {