diff --git a/.gitignore b/.gitignore index 29686a3..9ad6cd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target +/vendor *.ogg diff --git a/Cargo.lock b/Cargo.lock index 799e489..e8d72a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "aho-corasick" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +dependencies = [ + "memchr", +] + [[package]] name = "alsa" version = "0.6.0" @@ -1871,6 +1880,8 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] @@ -2838,9 +2849,9 @@ dependencies = [ "eframe", "egui", "libtor", + "regex", "reqwest", "rodio", - "serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index aee94b9..62ec2eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,8 @@ edition = "2021" [dependencies] libtor = { git = "https://github.com/MagicalBitcoin/libtor" } eframe = { version = "0.19.0", features = ["persistence"] } -serde = { version = "1", features = ["derive"] } +# serde = { version = "1", features = ["derive"] } reqwest = { version = "0.11.12", features = ["blocking", "json", "stream"] } egui = "0.19.0" -rodio = "0.16.0" \ No newline at end of file +rodio = "0.16.0" +regex = "1.6.0" \ No newline at end of file diff --git a/src/app.rs b/src/app.rs index 146148d..21b59c9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -25,6 +25,7 @@ impl eframe::App for App { ui.hyperlink("https://lzahq.tech"); ui.separator(); + ui.label(format!("Now Playing: ")); ui.horizontal(|ui| { if ui.button("▶").clicked() { // If stream thread is done, start again @@ -46,6 +47,8 @@ impl eframe::App for App { ui.add(egui::Slider::new(&mut self.player.volume, 0.0..=100.0).text("Volume")); self.player.sink.set_volume(self.player.volume / 100.0); + ui.label(format!("{:?}", self.player.get_song_meta())); + // ui.separator(); // ui.heading("Tor"); // if self.tor_started { diff --git a/src/main.rs b/src/main.rs index 70fb034..5ea51d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ -#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +// hide console window on Windows in release #[allow(dead_code)] pub use crate::player::Player; @@ -12,7 +13,6 @@ use rodio::{Decoder, OutputStream, source::Source, Sink}; mod app; mod player; - // "http://wowradiod6mhb4ignjqy5ghf5l42yh2yeumgeq3yi7gn7yqy3efhe5ad.onion" // "http://wowradiof5wx62w4avdk5fwbvcoea2z4ul2q3awffn5vmfaa3vhlgiid.onion" // "http://radio.poysibicsj73uhw7sjrv3fyopoyulrns4nlr5amyqdtafkqzlocd4qad.onion" diff --git a/src/player.rs b/src/player.rs index 655b78b..84d69fb 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,5 +1,4 @@ - - +use std::io::Read; pub struct Player { pub sink: rodio::Sink, pub stream_thread: std::thread::JoinHandle<()>, @@ -42,6 +41,16 @@ impl Player { } } + pub fn get_song_meta(&self) -> String { + let mut file = std::fs::File::open(&crate::RADIO_STREAM).unwrap(); + let mut buffer = [0u8; 384]; + file.read_exact(&mut buffer).unwrap(); + let s = std::string::String::from_utf8_lossy(&buffer); + let re = regex::Regex::new(r"title=(.*).{4}server=").unwrap(); + let caps = re.captures(&s).unwrap(); + return caps.get(1).map_or("", |m| m.as_str()).to_owned(); + } + pub fn get_radio_source(&self) -> rodio::Decoder> { Self::wait_for_source(); let file: std::io::BufReader = std::io::BufReader::new(std::fs::File::open(&crate::RADIO_STREAM).unwrap());