musicbrainz_rs 0.2.0

MusicBrainz Rust is a utility crate for the the MusicBrainz API.
Documentation

MusicBrainz rust is a utility crate for the the MusicBrainz API.


you may be looking for :

Features

Fetch query

To perform a lookups via fetch queries, you need to import the Fetch trait.

extern crate musicbrainz_rs;

use musicbrainz_rs::model::artist;
use musicbrainz_rs::model::artist::*;
use musicbrainz_rs::Fetch;

fn main() {
    let nirvana = Artist::fetch()
        .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da")
        .execute();

    assert_eq!(nirvana.unwrap().name, "Nirvana".to_string());
}

Include parameters

You can also use includes to get more detail about a resource :

Every Musicbrainz resource has allowed include parameters. To enforce safe and valid queries we enforce correctess with rust enums. For example if you want to get tag and ratings on a fetch label query you need to import musicbrainz_rs::model::label::Include

extern crate musicbrainz_rs;

use musicbrainz_rs::model::label;
use musicbrainz_rs::model::label::*;
use musicbrainz_rs::Fetch;

fn main() {
    let ninja_tune = Label::fetch()
        .id("dc940013-b8a8-4362-a465-291026c04b42")
        .include(label::Include::Tags)
        .include(label::Include::Rating)
        .execute()
        .unwrap();

    assert!(ninja_tune
        .tags
        .unwrap()
        .iter()
        .any(|tag| tag.name == "independent"));

    assert!(ninja_tune.rating.is_some());
}

Browse query

Use musicbrainz_rs::Browse to perform a browse query. Just like Include every muscibrainz resource has allowable linked entities for such queries. Use the Browse enum coresponding to the entity you need to lookup.

extern crate musicbrainz_rs;

use musicbrainz_rs::model::artist;
use musicbrainz_rs::model::artist::Artist;
use musicbrainz_rs::Browse;

fn main() {
    let artists_on_in_utero_release = Artist::browse()
        .by(
            artist::Browse::Release,
            "18d4e9b4-9247-4b44-914a-8ddec3502103",
        )
        .execute();

    let artists_on_in_utero_release = artists_on_in_utero_release.unwrap();
    artists_on_in_utero_release
        .entities
        .iter()
        .for_each(|artist| println!("{:?}", artist.name));
}

Custom user agent

You can set your application user-agent as recommended in the musicbrainz documentation :

fn main() {
    musicbrainz_rs::config::set_user_agent("my_awesome_app/1.0");

    let nirvana = Artist::fetch()
        .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da")
        .execute();

    assert_eq!(nirvana.unwrap().name, "Nirvana".to_string());
}

Examples

To see what is currently implemented in the crate you can look at the tests directory.

You can run examples with cargo run --example example_name

Contributing

All contributions are welcome, if find a bug or have a feature request don't hesitate to open an issue!

Credits

Most of this crate documentation is taken from the official MusicBrainz doc, thanks to the MetaBrainz Foundation and its sponsors and supporters. Cover Art provided by the Cover Art Archive.