### Complete Example: Browse Artists and Releases Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md A comprehensive example demonstrating synchronous browsing of artists by release and releases by label, including include methods and pagination. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::entity::release::Release; use musicbrainz_rs::prelude::*; #[cfg(feature = "sync")] fn main() -> Result<(), musicbrainz_rs::ApiEndpointError> { // Browse artists on a specific release let in_utero_artists = Artist::browse() .by_release("18d4e9b4-9247-4b44-914a-8ddec3502103") .with_annotation() .with_aliases() .execute()?; println!("Artists on 'In Utero': {}", in_utero_artists.count); for artist in in_utero_artists.entities { println!(" - {}", artist.name); } // Browse releases by label with pagination let ubiktune_releases = Release::browse() .by_label("47e718e1-7ee4-460c-b1cc-1192a841c6e5") .limit(20) .offset(0) .execute()?; println!("Found {} releases on Ubiktune", ubiktune_releases.count); Ok(()) } ``` -------------------------------- ### Complete Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/fetch-query.md A comprehensive example showing how to fetch an artist with and without includes. ```APIDOC ## Complete Example ### Description This example demonstrates fetching a single artist by MBID and then fetching another artist with additional relations and recordings. ### Method `Artist::fetch()` ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; #[cfg(feature = "sync")] fn main() -> Result<(), musicbrainz_rs::ApiEndpointError> { // Fetch a single artist by MBID let nirvana = Artist::fetch() .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da") .execute()?; println!("Artist: {}", nirvana.name); // Fetch with additional relations and recordings let radiohead = Artist::fetch() .id("e0ce2b6a-7a37-4af8-8aba-5c6f92eb1f1f") .with_recordings() .with_releases() .with_aliases() .execute()?; println!("Albums: {}", radiohead.releases.unwrap_or_default().len()); Ok(()) } ``` ### Response #### Success Response Prints the artist's name and the number of releases for the second artist. #### Response Example ``` Artist: Nirvana Albums: 15 ``` ``` -------------------------------- ### Complete Example: Synchronous Search and Query Builder Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md A comprehensive example demonstrating both simple text search and structured query builder usage for artists, including outputting results. Requires the `sync` feature. ```rust use musicbrainz_rs::entity::artist::{Artist, ArtistSearchQuery}; use musicbrainz_rs::prelude::*; #[cfg(feature = "sync")] fn main() -> Result<(), musicbrainz_rs::ApiEndpointError> { // Simple text search let results = Artist::search("Radiohead".to_string()) .limit(5) .execute()?; println!("Found {} artists matching 'Radiohead'", results.count); for artist in results.entities { println!(" - {} (score: {})", artist.name, artist.score.unwrap_or(0)); } // Structured query search let query = ArtistSearchQuery::query_builder() .artist("Miles Davis") .and() .country("US") .build(); let results = Artist::search(query) .limit(10) .offset(0) .execute()?; println!("Found {} American Miles Davis artists", results.count); Ok(()) } ``` -------------------------------- ### Complete Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md A comprehensive example showcasing both simple text searches and structured query searches for artists, including pagination. ```APIDOC ## Complete Example ### Description Illustrates a complete usage scenario for searching artists, covering both basic text-based searches and advanced structured queries with pagination. ### Method Synchronous function calls ### Endpoint N/A (SDK methods) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use musicbrainz_rs::entity::artist::{Artist, ArtistSearchQuery}; use musicbrainz_rs::prelude::*; #[cfg(feature = "sync")] fn main() -> Result<(), musicbrainz_rs::ApiEndpointError> { // Simple text search let results = Artist::search("Radiohead".to_string()) .limit(5) .execute()?; println!("Found {} artists matching 'Radiohead'", results.count); for artist in results.entities { println!(" - {} (score: {})", artist.name, artist.score.unwrap_or(0)); } // Structured query search let query = ArtistSearchQuery::query_builder() .artist("Miles Davis") .and() .country("US") .build(); let results = Artist::search(query) .limit(10) .offset(0) .execute()?; println!("Found {} American Miles Davis artists", results.count); Ok(()) } ``` ### Response #### Success Response `SearchResult` — Contains the search results for artists. #### Response Example (See individual examples for specific response structures) ``` -------------------------------- ### Complete Synchronous Artist Fetch Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/fetch-query.md A complete example demonstrating synchronous fetching of a single artist by MBID and another artist with additional relations and recordings. Requires the 'sync' feature. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; #[cfg(feature = "sync")] fn main() -> Result<(), musicbrainz_rs::ApiEndpointError> { // Fetch a single artist by MBID let nirvana = Artist::fetch() .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da") .execute()?; println!("Artist: {}", nirvana.name); // Fetch with additional relations and recordings let radiohead = Artist::fetch() .id("e0ce2b6a-7a37-4af8-8aba-5c6f92eb1f1f") .with_recordings() .with_releases() .with_aliases() .execute() ?; println!("Albums: {}", radiohead.releases.unwrap_or_default().len()); Ok(()) } ``` -------------------------------- ### Basic Fetch Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/README.md Demonstrates how to perform a basic fetch operation to retrieve an artist by their MBID. ```APIDOC ## Basic Fetch ### Description Retrieves a specific entity using its MusicBrainz Identifier (MBID). ### Method Not applicable (Rust SDK method) ### Endpoint Not applicable (Rust SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let artist = Artist::fetch() .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da") .execute()?; ``` ### Response #### Success Response Returns the requested entity (e.g., Artist) if found. #### Response Example (Varies based on entity type) ``` -------------------------------- ### Download Album Cover Art Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/PRACTICAL-GUIDE.md Fetches and simulates downloading album cover art for a given release ID. This example shows how to get the cover art metadata and then construct the URL for the image, but actual download requires an HTTP client. ```rust use musicbrainz_rs::entity::release::Release; use musicbrainz_rs::entity::CoverartResponse; use musicbrainz_rs::prelude::*; use std::io::Write; fn download_cover_art( release_id: &str, output_path: &str, ) -> Result<(), Box> { // Get the cover art metadata let coverart = Release::fetch_coverart() .id(release_id) .execute()?; // Get the JSON metadata to find the front cover if let CoverartResponse::Json(metadata) = coverart { if let Some(front_image) = metadata.images.iter().find(|img| img.front) { // Get the actual image URL let image_url = Release::fetch_coverart() .id(release_id) .front() .res_500() .execute()?; if let CoverartResponse::Url(url) = image_url { println!("Downloading from: {}", url); // In a real application, you would use reqwest or similar // to download the image from the URL println!("Would download to: {}", output_path); } } } Ok(()) } fn main() -> Result<(), Box> { let in_utero = "76df3287-6cda-33eb-8e9a-044b5e15ffdd"; download_cover_art(in_utero, "./in_utero_cover.jpg")?; Ok(()) } ``` -------------------------------- ### Basic Production Setup Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/configuration.md Demonstrates creating a MusicBrainz client with a custom user agent and fetching artist data. Ensure you have the `async` feature enabled. ```rust use musicbrainz_rs::client::MusicBrainzClient; use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; fn main() -> Result<(), Box> { // Create a client with your application's user agent let client = MusicBrainzClient::new( "MusicFinder/1.2.0 (https://musicfinder.example.com)" ); let artist = Artist::fetch() .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da") .execute_with_client(&client)?; println!("Artist: {}", artist.name); Ok(()) } ``` -------------------------------- ### Release Fetch Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/entity-types.md Demonstrates fetching a Release entity with include methods for related data like media, recordings, and artist credits. ```APIDOC ## Fetch Release ### Description Fetches a specific release by its MBID and includes related information. ### Method `Release::fetch()` ### Endpoint Not directly represented in this SDK method, but corresponds to a MusicBrainz API lookup. ### Parameters - `id` (String) - Required - The MBID of the release to fetch. - `with_media()` - Optional - Include media information. - `with_recordings()` - Optional - Include recordings. - `with_labels()` - Optional - Include labels. - `with_artist_credits()` - Optional - Include artist credits. - `with_aliases()` - Optional - Include aliases. - `with_tags()` - Optional - Include tags. - `with_rating()` - Optional - Include rating. - `with_genres()` - Optional - Include genres. - `with_annotations()` - Optional - Include annotations. ### Request Example ```rust let release = Release::fetch() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .with_media() .with_recordings() .execute()?; ``` ### Response #### Success Response - `Release` object containing release details and included data. ``` -------------------------------- ### Initiate Artist Search Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md Example of initiating a search for Artist entities using the `search` method. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let query_str = "Miles Davis".to_string(); let search_query = Artist::search(query_str); ``` -------------------------------- ### Pagination Example: Browse All Pages Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md Implements pagination for browse queries by iteratively fetching data with `limit()` and `offset()` until no more entities are returned. ```rust fn browse_all_pages( release_id: &str ) -> Result, Box> { let mut all_artists = Vec::new(); let page_size = 100u8; let mut offset = 0u16; loop { let results = Artist::browse() .by_release(release_id) .limit(page_size) .offset(offset) .execute()?; if results.entities.is_empty() { break; } all_artists.extend(results.entities); offset += page_size as u16; } Ok(all_artists) } ``` -------------------------------- ### Initiate Artist Browse Query Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md Example of initiating a browse query for Artist entities using the `Browse` trait. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let browse_query = Artist::browse(); ``` -------------------------------- ### Release Browse Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/entity-types.md Shows how to browse for releases related to other entities like labels, release groups, or artists. ```APIDOC ## Browse Releases ### Description Browses for releases based on relationships to other entities. ### Method `Release::browse()` ### Endpoint Not directly represented in this SDK method, but corresponds to a MusicBrainz API browse endpoint. ### Parameters - `by_label(String)` - Optional - Browse releases by label MBID. - `by_release_group(String)` - Optional - Browse releases by release group MBID. - `by_artist(String)` - Optional - Browse releases by artist MBID. - `by_area(String)` - Optional - Browse releases by area MBID. - `by_track_artist(String)` - Optional - Browse releases by track artist MBID. ### Request Example ```rust let releases = Release::browse() .by_label("47e718e1-7ee4-460c-b1cc-1192a841c6e5") .execute()?; ``` ### Response #### Success Response - A list of `Release` objects matching the browse criteria. ``` -------------------------------- ### Release Cover Art Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/entity-types.md Demonstrates how to fetch cover art for a release, specifying front cover and resolution. ```APIDOC ## Fetch Release Cover Art ### Description Fetches cover art for a specific release. ### Method `Release::fetch_coverart()` ### Endpoint Not directly represented in this SDK method, but corresponds to a MusicBrainz Cover Art API endpoint. ### Parameters - `id` (String) - Required - The MBID of the release to fetch cover art for. - `front()` - Optional - Request the front cover art. - `res_500()` - Optional - Request a 500px resolution image. ### Request Example ```rust let coverart = Release::fetch_coverart() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .front() .res_500() .execute()?; ``` ### Response #### Success Response - `CoverartResponse::Url(String)` - The URL of the cover art image. ``` -------------------------------- ### FetchCoverart Trait Usage Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/coverart-query.md Demonstrates how to use the FetchCoverart trait to get cover art queries for a Release, both statically and from an instance. ```rust use musicbrainz_rs::entity::release::Release; use musicbrainz_rs::prelude::*; // Static method let coverart_query = Release::fetch_coverart(); // Instance method let release = Release::fetch() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .execute()?; let coverart_query = release.get_coverart(); ``` -------------------------------- ### Artist Fetch Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/entity-types.md Demonstrates how to fetch an Artist entity with various include methods to retrieve related information such as recordings, releases, and aliases. ```APIDOC ## Fetch Artist ### Description Fetches a specific artist by its MBID and includes related data. ### Method `Artist::fetch()` ### Endpoint Not directly represented in this SDK method, but corresponds to a MusicBrainz API lookup. ### Parameters - `id` (String) - Required - The MBID of the artist to fetch. - `with_recordings()` - Optional - Include recordings. - `with_releases()` - Optional - Include releases. - `with_releases_and_discids()` - Optional - Include releases and discids. - `with_release_groups()` - Optional - Include release groups. - `with_aliases()` - Optional - Include aliases. - `with_works()` - Optional - Include works. - `with_tags()` - Optional - Include tags. - `with_rating()` - Optional - Include rating. - `with_genres()` - Optional - Include genres. - `with_annotations()` - Optional - Include annotations. ### Request Example ```rust let artist = Artist::fetch() .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da") .with_recordings() .with_releases() .execute()?; ``` ### Response #### Success Response - `Artist` object containing artist details and included data. ``` -------------------------------- ### Artist Search Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md Demonstrates how to search for artists using their name and retrieve results. ```APIDOC ## Artist::search ### Description Initiates a search query for Artist entities using a provided query string. ### Method `Artist::search(query: String) -> SearchQuery` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let query_str = "Miles Davis".to_string(); let search_query = Artist::search(query_str); ``` ### Response Returns a `SearchQuery` object that can be further configured and executed. ``` -------------------------------- ### Perform a Search Query for Artists Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/README.md This example shows how to construct and execute a search query for artists, filtering by artist name and country. It also demonstrates setting a custom user agent. Ensure `musicbrainz_rs::entity::artist::Artist` and `musicbrainz_rs::prelude::*` are imported. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; fn main() { musicbrainz_rs::config::set_user_agent("my_awesome_app/1.0"); let query = Artist::query_builder() .artist("Miles Davis") .and() .country("US") .build(); let query_result = Artist::search(query).execute().unwrap(); let query_result: Vec = query_result.entities .iter() .map(|artist| artist.name.clone()).collect(); assert!(query_result.contains(&"Miles Davis".to_string())); assert!(query_result.contains(&"Miles Davis Quintet".to_string())); } ``` -------------------------------- ### Execute Synchronous Search with Client Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md Example of executing a search query synchronously using a provided MusicBrainzClient instance. ```rust use musicbrainz_rs::client::MusicBrainzClient; use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let client = MusicBrainzClient::new("MyApp/1.0.0"); let results = Artist::search("Miles Davis".to_string()) .execute_with_client(&client)?; ``` -------------------------------- ### Execute Synchronous Browse Query Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md Example of executing a browse query synchronously and iterating over the results. Requires the `sync` feature. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let results = Artist::browse() .by_release("18d4e9b4-9247-4b44-914a-8ddec3502103") .execute()?; for artist in results.entities { println!("{}", artist.name); } ``` -------------------------------- ### Search Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/README.md Illustrates how to perform a full-text search for artists, with an option to limit the number of results. ```APIDOC ## Search ### Description Performs a full-text search for entities based on a query string. Supports limiting the number of results. ### Method Not applicable (Rust SDK method) ### Endpoint Not applicable (Rust SDK method) ### Parameters #### Path Parameters None #### Query Parameters - **limit** (usize) - Optional - The maximum number of results to return. #### Request Body None ### Request Example ```rust let results = Artist::search("Beatles".to_string()) .limit(10) .execute()?; ``` ### Response #### Success Response Returns a list of entities matching the search query. #### Response Example (Varies based on entity type and search results) ``` -------------------------------- ### Fetch Trait Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/fetch-query.md Demonstrates how to use the `fetch()` method from the `Fetch` trait to create a `FetchQuery` for an Artist entity. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let artist_query = Artist::fetch(); ``` -------------------------------- ### Execute Asynchronous Search Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md Example of executing a search query asynchronously and awaiting the results. ```rust let results = Artist::search("Miles Davis".to_string()) .limit(10) .execute_async() .await?; ``` -------------------------------- ### Execute Synchronous Search Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md Example of executing a search query synchronously and iterating over the results. ```rust use musicbrainz_rs::entity::artist::{Artist, ArtistSearchQuery}; use musicbrainz_rs::prelude::*; let results = Artist::search("Miles Davis".to_string()) .limit(10) .execute()?; for artist in results.entities { println!("{}: {}", artist.name, artist.score.unwrap_or(0)); } ``` -------------------------------- ### Add MusicBrainz Rust Crate (Async) Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/README.md Add the musicbrainz_rs crate to your project for asynchronous operations. This is the default client setup. ```toml musicbrainz_rs = "0.9.0" ``` -------------------------------- ### Set Browse Query Limit Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md Example of setting a custom limit for the number of results in a browse query. ```rust let results = Artist::browse() .by_release("18d4e9b4-9247-4b44-914a-8ddec3502103") .limit(50) .execute()?; ``` -------------------------------- ### Set Search Limit Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md Example of setting a limit for the number of search results using the `limit` method. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let results = Artist::search("Miles Davis".to_string()) .limit(50) .execute()?; ``` -------------------------------- ### Async Fetch with Rate Limiting Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/configuration.md An example of performing asynchronous artist fetches with the rate limiter automatically applied. This requires the `async` feature and ideally `rate_limit`. ```rust use musicbrainz_rs::client::MusicBrainzClient; use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; #[tokio::main] async fn main() -> Result<(), Box> { let client = MusicBrainzClient::new("MyApp/1.0.0"); // Rate limiting is applied automatically for id in vec![ "5b11f4ce-a62d-471e-81fc-a69a8278c7da", "e0ce2b6a-7a37-4af8-8aba-5c6f92eb1f1f", ] { let artist = Artist::fetch() .id(id) .execute_with_client_async(&client) .await?; println!("Artist: {}", artist.name); } Ok(()) } ``` -------------------------------- ### Artist Browse Example Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/entity-types.md Illustrates how to browse for artists related to other entities like areas, releases, or works, with options to include additional data. ```APIDOC ## Browse Artists ### Description Browses for artists based on relationships to other entities. ### Method `Artist::browse()` ### Endpoint Not directly represented in this SDK method, but corresponds to a MusicBrainz API browse endpoint. ### Parameters - `by_area(String)` - Optional - Browse artists by area MBID. - `by_release(String)` - Optional - Browse artists by release MBID. - `by_release_group(String)` - Optional - Browse artists by release group MBID. - `by_work(String)` - Optional - Browse artists by work MBID. - `by_collection(String)` - Optional - Browse artists by collection MBID. - `by_recording(String)` - Optional - Browse artists by recording MBID. - `with_annotation()` - Optional - Include annotation. - `with_tags()` - Optional - Include tags. - `with_user_tags()` - Optional - Include user tags. - `with_genres()` - Optional - Include genres. - `with_user_genres()` - Optional - Include user genres. - `with_aliases()` - Optional - Include aliases. ### Request Example ```rust let artists = Artist::browse() .by_area("08310658-51eb-3801-80de-688edeae1c62") .with_aliases() .execute()?; ``` ### Response #### Success Response - A list of `Artist` objects matching the browse criteria. ``` -------------------------------- ### Initiating a Browse Query Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md The `Browse` trait provides a static `browse()` method on entity types that implement it. This method returns a `BrowseQuery` builder to start constructing a browse request. ```APIDOC ## Initiate Browse Query ### Description Use the `browse()` method provided by the `Browse` trait to start a query for related entities. ### Method `static browse() -> BrowseQuery` ### Example ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let browse_query = Artist::browse(); ``` ``` -------------------------------- ### Fetch Release with Includes Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/fetch-query.md Demonstrates fetching a Release entity along with its media, recordings, labels, aliases, and tags using the FetchQuery builder. ```rust let release = Release::fetch() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .with_media() .with_recordings() .with_labels() .with_tags() .with_aliases() .execute()?; ``` -------------------------------- ### Create MusicBrainzClient using Builder Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/musicbrainz-client.md Initializes a MusicBrainzClient with custom configurations like domain and Cover Art Archive URL using a builder pattern. ```rust use musicbrainz_rs::client::MusicBrainzClient; let client = MusicBrainzClient::builder() .musicbrainz_domain("musicbrainz.org".to_string()) .coverart_archive_url("http://coverartarchive.org".to_string()) .build(); ``` -------------------------------- ### Configure MusicBrainz Client for Local Instance Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/PRACTICAL-GUIDE.md Shows how to configure the `MusicBrainzClient` to point to a local MusicBrainz instance for integration testing. This allows testing against a controlled environment. ```rust use musicbrainz_rs::MusicBrainzClient; #[test] fn test_api_integration() { let client = MusicBrainzClient::builder() .musicbrainz_domain("localhost:5000".to_string()) .build(); // Test against local instance } ``` -------------------------------- ### Browse Artists by Release Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md Example of browsing artists associated with a specific release using the `by_release` filter. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let artists_on_release = Artist::browse() .by_release("18d4e9b4-9247-4b44-914a-8ddec3502103") .execute()?; ``` -------------------------------- ### Create Default MusicBrainzClient Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/musicbrainz-client.md Creates a MusicBrainzClient with default settings, including a default user agent string. ```rust use musicbrainz_rs::client::MusicBrainzClient; let client = MusicBrainzClient::default(); ``` -------------------------------- ### Set Search Offset Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md Example of setting an offset to skip results for pagination using the `offset` method. ```rust let results = Artist::search("Miles Davis".to_string()) .offset(25) .limit(25) .execute()?; ``` -------------------------------- ### Execute FetchQuery Synchronously with Client Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/fetch-query.md Shows how to execute a fetch query synchronously using a specific `MusicBrainzClient` instance. This is useful for managing client configurations and requires the `sync` feature. ```rust use musicbrainz_rs::client::MusicBrainzClient; use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let client = MusicBrainzClient::new("MyApp/1.0.0"); let nirvana = Artist::fetch() .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da") .execute_with_client(&client)?; ``` -------------------------------- ### Paginate Release Browsing Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/INDEX.md Demonstrates how to handle pagination when browsing releases by a label. It iteratively fetches batches of 100 releases until no more entities are found. ```rust let mut offset = 0u16; loop { let batch = Release::browse() .by_label(label_id) .limit(100) .offset(offset) .execute()?; if batch.entities.is_empty() { break; } offset += 100; } ``` -------------------------------- ### Set Browse Query Offset for Pagination Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md Example of setting an offset to skip results for pagination in a browse query. ```rust let results = Artist::browse() .by_release("18d4e9b4-9247-4b44-914a-8ddec3502103") .offset(50) .limit(50) .execute()?; ``` -------------------------------- ### Release Include Methods Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/fetch-query.md Demonstrates fetching a Release with various related data using include methods. ```APIDOC ## Fetch Release with Includes ### Description Fetch a release and include related data such as media, recordings, labels, aliases, and tags. ### Method `Release::fetch()` ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let release = Release::fetch() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .with_media() .with_recordings() .with_labels() .with_tags() .with_aliases() .execute()?; ``` ### Response #### Success Response Returns a `Release` object with the requested included data populated. #### Response Example (Response structure depends on the included data, refer to entity-specific documentation) ``` -------------------------------- ### Execute Sync Browse Query with Client Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md Executes a synchronous browse query using a provided MusicBrainzClient. Requires the 'sync' feature. ```rust use musicbrainz_rs::client::MusicBrainzClient; use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let client = MusicBrainzClient::new("MyApp/1.0.0"); let results = Artist::browse() .by_release("18d4e9b4-9247-4b44-914a-8ddec3502103") .execute_with_client(&client)?; ``` -------------------------------- ### Browse Query with Include Methods Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md Demonstrates using include methods to fetch additional related data for entities in a browse query. Available includes are entity-specific. ```rust let results = Artist::browse() .by_release("18d4e9b4-9247-4b44-914a-8ddec3502103") .with_annotation() .with_tags() .with_aliases() .execute()?; ``` -------------------------------- ### Define Browse Trait Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/browse-query.md The Browse trait is implemented by browsable entity types and provides the `browse()` method to start a browse query. ```rust pub trait Browse { fn browse() -> BrowseQuery where Self: Sized + APIPath; } ``` -------------------------------- ### Execute FetchQuery Asynchronously with Client Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/fetch-query.md Shows how to execute a fetch query asynchronously using a specific `MusicBrainzClient` instance. This requires the `async` feature and allows for custom client configurations in asynchronous operations. ```rust use musicbrainz_rs::client::MusicBrainzClient; use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let client = MusicBrainzClient::new("MyApp/1.0.0"); let nirvana = Artist::fetch() .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da") .execute_with_client_async(&client) .await?; ``` -------------------------------- ### Get API Endpoints from Client Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/musicbrainz-client.md Retrieves the MusicBrainz API endpoints associated with the configured MusicBrainz domain from an existing client instance. ```rust let client = MusicBrainzClient::default(); let endpoints = client.endpoints(); ``` -------------------------------- ### Execute Cover Art Query (Sync) Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/coverart-query.md Use this method to execute a cover art query synchronously with a provided MusicBrainz client. Requires the 'sync' feature to be enabled. ```rust use musicbrainz_rs::client::MusicBrainzClient; use musicbrainz_rs::entity::release::Release; use musicbrainz_rs::prelude::*; let client = MusicBrainzClient::new("MyApp/1.0.0"); let coverart = Release::fetch_coverart() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .execute_with_client(&client)?; ``` -------------------------------- ### Custom HTTP Client Configuration Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/configuration.md Illustrates setting up a MusicBrainz client with a custom HTTP client, allowing for detailed configuration of the underlying agent, such as user agent and timeouts. ```rust use musicbrainz_rs::client::MusicBrainzClient; use api_bindium::ApiClient; use api_bindium::ureq::config::Config; use api_bindium::ureq::Agent; fn setup_custom_http_client() -> MusicBrainzClient { // Configure the underlying HTTP client let agent_config = Config::builder() .user_agent("MyApp/1.0.0 (https://myapp.com)") .timeout(std::time::Duration::from_secs(30)) .build(); let agent = Agent::new_with_config(agent_config); let api_client = ApiClient::builder() .agent(agent) .build(); MusicBrainzClient::builder() .api_client(api_client) .build() } ``` -------------------------------- ### Pagination Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/search-query.md Explains how to implement pagination for search queries by using the `limit()` and `offset()` methods. ```APIDOC ## Pagination ### Description Demonstrates how to fetch results in pages by utilizing the `limit()` and `offset()` methods on search queries. ### Method Synchronous function calls within a loop ### Endpoint N/A (SDK methods) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust fn fetch_all_results(query: &str) -> Result, Box> { let mut all_artists = Vec::new(); let page_size = 100u8; let mut offset = 0u16; loop { let results = Artist::search(query.to_string()) .limit(page_size) .offset(offset) .execute()?; if results.entities.is_empty() { break; } all_artists.extend(results.entities); offset += page_size as u16; } Ok(all_artists) } ``` ### Response #### Success Response `Vec` — A vector containing all fetched artist entities. #### Response Example (See `SearchResult` structure for individual page results) ``` -------------------------------- ### Create New MusicBrainzClient Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/musicbrainz-client.md Instantiates a new MusicBrainzClient with a custom user agent string. Ensure the user agent identifies your application for rate limiting compliance. ```rust use musicbrainz_rs::client::MusicBrainzClient; let client = MusicBrainzClient::new("MyApp/1.0.0 (http://myapp.example.com)"); ``` -------------------------------- ### Handling InvalidUriError Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/errors.md This example demonstrates how to specifically catch errors related to invalid URI construction or query parameters. It checks for the InvalidUriError variant. ```rust match Artist::fetch() .id("not a valid uuid format!") .execute() { Err(ApiEndpointError::InvalidUriError { .. }) => { eprintln!("Invalid query parameters"); } _ => {} } ``` -------------------------------- ### Execute Cover Art Query Async with Client Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/coverart-query.md Execute a cover art query asynchronously using a specific MusicBrainz client. This is useful when you already have a client instance. Requires the 'async' feature. ```rust let coverart = Release::fetch_coverart() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .execute_with_client_async(&client) .await?; ``` -------------------------------- ### Get Album Cover Art Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/INDEX.md Fetch the cover art URL for a release, with options to specify resolution and side (front/back). Use this for album covers. ```rust let url = Release::fetch_coverart() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .front() .res_500() .execute()?; ``` -------------------------------- ### Fetch Artist with Custom Client and User Agent Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/API-OVERVIEW.md Demonstrates how to use a custom MusicBrainz client with a specified user agent string for API requests. This allows for custom application identification. ```rust use musicbrainz_rs::client::MusicBrainzClient; use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; let client = MusicBrainzClient::new("MyApp/1.0.0 (https://myapp.example.com)"); let artist = Artist::fetch() .id("5b11f4ce-a62d-471e-81fc-a69a8278c7da") .execute_with_client(&client)?; ``` -------------------------------- ### MusicBrainzClient::default Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/musicbrainz-client.md Creates a MusicBrainzClient instance with default settings, including a default user agent string. ```APIDOC ## MusicBrainzClient::default() ### Description Creates a MusicBrainzClient with default configuration. Default user agent is `musicbrainz_rs/`. ### Returns `MusicBrainzClient` ### Example ```rust use musicbrainz_rs::client::MusicBrainzClient; let client = MusicBrainzClient::default(); ``` ``` -------------------------------- ### Get Specific Image with Resolution Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/coverart-query.md Query for a specific cover art image (e.g., front) with a specified resolution (e.g., 500px). Handles the URL response variant. ```rust let front_cover_500px = Release::fetch_coverart() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .front() .res_500() .execute()?; if let CoverartResponse::Url(url) = front_cover_500px { println!("Download from: {}", url); } ``` -------------------------------- ### Get All Cover Art Metadata Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/coverart-query.md Query for all available cover art metadata for a release by omitting specific image type and resolution. Handles the JSON response variant. ```rust use musicbrainz_rs::entity::release::Release; use musicbrainz_rs::entity::CoverartResponse; use musicbrainz_rs::prelude::*; let all_coverart = Release::fetch_coverart() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .execute()?; if let CoverartResponse::Json(coverart) = all_coverart { for image in &coverart.images { println!("Image: {}", image.image); if image.front { println!(" - This is the front cover"); } if image.back { println!(" - This is the back cover"); } } } ``` -------------------------------- ### Fetch Artist with Includes Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/INDEX.md Shows how to fetch an artist along with related data such as recordings, releases, and tags using the `with_...` methods. ```rust let artist = Artist::fetch() .id("mbid") .with_recordings() .with_releases() .with_tags() .execute()?; ``` -------------------------------- ### Build Music Database Index with Artist Data Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/PRACTICAL-GUIDE.md This snippet demonstrates how to create a local index of artists, including their recordings, releases, aliases, and tags, using a HashMap. It fetches detailed artist information from the MusicBrainz API and stores it locally for quick retrieval. ```rust use musicbrainz_rs::entity::artist::Artist; use musicbrainz_rs::prelude::*; use std::collections::HashMap; struct MusicIndex { artists: HashMap, } impl MusicIndex { fn new() -> Self { MusicIndex { artists: HashMap::new(), } } fn index_artist(&mut self, artist_id: &str) -> Result<(), Box> { let artist = Artist::fetch() .id(artist_id) .with_recordings() .with_releases() .with_aliases() .with_tags() .execute()?; self.artists.insert(artist_id.to_string(), artist); Ok(()) } fn get_artist_info(&self, artist_id: &str) -> Option { self.artists.get(artist_id).map(|artist| { ArtistInfo { name: artist.name.clone(), type_: artist.artist_type.as_ref().map(|t| format!("{:?}", t)), recording_count: artist.recordings.as_ref().map(|r| r.len()), release_count: artist.releases.as_ref().map(|r| r.len()), tag_count: artist.tags.as_ref().map(|t| t.len()), } }) } } #[derive(Debug, Clone)] struct ArtistInfo { name: String, type_: Option, recording_count: Option, release_count: Option, tag_count: Option, } fn main() -> Result<(), Box> { let mut index = MusicIndex::new(); // Index several artists let artist_ids = vec![ "5b11f4ce-a62d-471e-81fc-a69a8278c7da", "e0ce2b6a-7a37-4af8-8aba-5c6f92eb1f1f", ]; for id in artist_ids { index.index_artist(id)?; } // Query the index if let Some(info) = index.get_artist_info("5b11f4ce-a62d-471e-81fc-a69a8278c7da") { println!("{:?}", info); } Ok(()) } ``` -------------------------------- ### Find All Releases by Label Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/API-OVERVIEW.md Retrieves all releases associated with a specific label by repeatedly fetching batches of releases. This is useful for getting a complete list of a label's discography. ```rust let ubiktune_label = "47e718e1-7ee4-460c-b1cc-1192a841c6e5"; let mut all_releases = Vec::new(); let mut offset = 0u16; loop { let batch = Release::browse() .by_label(ubiktune_label) .limit(100) .offset(offset) .execute()?; if batch.entities.is_empty() { break; } all_releases.extend(batch.entities); offset += 100; } ``` -------------------------------- ### Search Artists by Query Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/api-reference/entity-types.md Searches for artists using a structured query builder that allows filtering by name, country, and other attributes. This example demonstrates searching for 'The Beatles' in the UK. ```rust let query = ArtistSearchQuery::query_builder() .artist("The Beatles") .and() .country("GB") .build(); let results = Artist::search(query) .limit(10) .execute()?; ``` -------------------------------- ### Private MusicBrainz Instance with Basic Auth Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/configuration.md Sets up a MusicBrainz client for a private instance using basic authentication. Requires the `basic_auth` feature to be enabled. ```rust #[cfg(feature = "basic_auth")] fn setup_private_client() -> musicbrainz_rs::client::MusicBrainzClient { use musicbrainz_rs::client::MusicBrainzClient; MusicBrainzClient::builder() .musicbrainz_domain("private.musicbrainz.local:5000".to_string()) .coverart_archive_url("http://private.musicbrainz.local:5000/coverart".to_string()) .basic_auth_credentials(Some(("user".to_string(), "pass".to_string()))) .build() } ``` -------------------------------- ### Get Front Cover Image for Album Source: https://github.com/rustynova016/musicbrainz_rs/blob/main/_autodocs/API-OVERVIEW.md Fetches the front cover art for a specific album using its ID and specifies the desired resolution. This is useful for displaying album artwork. ```rust let coverart = Release::fetch_coverart() .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd") .front() .res_500() .execute()?; if let CoverartResponse::Url(url) = coverart { println!("Download: {}", url); } ```