1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use crate::protocol::spirc::TrackRef;
use librespot_core::spotify_id::SpotifyId;
use serde;
#[derive(Deserialize, Debug)]
pub struct StationContext {
pub uri: Option<String>,
pub next_page_url: String,
#[serde(deserialize_with = "deserialize_protobuf_TrackRef")]
pub tracks: Vec<TrackRef>,
}
#[derive(Deserialize, Debug)]
pub struct PageContext {
pub uri: String,
pub next_page_url: String,
#[serde(deserialize_with = "deserialize_protobuf_TrackRef")]
pub tracks: Vec<TrackRef>,
}
#[derive(Deserialize, Debug)]
pub struct TrackContext {
#[serde(rename = "original_gid")]
pub gid: String,
pub uri: String,
pub uid: String,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ArtistContext {
artist_name: String,
artist_uri: String,
image_uri: String,
}
#[derive(Deserialize, Debug)]
pub struct MetadataContext {
album_title: String,
artist_name: String,
artist_uri: String,
image_url: String,
title: String,
uid: String,
}
#[allow(non_snake_case)]
fn deserialize_protobuf_TrackRef<'d, D>(de: D) -> Result<Vec<TrackRef>, D::Error>
where
D: serde::Deserializer<'d>,
{
let v: Vec<TrackContext> = serde::Deserialize::deserialize(de)?;
let track_vec = v
.iter()
.map(|v| {
let mut t = TrackRef::new();
t.set_gid(SpotifyId::from_base62(&v.gid).unwrap().to_raw().to_vec());
t.set_uri(v.uri.to_owned());
t
})
.collect::<Vec<TrackRef>>();
Ok(track_vec)
}