i guess i have add

irc-tor
lza_menace 2 years ago
parent a8bd952ce3
commit ca4d12377b

@ -2,8 +2,10 @@
use std::{thread, io, fs, time};
use libtor::{Tor, TorFlag, Error as libtorError, log as libtorLog};
use rodio::{Decoder, OutputStream, source::Source, Sink};
use eframe::egui;
#[allow(unused_imports)]
use rodio::{Decoder, OutputStream, source::Source, Sink};
// "http://wowradiod6mhb4ignjqy5ghf5l42yh2yeumgeq3yi7gn7yqy3efhe5ad.onion"
// "http://wowradiof5wx62w4avdk5fwbvcoea2z4ul2q3awffn5vmfaa3vhlgiid.onion"
@ -13,6 +15,14 @@ use eframe::egui;
// "https://radio.wownero.com/wow.ogg"
const TOR_LOG: &str = &"/tmp/tor-rust/tor.log";
const RADIO_STREAM: &str = &"radio.ogg";
fn cleanup() {
let r: io::Result<()> = fs::remove_file(&RADIO_STREAM);
match r {
_ => ()
}
}
fn start_tor() -> thread::JoinHandle<Result<u8, libtorError>> {
let t: thread::JoinHandle<_> = Tor::new()
@ -42,31 +52,40 @@ fn get_wow_price() -> String {
return res
}
fn get_radio_sink() -> Sink {
thread::spawn(|| {
fn start_radio_stream() -> thread::JoinHandle<()> {
let t: Result<thread::JoinHandle<()>, io::Error> = thread::Builder::new().name("radio_stream".to_string()).spawn(move || {
let mut res: reqwest::blocking::Response = reqwest::blocking::get("https://radio.wownero.com/wow.ogg").expect("request failed");
let mut out: fs::File = fs::File::create("woww.ogg").expect("failed to create file");
let mut out: fs::File = fs::File::create(RADIO_STREAM).expect("failed to create file");
io::copy(&mut res, &mut out).expect("failed to copy content");
});
std::thread::sleep(std::time::Duration::from_secs(3));
return t.unwrap()
}
fn get_radio_source() -> Decoder<io::BufReader<fs::File>> {
// let _: fs::File = fs::File::create(RADIO_STREAM).expect("failed to create file");
let file: io::BufReader<fs::File> = io::BufReader::new(fs::File::open(RADIO_STREAM).unwrap());
let source: Decoder<io::BufReader<fs::File>> = Decoder::new(file).unwrap();
return source
}
fn get_radio_sink() -> Sink {
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
let file: io::BufReader<fs::File> = io::BufReader::new(fs::File::open("woww.ogg").unwrap());
let source: Decoder<io::BufReader<fs::File>> = Decoder::new(file).unwrap();
sink.append(source);
return sink
}
struct LzaGUI {
tor_started: bool,
to_data: String
to_data: String,
sink: Sink
}
impl Default for LzaGUI {
fn default() -> Self {
Self {
tor_started: false,
to_data: "".to_owned()
to_data: "".to_owned(),
sink: get_radio_sink()
}
}
}
@ -75,21 +94,35 @@ impl eframe::App for LzaGUI {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("lza gui");
let texture: egui::TextureHandle = ui.ctx().load_texture(
"rainbow",
egui::ColorImage::example(),
egui::TextureFilter::Linear
);
ui.add(egui::Image::new(texture.id(), texture.size_vec2()));
ui.label("Made by ya boi, lza_menace");
ui.hyperlink("https://lzahq.tech");
ui.separator();
if ui.button("Play WOW!Radio").clicked() {
println!("Playing radio...");
let sink: Sink = get_radio_sink();
sink.play();
}
// ui.separator();
ui.horizontal(|ui| {
if ui.button("▶").clicked() {
let t: thread::JoinHandle<()> = start_radio_stream();
println!("Starting radio...streaming thread {:?}", t.thread());
thread::sleep(time::Duration::from_secs(3));
let source: Decoder<io::BufReader<fs::File>> = get_radio_source();
let _ = &self.sink.append(source);
let _ = &self.sink.play();
}
if ui.button("■").clicked() {
let _ = &self.sink.pause();
}
if ui.button("status").clicked() {
println!(
"is_paused: {}. empty: {}. len: {}. volume: {}.",
&self.sink.is_paused(),
&self.sink.empty(),
&self.sink.len(),
&self.sink.volume()
)
}
});
ui.separator();
if ui.button("Get TO Market Data").clicked() {
@ -128,4 +161,5 @@ fn main() {
options,
Box::new(|_cc| Box::new(LzaGUI::default())),
);
let _ = cleanup();
}