82 lines
2.1 KiB
Rust
82 lines
2.1 KiB
Rust
use musichoard::{
|
|
collection::musicbrainz::Mbid,
|
|
external::musicbrainz::{
|
|
api::{
|
|
lookup::{LookupArtistRequest, LookupReleaseGroupRequest},
|
|
MusicBrainzClient,
|
|
},
|
|
http::MusicBrainzHttp,
|
|
},
|
|
};
|
|
use structopt::StructOpt;
|
|
use uuid::Uuid;
|
|
|
|
const USER_AGENT: &str = concat!(
|
|
"MusicHoard---examples---musicbrainz-api---lookup/",
|
|
env!("CARGO_PKG_VERSION"),
|
|
" ( musichoard@thenineworlds.net )"
|
|
);
|
|
|
|
#[derive(StructOpt)]
|
|
struct Opt {
|
|
#[structopt(subcommand)]
|
|
entity: OptEntity,
|
|
}
|
|
|
|
#[derive(StructOpt)]
|
|
enum OptEntity {
|
|
#[structopt(about = "Lookup artist")]
|
|
Artist(OptArtist),
|
|
#[structopt(about = "Lookup release group")]
|
|
ReleaseGroup(OptReleaseGroup),
|
|
}
|
|
|
|
#[derive(StructOpt)]
|
|
struct OptArtist {
|
|
#[structopt(help = "Artist MBID to lookup")]
|
|
mbid: Uuid,
|
|
#[structopt(long, help = "Include release groups in lookup")]
|
|
release_groups: bool,
|
|
}
|
|
|
|
#[derive(StructOpt)]
|
|
struct OptReleaseGroup {
|
|
#[structopt(help = "Release group MBID to lookup")]
|
|
mbid: Uuid,
|
|
}
|
|
|
|
fn main() {
|
|
let opt = Opt::from_args();
|
|
|
|
println!("USER_AGENT: {USER_AGENT}");
|
|
|
|
let http = MusicBrainzHttp::new(USER_AGENT).expect("failed to create API client");
|
|
let mut client = MusicBrainzClient::new(http);
|
|
|
|
match opt.entity {
|
|
OptEntity::Artist(opt_artist) => {
|
|
let mbid: Mbid = opt_artist.mbid.into();
|
|
let mut request = LookupArtistRequest::new(&mbid);
|
|
if opt_artist.release_groups {
|
|
request.include_release_groups();
|
|
}
|
|
|
|
let response = client
|
|
.lookup_artist(request)
|
|
.expect("failed to make API call");
|
|
|
|
println!("{response:#?}");
|
|
}
|
|
OptEntity::ReleaseGroup(opt_release_group) => {
|
|
let mbid: Mbid = opt_release_group.mbid.into();
|
|
let request = LookupReleaseGroupRequest::new(&mbid);
|
|
|
|
let response = client
|
|
.lookup_release_group(request)
|
|
.expect("failed to make API call");
|
|
|
|
println!("{response:#?}");
|
|
}
|
|
}
|
|
}
|