mirror of
https://github.com/ivabus/lonelyradio
synced 2024-11-22 08:05:10 +03:00
0.1.6: add "WAR" mode
Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
6b5d73d341
commit
819972f0c0
3 changed files with 31 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "lonelyradio"
|
name = "lonelyradio"
|
||||||
description = "TCP radio for singles"
|
description = "TCP radio for singles"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = [ "Ivan Bushchik <ivabus@ivabus.dev>" ]
|
authors = [ "Ivan Bushchik <ivabus@ivabus.dev>" ]
|
||||||
|
|
|
@ -15,7 +15,7 @@ cargo build -r
|
||||||
## Run
|
## Run
|
||||||
|
|
||||||
```
|
```
|
||||||
lonelyradio [-a <ADDRESS:PORT>] <MUSIC_FOLDER> [-p]
|
lonelyradio [-a <ADDRESS:PORT>] <MUSIC_FOLDER> [-p] [-w]
|
||||||
```
|
```
|
||||||
|
|
||||||
All files (recursively) will be shuffled and played back. Public log will be displayed to stderr, private to stdout.
|
All files (recursively) will be shuffled and played back. Public log will be displayed to stderr, private to stdout.
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -1,9 +1,10 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use samplerate::ConverterType;
|
use samplerate::ConverterType;
|
||||||
use std::path::PathBuf;
|
|
||||||
use symphonia::core::audio::SampleBuffer;
|
use symphonia::core::audio::SampleBuffer;
|
||||||
use symphonia::core::codecs::CODEC_TYPE_NULL;
|
use symphonia::core::codecs::CODEC_TYPE_NULL;
|
||||||
use symphonia::core::formats::FormatOptions;
|
use symphonia::core::formats::FormatOptions;
|
||||||
|
@ -22,6 +23,9 @@ struct Args {
|
||||||
|
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
public_log: bool,
|
public_log: bool,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
war: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -63,19 +67,29 @@ async fn stream(mut s: TcpStream) {
|
||||||
'track: loop {
|
'track: loop {
|
||||||
let track = pick_track(&tracklist);
|
let track = pick_track(&tracklist);
|
||||||
println!(
|
println!(
|
||||||
"[{}] {} to {}:{}",
|
"[{}] {} to {}:{}{}",
|
||||||
Local::now().to_rfc3339(),
|
Local::now().to_rfc3339(),
|
||||||
track.to_str().unwrap(),
|
track.to_str().unwrap(),
|
||||||
s.peer_addr().unwrap().ip(),
|
s.peer_addr().unwrap().ip(),
|
||||||
s.peer_addr().unwrap().port()
|
s.peer_addr().unwrap().port(),
|
||||||
|
if args.war {
|
||||||
|
" with WAR.rs"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if args.public_log {
|
if args.public_log {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"[{}] {} to {}",
|
"[{}] {} to {}{}",
|
||||||
Local::now().to_rfc3339(),
|
Local::now().to_rfc3339(),
|
||||||
track.to_str().unwrap(),
|
track.to_str().unwrap(),
|
||||||
s.peer_addr().unwrap().port()
|
s.peer_addr().unwrap().port(),
|
||||||
|
if args.war {
|
||||||
|
" with WAR.rs"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +148,16 @@ async fn stream(mut s: TcpStream) {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
for sample in samples {
|
for sample in samples {
|
||||||
let result = s.write(&((sample * 32768_f32) as i16).to_le_bytes()).await;
|
let result = s
|
||||||
|
.write(
|
||||||
|
&(if args.war {
|
||||||
|
sample.signum() as i16 * 32767
|
||||||
|
} else {
|
||||||
|
(sample * 32768_f32) as i16
|
||||||
|
})
|
||||||
|
.to_le_bytes(),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
// Socket error -> stop
|
// Socket error -> stop
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue