### Install yandex-music Rust Crate Source: https://github.com/vyfor/yandex-music-rs/blob/master/README.md This command adds the yandex-music crate as a dependency to your Rust project using Cargo. Ensure you have Cargo installed as part of your Rust toolchain. ```bash cargo add yandex-music ``` -------------------------------- ### Get Playlist Recommendations - Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Fetches personalized track recommendations for a given playlist. It takes the Yandex Music client, user ID, and playlist kind as input. Outputs a list of recommended tracks with their artists. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::playlist::get_recommendations::GetRecommendationsOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let user_id = 12345678u64; let playlist_kind = "1234"; let recommendations = client.get_recommendations( &GetRecommendationsOptions::new(user_id, playlist_kind) ).await?; println!("Recommended tracks for your playlist:"); for track in recommendations.tracks { let artists: Vec<_> = track.artists.iter() .filter_map(|a| a.name.as_ref()) .collect(); println!(" - {} by {}", track.title.as_deref().unwrap_or("Unknown"), artists.join(", ") ); } Ok(()) } ``` -------------------------------- ### Get Artist Information Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Fetches comprehensive details about an artist, including their name, ID, genres, track and album counts, popular tracks, discography, and similar artists. This function requires an API token. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::artist::get_artist::GetArtistOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let artist_info = client.get_artist( &GetArtistOptions::new("1234") ).await?; let artist = &artist_info.artist; println!("Artist: {}", artist.name.as_deref().unwrap_or("Unknown")); println!(" ID: {:?}", artist.id); println!(" Genres: {:?}", artist.genres); if let Some(counts) = &artist.counts { println!(" Track count: {:?}", counts.tracks); println!(" Album count: {:?}", counts.albums); } println!("\nPopular tracks:"); for (i, track) in artist_info.popular_tracks.iter().take(10).enumerate() { println!(" {}. {}", i + 1, track.title.as_deref().unwrap_or("Unknown")); } println!("\nAlbums:"); for album in artist_info.albums.iter().take(5) { println!(" - {} ({:?})", album.title.as_deref().unwrap_or("Unknown"), album.year ); } println!("\nSimilar artists:"); for similar in artist_info.similar_artists.iter().take(5) { println!(" - {}", similar.name.as_deref().unwrap_or("Unknown")); } Ok(()) } ``` -------------------------------- ### Get Yandex Music Search Suggestions (Rust) Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves autocomplete suggestions for search queries using the Yandex Music API. Requires a valid API token and the 'yandex_music' crate. Returns a structured response containing best matches and a list of suggestions. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::search::get_search_suggestion::GetSearchSuggestionOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let suggestions = client.get_search_suggestion( &GetSearchSuggestionOptions::new("ramm") ).await?; println!("Search suggestions:"); if let Some(best) = suggestions.best { println!(" Best: {} (type: {:?})", best.text, best.r#type); } for suggestion in suggestions.suggestions { println!(" - {}", suggestion); } Ok(()) } ``` -------------------------------- ### Get Artist Albums with Pagination Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves an artist's albums, supporting pagination to handle large discographies efficiently. It allows fetching specific pages of results with a defined page size. Requires an API token. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::artist::get_artist_albums::GetArtistAlbumsOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; // Get first page of albums let page_0 = client.get_artist_albums( &GetArtistAlbumsOptions::new("1234") .page(0) .page_size(20) ).await?; println!("Albums (page 0):"); for album in &page_0.albums { println!(" - {} ({:?})", album.title.as_deref().unwrap_or("Unknown"), album.year ); } // Get next page if available if page_0.pager.page < page_0.pager.pages - 1 { let page_1 = client.get_artist_albums( &GetArtistAlbumsOptions::new("1234") .page(1) .page_size(20) ).await?; println!("\nAlbums (page 1):"); for album in &page_1.albums { println!(" - {}", album.title.as_deref().unwrap_or("Unknown")); } } Ok(()) } ``` -------------------------------- ### Get Artist Tracks with Pagination Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Fetches all tracks by a specific artist, implementing pagination to manage potentially large track lists. It allows specifying the page and page size for retrieving subsets of tracks. Requires an API token. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::artist::get_artist_tracks::GetArtistTracksOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let tracks = client.get_artist_tracks( &GetArtistTracksOptions::new("1234") .page(0) .page_size(50) ).await?; println!("Artist tracks (total: {}):", tracks.pager.total); for track in &tracks.tracks { let albums: Vec<_> = track.albums.iter() .filter_map(|a| a.title.as_ref()) .collect(); println!(" - {} [{}]", track.title.as_deref().unwrap_or("Unknown"), albums.join(", ") ); } Ok(()) } ``` -------------------------------- ### Get User Playlists Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieve a list of all playlists associated with a specific user account. ```APIDOC ## GET /users/{user_id}/playlists ### Description Retrieve all playlists for a user account. ### Method GET ### Endpoint /users/{user_id}/playlists ### Parameters #### Path Parameters - **user_id** (integer) - Required - The unique identifier of the user. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **title** (string) - The title of the playlist. - **track_count** (integer) - The number of tracks in the playlist. - **kind** (string) - The kind or type of the playlist. - **visibility** (string) - The visibility status of the playlist. - **revision** (integer) - The current revision number of the playlist. #### Response Example [ { "title": "My Playlist 1", "track_count": 50, "kind": "user", "visibility": "public", "revision": 3 }, { "title": "My Playlist 2", "track_count": 75, "kind": "user", "visibility": "private", "revision": 2 } ] ``` -------------------------------- ### Get Yandex Music Track Download Information (Rust) Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves available download URLs and codec information for a specific track. This requires the 'yandex_music' crate and an API token. The function outputs a list of download formats and demonstrates how to obtain a direct download link for the highest quality available. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::track::get_download_info::GetDownloadInfoOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let download_infos = client.get_download_info( &GetDownloadInfoOptions::new("123456") ).await?; println!("Available download formats:"); for info in &download_infos { println!(" - Codec: {}, Bitrate: {} kbps, Preview: {}", info.codec, info.bitrate_in_kbps, info.preview ); } // Get direct download link (requires signature computation) if let Some(best_quality) = download_infos.iter() .filter(|i| !i.preview) .max_by_key(|i| i.bitrate_in_kbps) { match best_quality.get_direct_link(&client.inner).await { Ok(direct_link) => { println!("\nDirect download link:"); println!("{}", direct_link); // Use this link to download or stream the track // Link format: https://storage.mds.yandex.net/get-mp3/{sign}/{ts}{path} } Err(e) => eprintln!("Error getting direct link: {:?}", e), } } Ok(()) } ``` -------------------------------- ### Get Playlist Information Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieve detailed information about a specific playlist, including its tracks, metadata, owner details, and other relevant statistics. ```APIDOC ## GET /playlists/{playlist_id} ### Description Retrieve detailed playlist information including tracks and metadata. ### Method GET ### Endpoint /playlists/{playlist_id} ### Parameters #### Path Parameters - **playlist_id** (string) - Required - The unique identifier of the playlist. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **title** (string) - The title of the playlist. - **playlist_uuid** (string) - The UUID of the playlist. - **owner.name** (string) - The name of the playlist owner. - **track_count** (integer) - The total number of tracks in the playlist. - **duration** (object) - Duration of the playlist in seconds. - **num_seconds** (integer) - The duration in seconds. - **visibility** (string) - The visibility status of the playlist (e.g., "public", "private"). - **likes_count** (integer) - The number of likes the playlist has received. - **revision** (integer) - The current revision number of the playlist. - **description** (string) - Optional description of the playlist. - **tracks** (object) - An object containing playlist tracks. - **items** (array) - An array of track items. - **track** (object) - Information about the track. - **title** (string) - The title of the track. - **artists** (array) - An array of artists for the track. - **name** (string) - The name of the artist. #### Response Example { "title": "My Awesome Playlist", "playlist_uuid": "1234", "owner": {"name": "User Name"}, "track_count": 100, "duration": {"num_seconds": 3600}, "visibility": "public", "likes_count": 50, "revision": 5, "description": "A collection of my favorite songs.", "tracks": { "items": [ { "track": { "title": "Song Title", "artists": [{"name": "Artist Name"}] } } ] } } ``` -------------------------------- ### Get All Radio Stations - Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Lists all available radio stations provided by Yandex Music. This function requires an authenticated Yandex Music client. It returns a collection of station objects, each containing its name and tag. ```rust use yandex_music::YandexMusicClient; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let stations = client.get_all_stations().await?; println!("Available radio stations:"); for station in stations { println!(" - {} ({})", station.name, station.id.tag ); if let Some(id_for_from) = &station.id_for_from { println!(" ID for from: {}", id_for_from); } } Ok(()) } ``` -------------------------------- ### Get Similar Tracks (Rust) Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Finds tracks that are similar to a specified track using Yandex Music's recommendation engine. This function requires a YandexMusicClient and a track ID. It returns a list of similar tracks, each with details like title and artist. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::track::get_similar_tracks::GetSimilarTracksOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let similar = client.get_similar_tracks( &GetSimilarTracksOptions::new("123456") ).await?; println!("Similar tracks:"); if let Some(track) = similar.similar_tracks.first() { println!(" Original: {}", track.title.as_deref().unwrap_or("Unknown")); } for track in similar.similar_tracks.iter().skip(1).take(10) { let artists: Vec<_> = track.artists.iter() .filter_map(|a| a.name.as_ref()) .collect(); println!(" - {} by {}", track.title.as_deref().unwrap_or("Unknown"), artists.join(", ") ); } Ok(()) } ``` -------------------------------- ### Get Yandex Music High-Quality Track File Info (Rust) Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves detailed information about high-quality or lossless audio files for a given track, including codec and bitrate. This function uses the 'yandex_music' crate and requires an API token. It outputs the codec, bitrate, and file size if available. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::track::get_file_info::GetFileInfoOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let file_info = client.get_file_info( &GetFileInfoOptions::new("123456") ).await?; println!("File Information:"); if let Some(codec) = file_info.codec { println!(" Codec: {}", codec); } if let Some(bitrate) = file_info.bitrate { println!(" Bitrate: {} kbps", bitrate); } if let Some(size) = file_info.size { println!(" Size: {} bytes ({:.2} MB)", size, size as f64 / 1_048_576.0); } Ok(()) } ``` -------------------------------- ### Get Album Information Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves detailed metadata for a single album or a list of albums by their IDs. It returns information such as title, year, track count, genre, artists, and tracks organized by disc. Requires a Yandex Music API token. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::album::get_album::GetAlbumOptions; use yandex_music::api::album::get_albums::GetAlbumsOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; // Get single album let album = client.get_album( &GetAlbumOptions::new(123456) ).await?; println!("Album: {}", album.title.as_deref().unwrap_or("Unknown")); println!(" ID: {:?}", album.id); println!(" Year: {:?}", album.year); println!(" Track count: {:?}", album.track_count); println!(" Genre: {:?}", album.genre); println!(" Artists:"); for artist in &album.artists { println!(" - {}", artist.name.as_deref().unwrap_or("Unknown")); } println!(" Tracks by disc:"); for (disc_num, disc) in album.volumes.iter().enumerate() { println!(" Disc {}:", disc_num + 1); for track in disc { println!(" - {}", track.title.as_deref().unwrap_or("Unknown")); } } // Get multiple albums let albums = client.get_albums( &GetAlbumsOptions::new(vec![123456, 234567, 345678]) ).await?; println!("\nRetrieved {} albums", albums.len()); Ok(()) } ``` -------------------------------- ### Get Yandex Music Account Status in Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves detailed user account information, including subscription status (Plus), permissions, and user details. This function is essential for understanding the user's current Yandex Music service level. ```rust use yandex_music::YandexMusicClient; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let status = client.get_account_status().await?; println!("Account Info:"); println!(" User ID: {}", status.account.uid); println!(" Display Name: {}", status.account.display_name.as_deref().unwrap_or("N/A")); println!(" Region: {:?}", status.account.region); println!(" Plus Subscription: {}", status.plus.has_plus); println!(" Skips per hour: {:?}", status.skips_per_hour); if let Some(permissions) = status.permissions.until { println!(" Subscription until: {}", permissions); } Ok(()) } ``` -------------------------------- ### Get Yandex Music Track Information (Rust) Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Fetches detailed metadata for one or multiple tracks from the Yandex Music API. This function requires an API token and the 'yandex_music' crate. It demonstrates how to retrieve information for a single track by its ID and also how to fetch multiple tracks in a single request. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::track::get_track::GetTrackOptions; use yandex_music::api::track::get_tracks::GetTracksOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; // Get single track let track = client.get_track( &GetTrackOptions::new("123456") ).await?; if let Some(first_track) = track.first() { println!("Track: {}", first_track.title.as_deref().unwrap_or("Unknown")); println!(" ID: {}", first_track.id); println!(" Real ID: {}", first_track.real_id); println!(" Duration: {:?}", first_track.duration); println!(" Explicit: {:?}", first_track.explicit); println!(" Available: {:?}", first_track.available); println!(" Lyrics available: {:?}", first_track.lyrics_available); println!(" Artists:"); for artist in &first_track.artists { println!(" - {} (ID: {})", artist.name.as_deref().unwrap_or("Unknown"), artist.id.as_deref().unwrap_or("N/A") ); } } // Get multiple tracks at once let tracks = client.get_tracks( &GetTracksOptions::new(vec!["123456", "789012", "345678"]) ).await?; println!("\nRetrieved {} tracks", tracks.len()); for track in tracks { println!(" - {}", track.title.as_deref().unwrap_or("Unknown")); } Ok(()) } ``` -------------------------------- ### Get Playlist Information in Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves detailed information about a specific Yandex Music playlist, including its tracks, metadata, and ownership details. Requires a Yandex Music client with an authentication token and playlist ID. Outputs playlist title, UUID, owner, track count, duration, visibility, likes, revision, and optionally description and the first 10 tracks with their artists. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::playlist::get_playlist::GetPlaylistOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let playlist = client.get_playlist( &GetPlaylistOptions::new(12345678, "1234") ).await?; println!("Playlist: {}", playlist.title); println!(" UUID: {}", playlist.playlist_uuid); println!(" Owner: {}", playlist.owner.name); println!(" Track count: {}", playlist.track_count); println!(" Duration: {} seconds", playlist.duration.num_seconds()); println!(" Visibility: {}", playlist.visibility); println!(" Likes: {}", playlist.likes_count); println!(" Revision: {}", playlist.revision); if let Some(description) = &playlist.description { println!(" Description: {}", description); } if let Some(tracks) = &playlist.tracks { println!("\nTracks:"); for (i, track_item) in tracks.items.iter().take(10).enumerate() { if let Some(track) = &track_item.track { let artists: Vec<_> = track.artists.iter() .filter_map(|a| a.name.as_ref()) .collect(); println!(" {}. {} - {}", i + 1, track.title.as_deref().unwrap_or("Unknown"), artists.join(", ") ); } } } Ok(()) } ``` -------------------------------- ### Get Radio Station Tracks - Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves a list of tracks currently playing or queued on a specific radio station (rotor). It requires the Yandex Music client and a station identifier. The output includes station details and track information. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::rotor::get_station_tracks::GetStationTracksOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let station_tracks = client.get_station_tracks( &GetStationTracksOptions::new("user:onyourwave") ).await?; println!("Station: {}", station_tracks.station.id.name); println!("Batch ID: {}", station_tracks.batch_id); println!("\nTracks in queue:"); for sequence in &station_tracks.sequence { if let Some(track) = &sequence.track { let artists: Vec<_> = track.artists.iter() .filter_map(|a| a.name.as_ref()) .collect(); println!(" - {} by {}", track.title.as_deref().unwrap_or("Unknown"), artists.join(", ") ); } } Ok(()) } ``` -------------------------------- ### Get Personalized Music Feed with Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves a user's personalized music feed, including recommendations and generated playlists. It requires an OAuth token for authentication and processes the feed data to display generated playlist counts and event types. The output includes details about generated playlists and user-specific events. ```rust use yandex_music::YandexMusicClient; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let feed = client.get_feed().await?; println!("Your personalized feed:"); println!("Generated at: {}", feed.generated_playlist_ids.len()); println!("Can get more: {}", feed.can_get_more_events); for day in feed.days { println!("\nDate: {}", day.day); for event in day.events { match event.type_for_from.as_deref() { Some("tracks") => println!(" [Tracks] {}", event.title.unwrap_or_default()), Some("artists") => println!(" [Artists] {}", event.title.unwrap_or_default()), Some("albums") => println!(" [Albums] {}", event.title.unwrap_or_default()), _ => println!(" [Other] {}", event.title.unwrap_or_default()), } } } Ok(()) } ``` -------------------------------- ### Get Track Lyrics (Rust) Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Retrieves lyrics for a given track in either plain text or synchronized (LRC) format. It requires a YandexMusicClient instance and track ID. The function returns a download URL for the lyrics, which can then be fetched using a separate HTTP request. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::track::get_lyrics::GetLyricsOptions; use yandex_music::model::info::lyrics::LyricsFormat; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; // Get plain text lyrics let text_lyrics = client.get_lyrics( &GetLyricsOptions::new("123456", LyricsFormat::TEXT) ).await?; println!("Text Lyrics URL: {}", text_lyrics.download_url); // Get synchronized lyrics (with timestamps) let sync_lyrics = client.get_lyrics( &GetLyricsOptions::new("123456", LyricsFormat::LRC) ).await?; println!("Synchronized Lyrics URL: {}", sync_lyrics.download_url); // Download and display lyrics let lyrics_text = reqwest::get(&text_lyrics.download_url) .await? .text() .await?; println!("\nLyrics:\n{}", lyrics_text); Ok(()) } ``` -------------------------------- ### Get User Playlists in Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Fetches all playlists associated with a specific user account on Yandex Music. It requires an authenticated Yandex Music client and the user's ID. The function iterates through the returned playlists, printing their title, track count, kind, visibility, and revision. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::playlist::get_all_playlists::GetAllPlaylistsOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let user_id = 12345678u64; let playlists = client.get_all_playlists( &GetAllPlaylistsOptions::new(user_id) ).await?; println!("Your playlists:"); for playlist in playlists { println!(" - {} ({} tracks, kind: {})", playlist.title, playlist.track_count, playlist.kind ); println!(" Visibility: {}, Revision: {}", playlist.visibility, playlist.revision ); } Ok(()) } ``` -------------------------------- ### Initialize Yandex Music API Client in Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Demonstrates how to create and configure a Yandex Music API client using OAuth token. It shows basic initialization and advanced configuration with proxy settings. The client is verified by fetching account status. ```rust use yandex_music::YandexMusicClient; #[tokio::main] async fn main() -> Result<(), Box> { // Basic client with OAuth token let client = YandexMusicClient::builder("YOUR_OAUTH_TOKEN") .build()?; // Client with custom configuration let proxy = reqwest::Proxy::all("http://proxy:8080")?; let custom_client = YandexMusicClient::builder("YOUR_OAUTH_TOKEN") .client_id("MyMusicApp/1.0") .proxy(proxy) .build()?; // Verify client works let status = client.get_account_status().await?; println!("User ID: {}", status.account.uid); println!("Has Premium: {}", status.plus.has_plus); Ok(()) } ``` -------------------------------- ### Create Playlist Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Create a new playlist for the authenticated user. ```APIDOC ## POST /users/{user_id}/playlists ### Description Create a new playlist for the user. ### Method POST ### Endpoint /users/{user_id}/playlists ### Parameters #### Path Parameters - **user_id** (integer) - Required - The unique identifier of the user for whom the playlist is created. #### Query Parameters None #### Request Body - **title** (string) - Required - The desired title for the new playlist. - **visibility** (string) - Required - The visibility setting for the playlist (e.g., "public", "private"). ### Request Example ```json { "title": "My New Playlist", "visibility": "public" } ``` ### Response #### Success Response (200) - **title** (string) - The title of the newly created playlist. - **kind** (string) - The kind or type of the playlist. - **playlist_uuid** (string) - The unique identifier (UUID) of the created playlist. - **revision** (integer) - The revision number of the newly created playlist. #### Response Example { "title": "My New Playlist", "kind": "user", "playlist_uuid": "abcdef12345", "revision": 1 } ``` -------------------------------- ### Create Playlist in Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Creates a new Yandex Music playlist for the authenticated user. This operation requires the Yandex Music client, the user ID, a desired playlist title, and a visibility setting (e.g., 'public'). The output confirms the creation and displays the new playlist's title, kind, UUID, and revision number. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::playlist::create_playlist::CreatePlaylistOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let user_id = 12345678u64; let new_playlist = client.create_playlist( &CreatePlaylistOptions::new( user_id, "My Awesome Playlist", "public" ) ).await?; println!("Created playlist:"); println!(" Title: {}", new_playlist.title); println!(" Kind: {}", new_playlist.kind); println!(" UUID: {}", new_playlist.playlist_uuid); println!(" Revision: {}", new_playlist.revision); Ok(()) } ``` -------------------------------- ### Comprehensive API Error Handling in Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Demonstrates robust error handling for Yandex Music API requests in Rust. It specifically shows how to catch and differentiate between various `ClientError` types, including Yandex Music API errors, request errors, and parsing errors. This enables implementing appropriate fallback or retry mechanisms. ```rust use yandex_music::{YandexMusicClient, error::ClientError}; use yandex_music::api::track::get_track::GetTrackOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; match client.get_track(&GetTrackOptions::new("invalid_id")).await { Ok(tracks) => { println!("Success! Got {} tracks", tracks.len()); } Err(ClientError::YandexMusicError { error }) => { eprintln!("Yandex Music API Error:"); eprintln!(" Error name: {}", error.name); if let Some(message) = error.message { eprintln!(" Message: {}", message); } } Err(ClientError::RequestError { error }) => { eprintln!("HTTP Request Error: {}", error); } Err(ClientError::JsonParseError { error }) => { eprintln!("JSON Parse Error: {}", error); } Err(ClientError::XmlParseError { error }) => { eprintln!("XML Parse Error: {}", error); } Err(ClientError::InvalidHeader { error }) => { eprintln!("Invalid Header Error: {}", error); } } Ok(()) } ``` -------------------------------- ### Fetch Yandex Music Account Status in Rust Source: https://github.com/vyfor/yandex-music-rs/blob/master/README.md Demonstrates how to use the YandexMusicClient from the yandex-music crate to retrieve account status. This requires an Yandex Music access token and uses Tokio for asynchronous operations. The output is printed to the console. ```rust use yandex_music::YandexMusicClient; #[tokio::main] async fn main() -> Result<(), Box> { // Replace "TOKEN" with your Yandex Music access token let client = YandexMusicClient::builder("TOKEN").build()?; // Example usage let status = client.get_account_status().await?; println!("Account status: {status:?}"); Ok(()) } ``` -------------------------------- ### Manage Liked Tracks (Rust) Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Allows users to manage their liked tracks library. This includes fetching the current list of liked tracks, adding new tracks to the liked list, and removing tracks. It requires a YandexMusicClient, a user ID, and track identifiers. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::track::{ get_liked_tracks::GetLikedTracksOptions, add_liked_tracks::AddLikedTracksOptions, remove_liked_tracks::RemoveLikedTracksOptions, }; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let user_id = 12345678u64; // Your user ID // Get current liked tracks let library = client.get_liked_tracks( &GetLikedTracksOptions::new(user_id) ).await?; println!("You have {} liked tracks", library.tracks.len()); println!("Library revision: {}", library.revision); // Like new tracks let tracks_to_like = vec!["123456:789012", "234567:890123"]; let new_revision = client.add_liked_tracks( &AddLikedTracksOptions::new(user_id, tracks_to_like) ).await?; println!("Liked tracks added. New revision: {}", new_revision); // Unlike tracks let tracks_to_unlike = vec!["123456:789012"]; let final_revision = client.remove_liked_tracks( &RemoveLikedTracksOptions::new(user_id, tracks_to_unlike) ).await?; println!("Tracks removed from likes. Final revision: {}", final_revision); // Get updated library let updated_library = client.get_liked_tracks( &GetLikedTracksOptions::new(user_id) ).await?; for track_short in updated_library.tracks.iter().take(5) { println!(" - Track ID: {}", track_short.id); } Ok(()) } ``` -------------------------------- ### Search Music on Yandex Music in Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Enables searching for various music entities like tracks, artists, and albums using the Yandex Music API. It supports specifying search types and pagination for results, allowing targeted music discovery. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::search::get_search::SearchOptions; use yandex_music::model::search::SearchType; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; // Search for everything let all_results = client.search( &SearchOptions::new("Rammstein").page(0) ).await?; // Search only for artists let artist_results = client.search( &SearchOptions::new("Rammstein") .item_type(SearchType::Artists) .page(0) ).await?; if let Some(artists) = artist_results.artists { println!("Found {} artists:", artists.total); for artist in artists.results.iter().take(5) { println!(" - {} (ID: {})", artist.name.as_deref().unwrap_or("Unknown"), artist.id.as_deref().unwrap_or("N/A") ); } } // Search for tracks let track_results = client.search( &SearchOptions::new("Du Hast") .item_type(SearchType::Tracks) .page(0) ).await?; if let Some(tracks) = track_results.tracks { println!("\nFound {} tracks:", tracks.total); for track in tracks.results.iter().take(3) { let artist_names: Vec<_> = track.artists.iter() .filter_map(|a| a.name.as_ref()) .collect(); println!(" - {} by {}", track.title.as_deref().unwrap_or("Unknown"), artist_names.join(", ") ); } } Ok(()) } ``` -------------------------------- ### Send Radio Station Feedback - Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Allows users to send feedback (like or dislike/skip) for tracks played on radio stations. It requires the Yandex Music client, station details, track information, and feedback type. Optional parameters include batch ID and total played seconds. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::rotor::send_station_feedback::SendStationFeedbackOptions; use yandex_music::model::rotor::FeedbackType; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; // Like a track client.send_station_feedback( &SendStationFeedbackOptions::new( "user:onyourwave", "123456:789012", FeedbackType::Like ) .batch_id("batch_123") .total_played_seconds(180.5) ).await?; println!("Liked track on station"); // Dislike (skip) a track client.send_station_feedback( &SendStationFeedbackOptions::new( "user:onyourwave", "234567:890123", FeedbackType::Skip ) .batch_id("batch_123") ).await?; println!("Skipped track on station"); Ok(()) } ``` -------------------------------- ### Retrieve Music Genres with Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Fetches a list of all available music genres from the Yandex Music API. This function requires an OAuth token and iterates through the genres and their sub-genres, printing their titles and IDs. It helps in understanding the categorization of music on the platform. ```rust use yandex_music::YandexMusicClient; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let genres = client.get_genres().await?; println!("Available genres:"); for genre in genres { println!(" - {} (ID: {})", genre.title, genre.id); if let Some(sub_genres) = genre.sub_genres { for sub in sub_genres { println!(" - {}", sub.title); } } } Ok(()) } ``` -------------------------------- ### Report Track Playback (Rust) Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Reports the playback state of a track to the Yandex Music API, which is used for analytics and personalized recommendations. This function requires a YandexMusicClient and options including play context, track ID, album ID, total duration, and listening duration. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::track::play_audio::PlayAudioOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; // Report that user played a track let options = PlayAudioOptions::new( "from_artist_123", // Play context (where track was played from) "123456", // Track ID "album_789" // Album ID ) .total_seconds(180.5) // Track duration .end_position_seconds(45.2); // How long user listened client.play_audio(&options).await?; println!("Playback reported to Yandex Music"); Ok(()) } ``` -------------------------------- ### Modify Playlist Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Modify an existing playlist by adding, removing, or reordering tracks. Requires the current revision number of the playlist. ```APIDOC ## POST /users/{user_id}/playlists/{playlist_id}/modify ### Description Add, remove, or reorder tracks in a playlist. ### Method POST ### Endpoint /users/{user_id}/playlists/{playlist_id}/modify ### Parameters #### Path Parameters - **user_id** (integer) - Required - The unique identifier of the user. - **playlist_id** (string) - Required - The unique identifier of the playlist. #### Query Parameters None #### Request Body - **diff** (object) - Required - An object describing the changes to be made to the playlist tracks. - **op** (string) - Required - The operation type (e.g., "insert", "delete", "move"). - **from** (integer) - Optional - The starting index for delete or move operations. - **to** (integer) - Optional - The destination index for insert or move operations. - **tracks** (array) - Optional - An array of track objects to insert. - **id** (string) - Required - The ID of the track. - **album_id** (string) - Optional - The ID of the album the track belongs to. - **revision** (integer) - Required - The current revision number of the playlist. ### Request Example ```json { "diff": { "op": "insert", "to": 0, "tracks": [ {"id": "123456", "album_id": "789012"}, {"id": "234567", "album_id": "890123"} ] }, "revision": 5 } ``` ### Response #### Success Response (200) - **revision** (integer) - The new revision number of the playlist after the modifications. #### Response Example ```json { "revision": 6 } ``` ``` -------------------------------- ### Delete Playlist - Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Removes a specified playlist from the user's library. Requires the Yandex Music client, user ID, and playlist kind. Returns a success message or an error. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::playlist::delete_playlist::DeletePlaylistOptions; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let user_id = 12345678u64; let playlist_kind = "1234"; client.delete_playlist( &DeletePlaylistOptions::new(user_id, playlist_kind) ).await?; println!("Playlist deleted successfully"); Ok(()) } ``` -------------------------------- ### Modify Playlist Tracks in Rust Source: https://context7.com/vyfor/yandex-music-rs/llms.txt Allows modification of tracks within a Yandex Music playlist, such as adding, deleting, or reordering. It requires an authenticated client, user ID, playlist identifier, a `Diff` object specifying the changes, and the current revision number of the playlist. The function returns the updated revision number upon successful modification. Note: The `current_revision` must be obtained prior to modification. ```rust use yandex_music::YandexMusicClient; use yandex_music::api::playlist::modify_playlist::ModifyPlaylistOptions; use yandex_music::model::playlist::modify::{Diff, DiffOp}; use yandex_music::model::track::TrackShort; #[tokio::main] async fn main() -> Result<(), Box> { let client = YandexMusicClient::builder("TOKEN").build()?; let user_id = 12345678u64; let playlist_kind = "1234"; let current_revision = 5; // Get this from get_playlist // Insert tracks at beginning let insert_diff = Diff::new( DiffOp::insert(0), vec![ TrackShort::new("123456", Some("789012".to_string())), TrackShort::new("234567", Some("890123".to_string())), ] ); let result = client.modify_playlist( &ModifyPlaylistOptions::new( user_id, playlist_kind, insert_diff, current_revision ) ).await?; println!("Tracks added. New revision: {}", result.revision); // Delete track at position 2 let delete_diff = Diff::new( DiffOp::delete(2, 2), // from, to vec![] ); let result2 = client.modify_playlist( &ModifyPlaylistOptions::new( user_id, playlist_kind, delete_diff, result.revision // Use updated revision ) ).await?; println!("Track removed. New revision: {}", result2.revision); Ok(()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.