up to querying songfilehub

main
aprzn
parent 1587afc887
commit f87c61e382

@ -137,6 +137,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
[[package]]
name = "anyhow"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "arboard"
version = "3.2.0"
@ -768,6 +774,12 @@ dependencies = [
"web-sys",
]
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "emath"
version = "0.22.0"
@ -1214,6 +1226,15 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "itertools"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.9"
@ -1503,7 +1524,9 @@ dependencies = [
name = "nong_fisher"
version = "0.1.0"
dependencies = [
"anyhow",
"eframe",
"itertools",
"notify",
"serde",
"serde_json",

@ -6,7 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.75"
eframe = "0.22.0"
itertools = "0.11.0"
notify = "6.1.1"
serde = { version = "1.0.186", features = ["derive"] }
serde_json = "1.0.105"

@ -1,5 +1,5 @@
#![allow(dead_code)]
use std::{sync::mpsc, thread};
use std::{sync::mpsc, thread, collections::HashMap};
use eframe::{
egui::{CentralPanel, Context, Layout, TextFormat, Visuals},
@ -7,7 +7,9 @@ use eframe::{
epaint::{text::LayoutJob, Color32, FontId},
Frame,
};
use itertools::Itertools;
use serde::Deserialize;
use anyhow::Result;
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
@ -42,6 +44,7 @@ struct SfhResponse {
enum Event {
IdSubmit { id: String },
Error { description: String },
}
enum State {
@ -50,6 +53,7 @@ enum State {
struct App {
state: State,
error: Option<String>,
event_tx: mpsc::Sender<Event>,
event_rx: mpsc::Receiver<Event>,
}
@ -62,14 +66,13 @@ impl App {
search_string: String::new(),
enabled: true,
},
error: None,
event_tx,
event_rx,
}
}
fn update(&mut self, ctx: &Context, frame: &mut Frame) {
let mut events: Vec<Event> = vec![];
ctx.set_visuals(Visuals::light());
let mut title_text = LayoutJob::default();
title_text.append(
@ -96,15 +99,18 @@ impl App {
ui.with_layout(Layout::top_down(Align::Center), |ui| {
ui.label(title_text);
match &mut self.state {
State::IdSelect { search_string, enabled } => {
match (&self.error, &mut self.state) {
(Some(desc), _) => {
},
(None, State::IdSelect { search_string, enabled }) => {
ui.label("Enter level ID:");
ui.add_enabled_ui(*enabled, |ui| {
ui.text_edit_singleline(search_string).request_focus();
});
if *enabled {
if ui.button("submit").clicked() {
events.push(Event::IdSubmit { id: search_string.clone() });
self.event_tx.send(Event::IdSubmit { id: search_string.clone() });
}
} else {
ui.label("loading...");
@ -114,25 +120,51 @@ impl App {
});
});
for event in events {
while let Ok(event) = self.event_rx.try_recv() {
match event {
Event::IdSubmit { id } => {
let tx = self.event_tx.clone();
self.state = State::IdSelect { search_string: id.clone(), enabled: false };
thread::spawn(move || {
let res = ureq::post("http://www.boomlings.com/database/downloadGJLevel22.php")
.set("User-Agent", "")
.send_form(&[
("levelID", &id),
("secret", "Wmfd2893gb7"),
]);
match query_level_id(&tx, id) {
Ok(Some(song_desc)) => todo!(),
Ok(None) => todo!(),
Err(e) => todo!(),
}
});
},
Event::Error { description } => self.error = Some(description),
}
}
}
}
fn query_level_id(tx: &mpsc::Sender<Event>, id: String) -> Result<Option<SfhSong>> {
let level_desc = ureq::post("http://www.boomlings.com/database/downloadGJLevel22.php")
.set("User-Agent", "")
.send_form(&[
("levelID", &id),
("secret", "Wmfd2893gb7"),
])?
.into_string()?;
let level_desc_chunks = level_desc.split(':').chunks(2);
let mut map = HashMap::new();
for mut pair in &level_desc_chunks {
let key: i32 = pair.next().unwrap().parse().unwrap();
let value = pair.next().unwrap();
map.insert(key, value.to_owned());
}
let song_id = map.get(&35).unwrap();
let sfh_response: SfhResponse = ureq::get(&format!("https://songfilehub.com/api/v1/nongs?id={}", song_id))
.call()?
.into_json()?;
todo!()
}
fn main() {
let mut app = App::new();
eframe::run_simple_native("NONGfisher", Default::default(), move |ctx, frame| {

Loading…
Cancel
Save