parent
0d7e6bb555
commit
e5a367aa90
@ -48,8 +48,8 @@ name = "musichoard-edit"
|
||||
required-features = ["bin", "database-json"]
|
||||
|
||||
[[example]]
|
||||
name = "musicbrainz-api---lookup-artist"
|
||||
path = "examples/musicbrainz_api/lookup_artist.rs"
|
||||
name = "musicbrainz-api---lookup"
|
||||
path = "examples/musicbrainz_api/lookup.rs"
|
||||
required-features = ["bin", "musicbrainz"]
|
||||
|
||||
[[example]]
|
||||
|
83
examples/musicbrainz_api/lookup.rs
Normal file
83
examples/musicbrainz_api/lookup.rs
Normal file
@ -0,0 +1,83 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
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:#?}");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use musichoard::{
|
||||
collection::musicbrainz::Mbid,
|
||||
external::musicbrainz::{
|
||||
api::{lookup::LookupArtistRequest, MusicBrainzClient},
|
||||
http::MusicBrainzHttp,
|
||||
},
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
use uuid::Uuid;
|
||||
|
||||
const USER_AGENT: &str = concat!(
|
||||
"MusicHoard---examples---musicbrainz-api---lookup-artist/",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
" ( musichoard@thenineworlds.net )"
|
||||
);
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct Opt {
|
||||
#[structopt(help = "Artist 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);
|
||||
|
||||
let mbid: Mbid = opt.mbid.into();
|
||||
let mut request = LookupArtistRequest::new(&mbid);
|
||||
request.include_release_groups();
|
||||
|
||||
let response = client
|
||||
.lookup_artist(request)
|
||||
.expect("failed to make API call");
|
||||
|
||||
println!("{response:#?}");
|
||||
}
|
Loading…
Reference in New Issue
Block a user