Enable fetch to apply modifications to the database #221
@ -4,9 +4,9 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use musichoard::collection::{
|
use musichoard::collection::{
|
||||||
album::AlbumMeta,
|
album::{Album, AlbumMeta},
|
||||||
artist::{Artist, ArtistId, ArtistMeta},
|
artist::{Artist, ArtistId, ArtistMeta},
|
||||||
musicbrainz::{IMusicBrainzRef, MbRefOption, Mbid},
|
musicbrainz::{IMusicBrainzRef, MbArtistRef, MbRefOption, Mbid},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tui::{
|
use crate::tui::{
|
||||||
@ -158,21 +158,10 @@ impl AppMachine<FetchState> {
|
|||||||
) -> Result<(), FetchError> {
|
) -> Result<(), FetchError> {
|
||||||
let requests = match artist.meta.info.musicbrainz {
|
let requests = match artist.meta.info.musicbrainz {
|
||||||
MbRefOption::Some(ref arid) => {
|
MbRefOption::Some(ref arid) => {
|
||||||
let arid = arid.mbid();
|
Self::fetch_albums_requests(&artist.meta.id, &arid, &artist.albums)
|
||||||
let albums = artist.albums.iter();
|
|
||||||
albums
|
|
||||||
.filter(|album| matches!(album.meta.info.musicbrainz, MbRefOption::None))
|
|
||||||
.map(|album| {
|
|
||||||
MbParams::search_release_group(
|
|
||||||
artist.meta.id.clone(),
|
|
||||||
arid.clone(),
|
|
||||||
album.meta.clone(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
MbRefOption::CannotHaveMbid => VecDeque::new(),
|
MbRefOption::CannotHaveMbid => VecDeque::new(),
|
||||||
MbRefOption::None => VecDeque::from([MbParams::search_artist(artist.meta.clone())]),
|
MbRefOption::None => Self::fetch_artist_request(&artist.meta),
|
||||||
};
|
};
|
||||||
if requests.is_empty() {
|
if requests.is_empty() {
|
||||||
return Err(FetchError::NothingToFetch);
|
return Err(FetchError::NothingToFetch);
|
||||||
@ -180,6 +169,25 @@ impl AppMachine<FetchState> {
|
|||||||
Ok(musicbrainz.submit_background_job(result_sender, requests)?)
|
Ok(musicbrainz.submit_background_job(result_sender, requests)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fetch_albums_requests(
|
||||||
|
artist: &ArtistId,
|
||||||
|
arid: &MbArtistRef,
|
||||||
|
albums: &[Album],
|
||||||
|
) -> VecDeque<MbParams> {
|
||||||
|
let arid = arid.mbid();
|
||||||
|
albums
|
||||||
|
.iter()
|
||||||
|
.filter(|album| matches!(album.meta.info.musicbrainz, MbRefOption::None))
|
||||||
|
.map(|album| {
|
||||||
|
MbParams::search_release_group(artist.clone(), arid.clone(), album.meta.clone())
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fetch_artist_request(meta: &ArtistMeta) -> VecDeque<MbParams> {
|
||||||
|
VecDeque::from([MbParams::search_artist(meta.clone())])
|
||||||
|
}
|
||||||
|
|
||||||
fn submit_lookup_artist_job(
|
fn submit_lookup_artist_job(
|
||||||
musicbrainz: &dyn IMbJobSender,
|
musicbrainz: &dyn IMbJobSender,
|
||||||
result_sender: ResultSender,
|
result_sender: ResultSender,
|
||||||
|
Loading…
Reference in New Issue
Block a user