mirror of
https://github.com/ivabus/lonelyradio
synced 2024-11-25 09:35: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]]
|
[[package]]
|
||||||
name = "lonelyradio"
|
name = "lonelyradio"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
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.3"
|
version = "0.1.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = [ "Ivan Bushchik <ivabus@ivabus.dev>" ]
|
authors = [ "Ivan Bushchik <ivabus@ivabus.dev>" ]
|
||||||
|
@ -10,7 +10,7 @@ repository = "https://github.com/ivabus/lonelyradio"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
clap = { version = "4.4.18", features = [ "derive" ] }
|
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"
|
walkdir = "2.4.0"
|
||||||
symphonia = { version = "0.5.3", features = [ "all-codecs", "all-formats", "pcm", "symphonia-codec-pcm" ] }
|
symphonia = { version = "0.5.3", features = [ "all-codecs", "all-formats", "pcm", "symphonia-codec-pcm" ] }
|
||||||
samplerate = "0.2.4"
|
samplerate = "0.2.4"
|
||||||
|
|
|
@ -15,10 +15,10 @@ cargo build -r
|
||||||
## Run
|
## 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
|
### Clients
|
||||||
|
|
||||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -19,11 +19,15 @@ struct Args {
|
||||||
dir: PathBuf,
|
dir: PathBuf,
|
||||||
#[arg(short, default_value = "0.0.0.0:5894")]
|
#[arg(short, default_value = "0.0.0.0:5894")]
|
||||||
address: String,
|
address: String,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
public_log: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let listener = TcpListener::bind(Args::parse().address).await.unwrap();
|
let listener = TcpListener::bind(Args::parse().address).await.unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (socket, _) = listener.accept().await.unwrap();
|
let (socket, _) = listener.accept().await.unwrap();
|
||||||
tokio::spawn(stream(socket));
|
tokio::spawn(stream(socket));
|
||||||
|
@ -49,6 +53,7 @@ fn pick_track(tracklist: &Vec<PathBuf>) -> &PathBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn stream(mut s: TcpStream) {
|
async fn stream(mut s: TcpStream) {
|
||||||
|
let args = Args::parse();
|
||||||
let tracklist = walkdir::WalkDir::new(Args::parse().dir)
|
let tracklist = walkdir::WalkDir::new(Args::parse().dir)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_entry(is_not_hidden)
|
.filter_entry(is_not_hidden)
|
||||||
|
@ -61,9 +66,19 @@ async fn stream(mut s: TcpStream) {
|
||||||
"[{}] {} to {}:{}",
|
"[{}] {} to {}:{}",
|
||||||
Local::now().to_rfc3339(),
|
Local::now().to_rfc3339(),
|
||||||
track.to_str().unwrap(),
|
track.to_str().unwrap(),
|
||||||
s.peer_addr().unwrap().ip().to_string(),
|
s.peer_addr().unwrap().ip(),
|
||||||
s.peer_addr().unwrap().port()
|
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 file = Box::new(std::fs::File::open(track).unwrap());
|
||||||
let mut hint = Hint::new();
|
let mut hint = Hint::new();
|
||||||
hint.with_extension(track.extension().unwrap().to_str().unwrap());
|
hint.with_extension(track.extension().unwrap().to_str().unwrap());
|
||||||
|
@ -123,11 +138,9 @@ async fn stream(mut s: TcpStream) {
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
// Socket error -> stop
|
// Socket error -> stop
|
||||||
return;
|
return;
|
||||||
} else {
|
} else if result.unwrap() == 0 {
|
||||||
if result.unwrap() == 0 {
|
// If socket cannot accept data -> stop
|
||||||
// If socket cannot accept data -> stop
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue