main: make bandcamp command use bandcamp library to avoid panics
This commit is contained in:
+10
-9
@@ -14,7 +14,7 @@ use futures::{StreamExt, future::FutureExt};
|
||||
|
||||
use ratatui::prelude::*;
|
||||
|
||||
use crate::{events::AudioRecordRequest, prediction::PossibleResponse, scene::{ConversationEntry, PlaylistEntry, Scene, StageActions, StageDirection}, tts::start_tts};
|
||||
use crate::{events::AudioRecordRequest, prediction::{BandcampResult, PossibleResponse}, scene::{ConversationEntry, PlaylistEntry, Scene, StageActions, StageDirection}, tts::start_tts};
|
||||
|
||||
mod scene;
|
||||
mod events;
|
||||
@@ -364,7 +364,7 @@ impl App {
|
||||
} else {
|
||||
self.sys_message_sink.send("Invalid timer format. Use /timer [minutes]".into()).await.unwrap();
|
||||
}
|
||||
}
|
||||
},
|
||||
"/clear" => {
|
||||
match arg.trim() {
|
||||
"playlist" => {
|
||||
@@ -415,12 +415,14 @@ impl App {
|
||||
}
|
||||
|
||||
async fn add_bandcamp_artifact(&mut self, url: &str) {
|
||||
// FIXME: This can crash if the page doesn't load properly, or if the structure of the Bandcamp page changes. We should add some error handling here.
|
||||
let body = reqwest::get(url).await.unwrap().text().await.unwrap();
|
||||
let fragment = Html::parse_document(&body);
|
||||
let selector = Selector::parse("script[type=\"application/ld+json\"]").unwrap();
|
||||
let json_ld = fragment.select(&selector).next().unwrap().inner_html();
|
||||
self.direction.artifacts.push(json_ld.trim().to_string());
|
||||
if let Ok(album) = bandcamp::album_from_url(url).await {
|
||||
let result: BandcampResult = album.into();
|
||||
let json = serde_json::to_string(&result).unwrap();
|
||||
self.direction.artifacts.push(json);
|
||||
self.sys_message_sink.send("Added bandcamp album".into()).await.unwrap();
|
||||
} else {
|
||||
self.sys_message_sink.send("Could not fetch bandcamp data! Is that a proper URL?".into()).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
async fn speak(&mut self, text: String) {
|
||||
@@ -436,7 +438,6 @@ impl App {
|
||||
self.scene.conversation_mut().append(&mut actions.additions.clone());
|
||||
self.prediction_request_sink.send(actions).unwrap();
|
||||
self.is_requesting = true;
|
||||
panic!("at the disco");
|
||||
}
|
||||
|
||||
fn reload_mixxx_playlist(&mut self) {
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ struct BandcampQueryArgs {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
enum BandcampResult {
|
||||
pub enum BandcampResult {
|
||||
Artist { name: String, bio: Option<String>, location: Option<String> },
|
||||
Album { title: String, about: Option<String>, credits: Option<String>, release_date: DateTime<Utc>, artist: String }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user