mirror of
https://github.com/ivabus/lonelyradio
synced 2024-11-21 23:55:09 +03:00
0.1.4: logging things
Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
84d4a9e65d
commit
4f63fcd5d2
4 changed files with 24 additions and 11 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -320,7 +320,7 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
|||
|
||||
[[package]]
|
||||
name = "lonelyradio"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -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,11 +138,9 @@ async fn stream(mut s: TcpStream) {
|
|||
if result.is_err() {
|
||||
// Socket error -> stop
|
||||
return;
|
||||
} else {
|
||||
if result.unwrap() == 0 {
|
||||
// If socket cannot accept data -> stop
|
||||
return;
|
||||
}
|
||||
} else if result.unwrap() == 0 {
|
||||
// If socket cannot accept data -> stop
|
||||
return;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue