Search by RGID if available
This commit is contained in:
parent
3ed13ca0e9
commit
e008bf1b10
@ -21,6 +21,20 @@ struct Opt {
|
||||
#[structopt(help = "Release group's artist MBID")]
|
||||
arid: Uuid,
|
||||
|
||||
#[structopt(subcommand)]
|
||||
command: OptCommand,
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
enum OptCommand {
|
||||
#[structopt(about = "Search by title (and date)")]
|
||||
Title(OptTitle),
|
||||
#[structopt(about = "Search by release group MBID")]
|
||||
Rgid(OptRgid),
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct OptTitle {
|
||||
#[structopt(help = "Release group title")]
|
||||
title: String,
|
||||
|
||||
@ -28,6 +42,12 @@ struct Opt {
|
||||
date: Option<Date>,
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct OptRgid {
|
||||
#[structopt(help = "Release group MBID")]
|
||||
rgid: Uuid,
|
||||
}
|
||||
|
||||
struct Date(AlbumDate);
|
||||
|
||||
impl FromStr for Date {
|
||||
@ -64,8 +84,24 @@ fn main() {
|
||||
let mut api = MusicBrainzApi::new(client);
|
||||
|
||||
let arid: Mbid = opt.arid.into();
|
||||
let date: AlbumDate = opt.date.map(Into::into).unwrap_or_default();
|
||||
let album = Album::new(AlbumId::new(opt.title), date, None, vec![]);
|
||||
|
||||
let album = match opt.command {
|
||||
OptCommand::Title(opt_title) => {
|
||||
let date: AlbumDate = opt_title.date.map(Into::into).unwrap_or_default();
|
||||
Album::new(AlbumId::new(opt_title.title), date, None, vec![])
|
||||
}
|
||||
OptCommand::Rgid(opt_rgid) => {
|
||||
let mut album = Album::new(
|
||||
AlbumId::new(String::default()),
|
||||
AlbumDate::default(),
|
||||
None,
|
||||
vec![],
|
||||
);
|
||||
album.set_musicbrainz_ref(opt_rgid.rgid.into());
|
||||
album
|
||||
}
|
||||
};
|
||||
|
||||
let matches = api
|
||||
.search_release_group(&arid, album)
|
||||
.expect("failed to make API call");
|
||||
|
15
src/external/musicbrainz/api/mod.rs
vendored
15
src/external/musicbrainz/api/mod.rs
vendored
@ -11,7 +11,7 @@ use mockall::automock;
|
||||
use crate::core::{
|
||||
collection::{
|
||||
album::{Album, AlbumDate, AlbumPrimaryType, AlbumSecondaryType},
|
||||
musicbrainz::MbAlbumRef,
|
||||
musicbrainz::{IMusicBrainzRef, MbAlbumRef},
|
||||
},
|
||||
interface::musicbrainz::{Error, IMusicBrainz, Match, Mbid},
|
||||
};
|
||||
@ -74,11 +74,20 @@ impl<Mbc: IMusicBrainzApiClient> IMusicBrainz for MusicBrainzApi<Mbc> {
|
||||
) -> Result<Vec<Match<Album>>, Error> {
|
||||
let title = &album.id.title;
|
||||
let arid = arid.uuid().as_hyphenated().to_string();
|
||||
let mut query = format!("releasegroup:\"{title}\" AND arid:{arid}");
|
||||
let mut query = format!("arid:{arid}");
|
||||
|
||||
match album.musicbrainz {
|
||||
Some(mbref) => {
|
||||
let rgid = mbref.mbid().uuid().as_hyphenated().to_string();
|
||||
query.push_str(&format!(" AND rgid:{rgid}"));
|
||||
}
|
||||
None => {
|
||||
query.push_str(&format!(" AND releasegroup:\"{title}\""));
|
||||
if let Some(year) = album.date.year {
|
||||
query.push_str(&format!(" AND firstreleasedate:{year}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let query: String = form_urlencoded::byte_serialize(query.as_bytes()).collect();
|
||||
|
||||
@ -292,7 +301,7 @@ mod tests {
|
||||
let url = format!(
|
||||
"https://musicbrainz.org/ws/2\
|
||||
/release-group\
|
||||
?query=releasegroup%3A%22{title}%22+AND+arid%3A{arid}+AND+firstreleasedate%3A{year}",
|
||||
?query=arid%3A{arid}+AND+releasegroup%3A%22{title}%22+AND+firstreleasedate%3A{year}",
|
||||
title = "an+album",
|
||||
arid = "00000000-0000-0000-0000-000000000000",
|
||||
year = "1986"
|
||||
|
Loading…
Reference in New Issue
Block a user