2021-12-26 20:18:42 +00:00
|
|
|
// TODO : move to metadata
|
|
|
|
|
2021-02-21 18:38:44 +00:00
|
|
|
use crate::core::spotify_id::SpotifyId;
|
2019-10-08 09:31:18 +00:00
|
|
|
use crate::protocol::spirc::TrackRef;
|
2019-03-13 19:35:46 +00:00
|
|
|
|
2021-12-26 20:18:42 +00:00
|
|
|
use serde::{
|
|
|
|
de::{Error, Unexpected},
|
|
|
|
Deserialize,
|
|
|
|
};
|
2019-03-13 19:35:46 +00:00
|
|
|
|
2022-09-30 19:36:20 +00:00
|
|
|
#[derive(Deserialize, Debug, Default, Clone)]
|
2019-03-13 19:35:46 +00:00
|
|
|
pub struct StationContext {
|
2022-09-30 19:36:20 +00:00
|
|
|
pub uri: String,
|
|
|
|
pub title: String,
|
|
|
|
#[serde(rename = "titleUri")]
|
|
|
|
pub title_uri: String,
|
|
|
|
pub subtitles: Vec<SubtitleContext>,
|
|
|
|
#[serde(rename = "imageUri")]
|
|
|
|
pub image_uri: String,
|
|
|
|
pub seeds: Vec<String>,
|
2019-03-13 19:35:46 +00:00
|
|
|
#[serde(deserialize_with = "deserialize_protobuf_TrackRef")]
|
|
|
|
pub tracks: Vec<TrackRef>,
|
2022-09-30 19:36:20 +00:00
|
|
|
pub next_page_url: String,
|
|
|
|
pub correlation_id: String,
|
|
|
|
pub related_artists: Vec<ArtistContext>,
|
2019-03-13 19:35:46 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 19:36:20 +00:00
|
|
|
#[derive(Deserialize, Debug, Default, Clone)]
|
2019-03-13 19:35:46 +00:00
|
|
|
pub struct PageContext {
|
|
|
|
#[serde(deserialize_with = "deserialize_protobuf_TrackRef")]
|
|
|
|
pub tracks: Vec<TrackRef>,
|
2022-09-30 19:36:20 +00:00
|
|
|
pub next_page_url: String,
|
|
|
|
pub correlation_id: String,
|
2019-03-13 19:35:46 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 19:36:20 +00:00
|
|
|
#[derive(Deserialize, Debug, Default, Clone)]
|
2019-03-13 19:35:46 +00:00
|
|
|
pub struct TrackContext {
|
|
|
|
pub uri: String,
|
|
|
|
pub uid: String,
|
2022-09-30 19:36:20 +00:00
|
|
|
pub artist_uri: String,
|
|
|
|
pub album_uri: String,
|
|
|
|
#[serde(rename = "original_gid")]
|
|
|
|
pub gid: String,
|
|
|
|
pub metadata: MetadataContext,
|
|
|
|
pub name: String,
|
2019-03-13 19:35:46 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 17:47:51 +00:00
|
|
|
#[allow(dead_code)]
|
2022-09-30 19:36:20 +00:00
|
|
|
#[derive(Deserialize, Debug, Default, Clone)]
|
2019-03-13 19:35:46 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ArtistContext {
|
2022-09-30 19:36:20 +00:00
|
|
|
#[serde(rename = "artistName")]
|
2019-03-13 19:35:46 +00:00
|
|
|
artist_name: String,
|
2022-09-30 19:36:20 +00:00
|
|
|
#[serde(rename = "imageUri")]
|
2019-03-13 19:35:46 +00:00
|
|
|
image_uri: String,
|
2022-09-30 19:36:20 +00:00
|
|
|
#[serde(rename = "artistUri")]
|
|
|
|
artist_uri: String,
|
2019-03-13 19:35:46 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 17:47:51 +00:00
|
|
|
#[allow(dead_code)]
|
2022-09-30 19:36:20 +00:00
|
|
|
#[derive(Deserialize, Debug, Default, Clone)]
|
2019-03-13 19:35:46 +00:00
|
|
|
pub struct MetadataContext {
|
|
|
|
album_title: String,
|
|
|
|
artist_name: String,
|
|
|
|
artist_uri: String,
|
|
|
|
image_url: String,
|
|
|
|
title: String,
|
2022-09-30 19:36:20 +00:00
|
|
|
#[serde(deserialize_with = "bool_from_string")]
|
|
|
|
is_explicit: bool,
|
|
|
|
#[serde(deserialize_with = "bool_from_string")]
|
|
|
|
is_promotional: bool,
|
|
|
|
decision_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[derive(Deserialize, Debug, Default, Clone)]
|
|
|
|
pub struct SubtitleContext {
|
|
|
|
name: String,
|
|
|
|
uri: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bool_from_string<'de, D>(de: D) -> Result<bool, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
|
|
|
match String::deserialize(de)?.as_ref() {
|
|
|
|
"true" => Ok(true),
|
|
|
|
"false" => Ok(false),
|
|
|
|
other => Err(D::Error::invalid_value(
|
|
|
|
Unexpected::Str(other),
|
|
|
|
&"true or false",
|
|
|
|
)),
|
|
|
|
}
|
2019-03-13 19:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(non_snake_case)]
|
2019-03-15 14:50:15 +00:00
|
|
|
fn deserialize_protobuf_TrackRef<'d, D>(de: D) -> Result<Vec<TrackRef>, D::Error>
|
2019-03-13 19:35:46 +00:00
|
|
|
where
|
2019-03-15 14:50:15 +00:00
|
|
|
D: serde::Deserializer<'d>,
|
2019-03-13 19:35:46 +00:00
|
|
|
{
|
2019-10-08 09:31:18 +00:00
|
|
|
let v: Vec<TrackContext> = serde::Deserialize::deserialize(de)?;
|
2021-12-26 20:18:42 +00:00
|
|
|
v.iter()
|
2019-03-13 19:35:46 +00:00
|
|
|
.map(|v| {
|
|
|
|
let mut t = TrackRef::new();
|
|
|
|
// This has got to be the most round about way of doing this.
|
2021-12-26 20:18:42 +00:00
|
|
|
t.set_gid(
|
|
|
|
SpotifyId::from_base62(&v.gid)
|
|
|
|
.map_err(|_| {
|
|
|
|
D::Error::invalid_value(
|
|
|
|
Unexpected::Str(&v.gid),
|
|
|
|
&"a Base-62 encoded Spotify ID",
|
|
|
|
)
|
|
|
|
})?
|
|
|
|
.to_raw()
|
|
|
|
.to_vec(),
|
|
|
|
);
|
2019-03-13 19:35:46 +00:00
|
|
|
t.set_uri(v.uri.to_owned());
|
2021-12-26 20:18:42 +00:00
|
|
|
Ok(t)
|
2019-03-13 19:35:46 +00:00
|
|
|
})
|
2021-12-26 20:18:42 +00:00
|
|
|
.collect::<Result<Vec<TrackRef>, D::Error>>()
|
2019-03-13 19:35:46 +00:00
|
|
|
}
|