Separate metadata from collections #209
@ -158,6 +158,16 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
impl<T> Match<T> {
|
||||
pub fn new(score: u8, item: T) -> Self {
|
||||
Match {
|
||||
score,
|
||||
item,
|
||||
disambiguation: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn artist_matches_info_vec() -> Vec<AppMatchesInfo> {
|
||||
let artist_1 = ArtistMeta::new(ArtistId::new("Artist 1"));
|
||||
|
||||
@ -166,7 +176,7 @@ mod tests {
|
||||
|
||||
let artist_1_2 = artist_1.clone();
|
||||
let mut artist_match_1_2 = Match::new(100, artist_1_2);
|
||||
artist_match_1_2.set_disambiguation("some disambiguation");
|
||||
artist_match_1_2.disambiguation = Some(String::from("some disambiguation"));
|
||||
|
||||
let list = vec![artist_match_1_1.clone(), artist_match_1_2.clone()];
|
||||
let matches_info_1 = AppMatchesInfo::artist(artist_1.clone(), list);
|
||||
|
44
src/tui/lib/external/musicbrainz/mod.rs
vendored
44
src/tui/lib/external/musicbrainz/mod.rs
vendored
@ -1,8 +1,10 @@
|
||||
//! Module for interacting with the [MusicBrainz API](https://musicbrainz.org/doc/MusicBrainz_API).
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use musichoard::{
|
||||
collection::{
|
||||
album::{AlbumDate, AlbumMeta},
|
||||
album::{AlbumDate, AlbumMeta, AlbumSeq},
|
||||
artist::ArtistMeta,
|
||||
musicbrainz::Mbid,
|
||||
},
|
||||
@ -71,30 +73,32 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
|
||||
}
|
||||
|
||||
fn from_search_artist_response_artist(entity: SearchArtistResponseArtist) -> Match<ArtistMeta> {
|
||||
let mut artist = ArtistMeta::new(entity.name);
|
||||
if let Some(sort) = entity.sort {
|
||||
artist.set_sort_key(sort);
|
||||
Match {
|
||||
score: entity.score,
|
||||
item: ArtistMeta {
|
||||
id: entity.name.into(),
|
||||
sort: entity.sort.map(Into::into),
|
||||
musicbrainz: Some(entity.id.into()),
|
||||
properties: HashMap::new(),
|
||||
},
|
||||
disambiguation: entity.disambiguation,
|
||||
}
|
||||
artist.set_musicbrainz_ref(entity.id.into());
|
||||
|
||||
let mut artist_match = Match::new(entity.score, artist);
|
||||
if let Some(disambiguation) = entity.disambiguation {
|
||||
artist_match.set_disambiguation(disambiguation);
|
||||
}
|
||||
|
||||
artist_match
|
||||
}
|
||||
|
||||
fn from_search_release_group_response_release_group(
|
||||
entity: SearchReleaseGroupResponseReleaseGroup,
|
||||
) -> Match<AlbumMeta> {
|
||||
let mut album = AlbumMeta::new(
|
||||
entity.title,
|
||||
entity.first_release_date,
|
||||
Some(entity.primary_type),
|
||||
entity.secondary_types.unwrap_or_default(),
|
||||
);
|
||||
album.set_musicbrainz_ref(entity.id.into());
|
||||
Match::new(entity.score, album)
|
||||
Match {
|
||||
score: entity.score,
|
||||
item: AlbumMeta {
|
||||
id: entity.title.into(),
|
||||
date: entity.first_release_date,
|
||||
seq: AlbumSeq::default(),
|
||||
musicbrainz: Some(entity.id.into()),
|
||||
primary_type: Some(entity.primary_type),
|
||||
secondary_types: entity.secondary_types.unwrap_or_default(),
|
||||
},
|
||||
disambiguation: None,
|
||||
}
|
||||
}
|
||||
// GRCOV_EXCL_STOP
|
||||
|
@ -23,18 +23,4 @@ pub struct Match<T> {
|
||||
pub disambiguation: Option<String>,
|
||||
}
|
||||
|
||||
impl<T> Match<T> {
|
||||
pub fn new(score: u8, item: T) -> Self {
|
||||
Match {
|
||||
score,
|
||||
item,
|
||||
disambiguation: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_disambiguation<S: Into<String>>(&mut self, disambiguation: S) {
|
||||
self.disambiguation = Some(disambiguation.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub type Error = musichoard::external::musicbrainz::api::Error;
|
||||
|
Loading…
Reference in New Issue
Block a user