context.rs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. use crate::protocol::spirc::TrackRef;
  2. use librespot_core::spotify_id::SpotifyId;
  3. use serde;
  4. #[derive(Deserialize, Debug)]
  5. pub struct StationContext {
  6. pub uri: Option<String>,
  7. pub next_page_url: String,
  8. #[serde(deserialize_with = "deserialize_protobuf_TrackRef")]
  9. pub tracks: Vec<TrackRef>,
  10. // Not required for core functionality
  11. // pub seeds: Vec<String>,
  12. // #[serde(rename = "imageUri")]
  13. // pub image_uri: String,
  14. // pub subtitle: Option<String>,
  15. // pub subtitles: Vec<String>,
  16. // #[serde(rename = "subtitleUri")]
  17. // pub subtitle_uri: Option<String>,
  18. // pub title: String,
  19. // #[serde(rename = "titleUri")]
  20. // pub title_uri: String,
  21. // pub related_artists: Vec<ArtistContext>,
  22. }
  23. #[derive(Deserialize, Debug)]
  24. pub struct PageContext {
  25. pub uri: String,
  26. pub next_page_url: String,
  27. #[serde(deserialize_with = "deserialize_protobuf_TrackRef")]
  28. pub tracks: Vec<TrackRef>,
  29. // Not required for core functionality
  30. // pub url: String,
  31. // // pub restrictions:
  32. }
  33. #[derive(Deserialize, Debug)]
  34. pub struct TrackContext {
  35. #[serde(rename = "original_gid")]
  36. pub gid: String,
  37. pub uri: String,
  38. pub uid: String,
  39. // Not required for core functionality
  40. // pub album_uri: String,
  41. // pub artist_uri: String,
  42. // pub metadata: MetadataContext,
  43. }
  44. #[derive(Deserialize, Debug)]
  45. #[serde(rename_all = "camelCase")]
  46. pub struct ArtistContext {
  47. artist_name: String,
  48. artist_uri: String,
  49. image_uri: String,
  50. }
  51. #[derive(Deserialize, Debug)]
  52. pub struct MetadataContext {
  53. album_title: String,
  54. artist_name: String,
  55. artist_uri: String,
  56. image_url: String,
  57. title: String,
  58. uid: String,
  59. }
  60. #[allow(non_snake_case)]
  61. fn deserialize_protobuf_TrackRef<'d, D>(de: D) -> Result<Vec<TrackRef>, D::Error>
  62. where
  63. D: serde::Deserializer<'d>,
  64. {
  65. let v: Vec<TrackContext> = serde::Deserialize::deserialize(de)?;
  66. let track_vec = v
  67. .iter()
  68. .map(|v| {
  69. let mut t = TrackRef::new();
  70. // This has got to be the most round about way of doing this.
  71. t.set_gid(SpotifyId::from_base62(&v.gid).unwrap().to_raw().to_vec());
  72. t.set_uri(v.uri.to_owned());
  73. t
  74. })
  75. .collect::<Vec<TrackRef>>();
  76. Ok(track_vec)
  77. }