use serde::{Deserialize, Serialize}; use std::collections::HashSet; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct UserAccount { pub uid: u64, pub login: String, pub display_name: String, pub has_plus: bool, pub avatar_uri: Option, #[serde(default)] pub default_email: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ArtistSummary { pub id: String, pub name: String, pub cover_uri: Option, pub genres: Vec, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AlbumSummary { pub id: String, pub title: String, pub year: Option, pub cover_uri: Option, pub artists: Vec, pub track_count: u32, pub genre: Option, pub is_explicit: bool, /// Official API content type (`album.type` / `album.metaType`, e.g. "album", "single", "podcast", "audiobook") #[serde(default)] pub content_type: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Track { pub id: String, pub title: String, pub version: Option, pub artists: Vec, pub album_id: Option, pub album_title: Option, pub cover_uri: Option, pub duration_ms: u64, pub is_explicit: bool, pub has_lossless: bool, pub has_lyrics: bool, pub chart_position: Option, pub chart_progress: Option, // "up", "down", "new", "same" pub preview_url: Option, /// EBU R128 integrated loudness (LUFS) from Yandex Music API (`track.r128.i`) #[serde(default)] pub r128_i: Option, /// EBU R128 true peak (dBTP) from Yandex Music API (`track.r128.tp`) #[serde(default)] pub r128_tp: Option, /// Official Yandex Music track palette (`track.derivedColors.average` & `.accent`) #[serde(default)] pub derived_average_hex: Option, #[serde(default)] pub derived_accent_hex: Option, } impl Track { pub fn artists_string(&self) -> String { if self.artists.is_empty() { "Неизвестный исполнитель".to_string() } else { self.artists .iter() .map(|a| a.name.as_str()) .collect::>() .join(", ") } } pub fn full_title(&self) -> String { match &self.version { Some(v) if !v.is_empty() => format!("{} ({})", self.title, v), _ => self.title.clone(), } } pub fn duration_formatted(&self) -> String { format_ms(self.duration_ms) } /// Exact Rotor / My Vibe feedback `trackId` format: `"{id}:{albumId}"` (or `"{id}"` if no album) pub fn rotor_track_id(&self) -> String { match &self.album_id { Some(aid) if !aid.is_empty() => format!("{}:{}", self.id, aid), _ => self.id.clone(), } } } pub fn format_ms(ms: u64) -> String { let total_secs = ms / 1000; let mins = total_secs / 60; let secs = total_secs % 60; format!("{:02}:{:02}", mins, secs) } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PlaylistSummary { pub kind: String, pub owner_uid: String, pub owner_name: String, pub title: String, pub description: Option, pub cover_uri: Option, pub track_count: u32, pub likes_count: u32, pub generated_type: Option, // "playlistOfTheDay", "neverHeard", "recentTracks", etc. #[serde(default)] pub revision: u32, #[serde(default)] pub visibility: Option, // "public" | "private" #[serde(default)] pub playlist_uuid: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PlaylistDetail { pub summary: PlaylistSummary, pub tracks: Vec, #[serde(default)] pub revision: u32, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AlbumDetail { pub summary: AlbumSummary, pub tracks: Vec, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ArtistDetail { pub summary: ArtistSummary, pub monthly_listeners: u64, pub popular_tracks: Vec, pub albums: Vec, pub similar_artists: Vec, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct LyricLine { pub time_ms: u64, pub text: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TrackLyrics { pub track_id: String, pub is_synced: bool, pub lines: Vec, pub writers: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SearchResults { pub query: String, pub best_kind: Option, pub best_track: Option, pub best_artist: Option, pub best_album: Option, #[serde(default)] pub best_playlist: Option, pub tracks: Vec, pub artists: Vec, pub albums: Vec, pub playlists: Vec, } #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct LandingData { pub personal_playlists: Vec, pub chart_tracks: Vec, pub new_releases: Vec, pub popular_playlists: Vec, pub vibe_tracks: Vec, pub podcasts: Vec, pub kids_playlists: Vec, } #[derive(Debug, Clone)] pub struct ResolvedStream { pub url: String, pub codec_label: String, pub bitrate_kbps: u32, pub decrypt_key_hex: Option, /// True if server-side loudness gain is already baked into the stream (`downloadInfo.gain`) pub gain_applied: bool, } /// Active Yandex Music 5.129.0 Rotor / My Vibe session state (`POST /rotor/session/new`) #[derive(Debug, Clone, Serialize, Deserialize)] pub struct RotorSession { pub radio_session_id: String, pub batch_id: Option, pub seeds: Vec, pub wave_name: String, pub tracks: Vec, pub terminated: bool, } /// Exact Rotor session feedback event types (from `818` mod 11105) #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum RotorFeedbackKind { RadioStarted, TrackStarted, TrackFinished, Skip, Like, Unlike, Dislike, Undislike, } impl RotorFeedbackKind { pub fn as_str(self) -> &'static str { match self { Self::RadioStarted => "radioStarted", Self::TrackStarted => "trackStarted", Self::TrackFinished => "trackFinished", Self::Skip => "skip", Self::Like => "like", Self::Unlike => "unlike", Self::Dislike => "dislike", Self::Undislike => "undislike", } } } /// Exact Desktop 5.129.0 `POST /plays?clientNow=...` telemetry event payload #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PlayTelemetryEvent { pub play_id: String, pub from: String, pub track_id: String, #[serde(skip_serializing_if = "Option::is_none")] pub album_id: Option, pub timestamp: String, pub start_timestamp: String, pub total_played_seconds: f64, pub end_position_seconds: f64, pub track_length_seconds: f64, pub context: String, #[serde(skip_serializing_if = "Option::is_none")] pub context_item: Option, pub from_cache: bool, pub is_restored: bool, pub seek: bool, pub pause: bool, pub is_repeated: bool, pub change_reason: String, #[serde(skip_serializing_if = "Option::is_none")] pub radio_session_id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub batch_id: Option, } /// Concert item returned by `GET /concerts/feed` #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ConcertItem { pub id: String, pub title: String, pub artist_name: String, pub city: String, pub place: String, pub date: String, pub cover_uri: Option, pub afisha_url: Option, } fn default_wheel_item_type() -> String { "WAVE".to_string() } /// Rotor station / Vibe carousel bubble returned by `POST /wheel/new` or `GET /rotor/stations/dashboard` #[derive(Debug, Clone, Serialize, Deserialize)] pub struct VibeStationSummary { pub id: String, pub title: String, pub subtitle: Option, pub seeds: Vec, pub cover_uri: Option, pub color_hex: Option, #[serde(default)] pub is_artist: bool, #[serde(default)] pub has_link_arrow: bool, /// Exact wheel item kind: "WAVE" | "ALBUM" | "ARTIST" | "NON_MUSIC" | "PROMO_LINK" | "SETTING" | "RESHUFFLE" #[serde(default = "default_wheel_item_type")] pub item_type: String, /// Link or internal route for `PROMO_LINK` items (`data.action.weblink` / `data.link` / `data.url`) #[serde(default)] pub promo_url: Option, /// True when `style == "CONTROL_ACCENT"` or `seeds` contains `"diversity:reshuffle"` #[serde(default)] pub is_reshuffle: bool, } /// All library IDs returned by `GET /library/all-ids` #[derive(Debug, Clone, Default)] pub struct LibraryAllIds { pub liked_track_ids: Vec, pub disliked_track_ids: Vec, pub liked_album_ids: Vec, pub liked_artist_ids: Vec, } /// Mood/genre filter chip returned by `POST /filters/tracks` for "My Favorites" #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TrackFilterChip { pub id: String, pub name: String, /// Bare track IDs (`track.id`, split before `:` from `"trackId:albumId"`) belonging to this chip pub track_ids: HashSet, } impl TrackFilterChip { pub fn matches_track(&self, track: &Track) -> bool { if self.id == "all" { return true; } self.track_ids.contains(&track.id) || self.track_ids.contains(&track.rotor_track_id()) } } /// Exact Yandex Music 5.129.0 `PlaylistPageFilters` chip normalization rule (`9298` offset 199241): /// - Requires at least 3 raw filters total and an `"all"` chip /// - Keeps only non-`"all"` chips with `>= 8` tracks /// - Requires at least 2 eligible chips (or returns empty if fewer than 2 non-empty chips) /// - Returns `[all, ...eligible.take(7)]` (maximum 8 chips total!) pub fn normalize_track_filters(raw: Vec) -> Vec { if raw.len() < 3 { return Vec::new(); } let mut all_chip: Option = None; let mut eligible: Vec = Vec::new(); for chip in raw { if chip.id == "all" { if all_chip.is_none() { all_chip = Some(chip); } } else if chip.track_ids.len() >= 8 { eligible.push(chip); } } let Some(all) = all_chip else { return Vec::new(); }; if eligible.len() < 2 { return Vec::new(); } eligible.truncate(7); let mut out = Vec::with_capacity(1 + eligible.len()); out.push(all); out.extend(eligible); out } /// Leaf item inside `GET /landing3/metatags` tree (Mixes / Genres / Moods / Activities) #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MetatagLeaf { pub id: String, pub title: String, pub cover_uri: Option, pub color_hex: Option, } /// Category tree returned by `GET /landing3/metatags` #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MetatagTree { pub navigation_id: String, pub title: String, pub leaves: Vec, } /// Detail page payload returned by `GET /metatags/{id}` #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MetatagDetail { pub id: String, pub title: String, pub description: Option, pub cover_uri: Option, pub color_hex: Option, pub tracks: Vec, pub albums: Vec, pub artists: Vec, pub playlists: Vec, } /// Optional clickable action link attached to an AI WordsCard (`card.action`). #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct WordsCardAction { pub title: String, pub url: String, } /// External source citation attached to an AI WordsCard / WordsBigCard (`actions[]`). #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct WordsCardSource { pub title: String, pub url: String, pub favicon_url: Option, } /// Official 5.129.0 AI Track Fact / Reply card returned by `POST /words/cards`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct WordsCard { pub id: String, pub track_id: String, pub text: String, pub tags: Vec, pub action: Option, pub actions: Vec, pub big_card_ids: Vec, pub feedback_state: Option, } impl WordsCard { pub fn is_fact(&self) -> bool { self.tags.iter().any(|t| t == "FACT") } pub fn is_liked(&self) -> bool { self.feedback_state .as_deref() .map_or(false, |s| s.eq_ignore_ascii_case("like")) } pub fn is_disliked(&self) -> bool { self.feedback_state .as_deref() .map_or(false, |s| s.eq_ignore_ascii_case("dislike")) } pub fn has_big_card(&self) -> bool { !self.big_card_ids.is_empty() } } /// Expanded full-screen AI fact/story card returned by `POST /words/big-cards`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct WordsBigCard { pub id: String, pub text: String, pub actions: Vec, }