Skip to content

Commit bfb7d56

Browse files
committed
Retrieve autoplay contexts over HTTPS and fix repeat/prev/next
Repeat, previous and next used to start playback regardless of the actual playback state. They now start playback only if we were already playing.
1 parent 6dc7a11 commit bfb7d56

4 files changed

Lines changed: 139 additions & 145 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ https://github.com/librespot-org/librespot
4040
- [audio] Improve file opening and seeking performance (breaking)
4141
- [chore] MSRV is now 1.61 (breaking)
4242
- [connect] `DeviceType` moved out of `connect` into `core` (breaking)
43+
- [connect] Update and expose all `spirc` context fields (breaking)
44+
- [connect] Add `Clone, Defaut` traits to `spirc` contexts
45+
- [connect] Autoplay contexts are now retrieved with the `spclient` (breaking)
4346
- [core] Message listeners are registered before authenticating. As a result
4447
there now is a separate `Session::new` and subsequent `session.connect`.
4548
(breaking)
@@ -96,6 +99,8 @@ https://github.com/librespot-org/librespot
9699
`LoadingPause` in `spirc.rs`
97100
- [connect] Handle attempts to play local files better by basically ignoring
98101
attempts to load them in `handle_remote_update` in `spirc.rs`
102+
- [connect] Loading previous or next tracks, or looping back on repeat, will
103+
only start playback when we were already playing
99104
- [connect, playback] Clean up and de-noise events and event firing
100105
- [playback] Handle invalid track start positions by just starting the track
101106
from the beginning

connect/src/context.rs

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,89 @@ use serde::{
88
Deserialize,
99
};
1010

11-
#[derive(Deserialize, Debug)]
11+
#[derive(Deserialize, Debug, Default, Clone)]
1212
pub struct StationContext {
13-
pub uri: Option<String>,
14-
pub next_page_url: String,
13+
pub uri: String,
14+
pub title: String,
15+
#[serde(rename = "titleUri")]
16+
pub title_uri: String,
17+
pub subtitles: Vec<SubtitleContext>,
18+
#[serde(rename = "imageUri")]
19+
pub image_uri: String,
20+
pub seeds: Vec<String>,
1521
#[serde(deserialize_with = "deserialize_protobuf_TrackRef")]
1622
pub tracks: Vec<TrackRef>,
17-
// Not required for core functionality
18-
// pub seeds: Vec<String>,
19-
// #[serde(rename = "imageUri")]
20-
// pub image_uri: String,
21-
// pub subtitle: Option<String>,
22-
// pub subtitles: Vec<String>,
23-
// #[serde(rename = "subtitleUri")]
24-
// pub subtitle_uri: Option<String>,
25-
// pub title: String,
26-
// #[serde(rename = "titleUri")]
27-
// pub title_uri: String,
28-
// pub related_artists: Vec<ArtistContext>,
23+
pub next_page_url: String,
24+
pub correlation_id: String,
25+
pub related_artists: Vec<ArtistContext>,
2926
}
3027

31-
#[derive(Deserialize, Debug)]
28+
#[derive(Deserialize, Debug, Default, Clone)]
3229
pub struct PageContext {
33-
pub uri: String,
34-
pub next_page_url: String,
3530
#[serde(deserialize_with = "deserialize_protobuf_TrackRef")]
3631
pub tracks: Vec<TrackRef>,
37-
// Not required for core functionality
38-
// pub url: String,
39-
// // pub restrictions:
32+
pub next_page_url: String,
33+
pub correlation_id: String,
4034
}
4135

42-
#[derive(Deserialize, Debug)]
36+
#[derive(Deserialize, Debug, Default, Clone)]
4337
pub struct TrackContext {
44-
#[serde(rename = "original_gid")]
45-
pub gid: String,
4638
pub uri: String,
4739
pub uid: String,
48-
// Not required for core functionality
49-
// pub album_uri: String,
50-
// pub artist_uri: String,
51-
// pub metadata: MetadataContext,
40+
pub artist_uri: String,
41+
pub album_uri: String,
42+
#[serde(rename = "original_gid")]
43+
pub gid: String,
44+
pub metadata: MetadataContext,
45+
pub name: String,
5246
}
5347

5448
#[allow(dead_code)]
55-
#[derive(Deserialize, Debug)]
49+
#[derive(Deserialize, Debug, Default, Clone)]
5650
#[serde(rename_all = "camelCase")]
5751
pub struct ArtistContext {
52+
#[serde(rename = "artistName")]
5853
artist_name: String,
59-
artist_uri: String,
54+
#[serde(rename = "imageUri")]
6055
image_uri: String,
56+
#[serde(rename = "artistUri")]
57+
artist_uri: String,
6158
}
6259

6360
#[allow(dead_code)]
64-
#[derive(Deserialize, Debug)]
61+
#[derive(Deserialize, Debug, Default, Clone)]
6562
pub struct MetadataContext {
6663
album_title: String,
6764
artist_name: String,
6865
artist_uri: String,
6966
image_url: String,
7067
title: String,
71-
uid: String,
68+
#[serde(deserialize_with = "bool_from_string")]
69+
is_explicit: bool,
70+
#[serde(deserialize_with = "bool_from_string")]
71+
is_promotional: bool,
72+
decision_id: String,
73+
}
74+
75+
#[allow(dead_code)]
76+
#[derive(Deserialize, Debug, Default, Clone)]
77+
pub struct SubtitleContext {
78+
name: String,
79+
uri: String,
80+
}
81+
82+
fn bool_from_string<'de, D>(de: D) -> Result<bool, D::Error>
83+
where
84+
D: serde::Deserializer<'de>,
85+
{
86+
match String::deserialize(de)?.as_ref() {
87+
"true" => Ok(true),
88+
"false" => Ok(false),
89+
other => Err(D::Error::invalid_value(
90+
Unexpected::Str(other),
91+
&"true or false",
92+
)),
93+
}
7294
}
7395

7496
#[allow(non_snake_case)]

0 commit comments

Comments
 (0)