Simplify fetch
This commit is contained in:
parent
2a32fc8ea7
commit
b0ac9bf2c1
@ -4,9 +4,9 @@ use std::{
|
||||
};
|
||||
|
||||
use musichoard::collection::{
|
||||
album::AlbumMeta,
|
||||
album::{Album, AlbumMeta},
|
||||
artist::{Artist, ArtistId, ArtistMeta},
|
||||
musicbrainz::{IMusicBrainzRef, MbRefOption, Mbid},
|
||||
musicbrainz::{IMusicBrainzRef, MbArtistRef, MbRefOption, Mbid},
|
||||
};
|
||||
|
||||
use crate::tui::{
|
||||
@ -158,21 +158,10 @@ impl AppMachine<FetchState> {
|
||||
) -> Result<(), FetchError> {
|
||||
let requests = match artist.meta.info.musicbrainz {
|
||||
MbRefOption::Some(ref arid) => {
|
||||
let arid = arid.mbid();
|
||||
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()
|
||||
Self::fetch_albums_requests(&artist.meta.id, &arid, &artist.albums)
|
||||
}
|
||||
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() {
|
||||
return Err(FetchError::NothingToFetch);
|
||||
@ -180,6 +169,25 @@ impl AppMachine<FetchState> {
|
||||
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(
|
||||
musicbrainz: &dyn IMbJobSender,
|
||||
result_sender: ResultSender,
|
||||
|
Loading…
Reference in New Issue
Block a user