455 lines
13 KiB
Rust
455 lines
13 KiB
Rust
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<String>,
|
|
#[serde(default)]
|
|
pub default_email: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ArtistSummary {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub cover_uri: Option<String>,
|
|
pub genres: Vec<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct AlbumSummary {
|
|
pub id: String,
|
|
pub title: String,
|
|
pub year: Option<u32>,
|
|
pub cover_uri: Option<String>,
|
|
pub artists: Vec<ArtistSummary>,
|
|
pub track_count: u32,
|
|
pub genre: Option<String>,
|
|
pub is_explicit: bool,
|
|
/// Official API content type (`album.type` / `album.metaType`, e.g. "album", "single", "podcast", "audiobook")
|
|
#[serde(default)]
|
|
pub content_type: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Track {
|
|
pub id: String,
|
|
pub title: String,
|
|
pub version: Option<String>,
|
|
pub artists: Vec<ArtistSummary>,
|
|
pub album_id: Option<String>,
|
|
pub album_title: Option<String>,
|
|
pub cover_uri: Option<String>,
|
|
pub duration_ms: u64,
|
|
pub is_explicit: bool,
|
|
pub has_lossless: bool,
|
|
pub has_lyrics: bool,
|
|
pub chart_position: Option<u32>,
|
|
pub chart_progress: Option<String>, // "up", "down", "new", "same"
|
|
pub preview_url: Option<String>,
|
|
/// EBU R128 integrated loudness (LUFS) from Yandex Music API (`track.r128.i`)
|
|
#[serde(default)]
|
|
pub r128_i: Option<f32>,
|
|
/// EBU R128 true peak (dBTP) from Yandex Music API (`track.r128.tp`)
|
|
#[serde(default)]
|
|
pub r128_tp: Option<f32>,
|
|
/// Official Yandex Music track palette (`track.derivedColors.average` & `.accent`)
|
|
#[serde(default)]
|
|
pub derived_average_hex: Option<String>,
|
|
#[serde(default)]
|
|
pub derived_accent_hex: Option<String>,
|
|
}
|
|
|
|
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::<Vec<_>>()
|
|
.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<String>,
|
|
pub cover_uri: Option<String>,
|
|
pub track_count: u32,
|
|
pub likes_count: u32,
|
|
pub generated_type: Option<String>, // "playlistOfTheDay", "neverHeard", "recentTracks", etc.
|
|
#[serde(default)]
|
|
pub revision: u32,
|
|
#[serde(default)]
|
|
pub visibility: Option<String>, // "public" | "private"
|
|
#[serde(default)]
|
|
pub playlist_uuid: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct PlaylistDetail {
|
|
pub summary: PlaylistSummary,
|
|
pub tracks: Vec<Track>,
|
|
#[serde(default)]
|
|
pub revision: u32,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct AlbumDetail {
|
|
pub summary: AlbumSummary,
|
|
pub tracks: Vec<Track>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ArtistDetail {
|
|
pub summary: ArtistSummary,
|
|
pub monthly_listeners: u64,
|
|
pub popular_tracks: Vec<Track>,
|
|
pub albums: Vec<AlbumSummary>,
|
|
pub similar_artists: Vec<ArtistSummary>,
|
|
}
|
|
|
|
#[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<LyricLine>,
|
|
pub writers: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct SearchResults {
|
|
pub query: String,
|
|
pub best_kind: Option<String>,
|
|
pub best_track: Option<Track>,
|
|
pub best_artist: Option<ArtistSummary>,
|
|
pub best_album: Option<AlbumSummary>,
|
|
#[serde(default)]
|
|
pub best_playlist: Option<PlaylistSummary>,
|
|
pub tracks: Vec<Track>,
|
|
pub artists: Vec<ArtistSummary>,
|
|
pub albums: Vec<AlbumSummary>,
|
|
pub playlists: Vec<PlaylistSummary>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
|
pub struct LandingData {
|
|
pub personal_playlists: Vec<PlaylistSummary>,
|
|
pub chart_tracks: Vec<Track>,
|
|
pub new_releases: Vec<AlbumSummary>,
|
|
pub popular_playlists: Vec<PlaylistSummary>,
|
|
pub vibe_tracks: Vec<Track>,
|
|
pub podcasts: Vec<AlbumSummary>,
|
|
pub kids_playlists: Vec<PlaylistSummary>,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct ResolvedStream {
|
|
pub url: String,
|
|
pub codec_label: String,
|
|
pub bitrate_kbps: u32,
|
|
pub decrypt_key_hex: Option<String>,
|
|
/// 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<String>,
|
|
pub seeds: Vec<String>,
|
|
pub wave_name: String,
|
|
pub tracks: Vec<Track>,
|
|
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<String>,
|
|
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<String>,
|
|
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<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub batch_id: Option<String>,
|
|
}
|
|
|
|
/// 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<String>,
|
|
pub afisha_url: Option<String>,
|
|
}
|
|
|
|
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<String>,
|
|
pub seeds: Vec<String>,
|
|
pub cover_uri: Option<String>,
|
|
pub color_hex: Option<String>,
|
|
#[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<String>,
|
|
/// 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<String>,
|
|
pub disliked_track_ids: Vec<String>,
|
|
pub liked_album_ids: Vec<String>,
|
|
pub liked_artist_ids: Vec<String>,
|
|
}
|
|
|
|
/// 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<String>,
|
|
}
|
|
|
|
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<TrackFilterChip>) -> Vec<TrackFilterChip> {
|
|
if raw.len() < 3 {
|
|
return Vec::new();
|
|
}
|
|
let mut all_chip: Option<TrackFilterChip> = None;
|
|
let mut eligible: Vec<TrackFilterChip> = 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<String>,
|
|
pub color_hex: Option<String>,
|
|
}
|
|
|
|
/// 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<MetatagLeaf>,
|
|
}
|
|
|
|
/// 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<String>,
|
|
pub cover_uri: Option<String>,
|
|
pub color_hex: Option<String>,
|
|
pub tracks: Vec<Track>,
|
|
pub albums: Vec<AlbumSummary>,
|
|
pub artists: Vec<ArtistSummary>,
|
|
pub playlists: Vec<PlaylistSummary>,
|
|
}
|
|
|
|
/// 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<String>,
|
|
}
|
|
|
|
/// 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<String>,
|
|
pub action: Option<WordsCardAction>,
|
|
pub actions: Vec<WordsCardSource>,
|
|
pub big_card_ids: Vec<String>,
|
|
pub feedback_state: Option<String>,
|
|
}
|
|
|
|
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<WordsCardSource>,
|
|
}
|