Provide a keyboard shortcut to sync all existing albums with MusicBrainz #167

Merged
wojtek merged 13 commits from 166---provide-a-keyboard-shortcut-to-sync-all-existing-albums-with-musicbrainz into main 2024-08-27 17:55:53 +02:00
2 changed files with 26 additions and 9 deletions
Showing only changes of commit e9ca6ccdfe - Show all commits

View File

@ -2,6 +2,8 @@
pub mod client;
use std::fmt;
use serde::{de::DeserializeOwned, Deserialize};
use url::form_urlencoded;
@ -42,6 +44,15 @@ impl From<ClientError> for Error {
}
}
impl fmt::Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ClientError::Client(s) => write!(f, "the API client failed: {s}"),
ClientError::Status(u) => write!(f, "the API client failed with status: {u}"),
}
}
}
pub struct MusicBrainzApi<Mbc> {
client: Mbc,
}

View File

@ -7,13 +7,14 @@ use musichoard::{
};
use crate::tui::{
app::{
machine::{matches::AppMatchInfo, App, AppInner, AppMachine},
selection::{Delta, ListSelection},
AppPublic, AppState, IAppInteractBrowse,
},
lib::IMusicHoard, MUSICHOARD_TUI_HTTP_USER_AGENT,
};
app::{
machine::{matches::AppMatchInfo, App, AppInner, AppMachine},
selection::{Delta, ListSelection},
AppPublic, AppState, IAppInteractBrowse,
},
lib::IMusicHoard,
MUSICHOARD_TUI_HTTP_USER_AGENT,
};
pub struct AppBrowse;
@ -90,8 +91,13 @@ impl<MH: IMusicHoard> IAppInteractBrowse for AppMachine<MH, AppBrowse> {
}
fn fetch_musicbrainz(self) -> Self::APP {
let client = MusicBrainzApiClient::new(MUSICHOARD_TUI_HTTP_USER_AGENT)
.expect("failed to create API client");
let client = match MusicBrainzApiClient::new(MUSICHOARD_TUI_HTTP_USER_AGENT) {
Ok(client) => client,
Err(err) => {
return AppMachine::error(self.inner, format!("cannot fetch: {}", err.to_string()))
.into()
}
};
let mut api = MusicBrainzApi::new(client);
let coll = self.inner.music_hoard.get_collection();