spotify_rs/model/
player.rs

1use chrono::{DateTime, Utc};
2use serde::Deserialize;
3use spotify_rs_macros::docs;
4
5use super::{track::Track, *};
6
7/// The current user's playback state.
8#[derive(Clone, Debug, Deserialize, PartialEq)]
9pub struct PlaybackState {
10    /// The currently active device.
11    pub device: Option<Device>,
12    /// The repeat state.
13    pub repeat_state: Option<RepeatState>,
14    /// Whether or not shuffle is enabled.
15    pub shuffle_state: Option<bool>,
16    /// The context the item is being played from. (e.g. arist, playlist, album
17    /// or show.
18    pub context: Option<Context>,
19    /// A Unix timestamp of when the playback state was last changed.
20    pub timestamp: u64,
21    /// The playback position in miliseconds.
22    pub progress_ms: Option<u32>,
23    /// Whether or not the user is playing something.
24    pub is_playing: bool,
25    /// The currently playing item - a track or episode.
26    pub item: Option<PlayableItem>,
27    /// The type of the currently playing item. It may have more variants than `item`.
28    pub currently_playing_type: CurrentlyPlayingType,
29    /// Allows to update the user interface based on which playback actions
30    /// are currently available.
31    pub actions: Actions,
32}
33
34/// A device.
35#[derive(Clone, Debug, Deserialize, PartialEq)]
36pub struct Device {
37    /// The device ID. It is unique and may be persistent, but persistence is
38    /// not guaranteed, so it shouldn't be cached for long periods.
39    pub id: Option<String>,
40    /// Whether or not the device is currently active.
41    pub is_active: bool,
42    /// Whether or not the device is in a private playback session.
43    pub is_private_session: bool,
44    /// Whether or not the device is currently restricted. If `true`, the Web API  commands won't be accepted by the device.
45    pub is_restricted: bool,
46    /// The human-readable name for the device.
47    pub name: String,
48    /// The type of the device (e.g. computer, smartphone, speaker).
49    pub r#type: String,
50    /// The current volume percentage.
51    pub volume_percent: Option<u32>,
52    /// Whether or not the device allows setting the volume.
53    pub supports_volume: bool,
54}
55
56// Used only to deserialize JSON responses with arrays that are named objects.
57#[derive(Clone, Debug, Deserialize, PartialEq)]
58pub(crate) struct Devices {
59    pub(crate) devices: Vec<Device>,
60}
61
62/// The context an item is played from.
63#[derive(Clone, Debug, Deserialize, PartialEq)]
64#[docs]
65pub struct Context {
66    /// The type of the context (e.g. artist, playlist, album, show).
67    pub r#type: String,
68    pub href: String,
69    pub external_urls: ExternalUrls,
70    pub uri: String,
71}
72
73/// Allows to update the user interface based on which playback actions
74/// are currently available.
75#[derive(Clone, Debug, Deserialize, PartialEq)]
76pub struct Actions {
77    /// The disallowed actions.
78    pub disallows: Disallows,
79}
80
81/// Contains (optional) disallowewd actions.
82#[derive(Clone, Debug, Deserialize, PartialEq)]
83pub struct Disallows {
84    pub interrupting_playback: Option<bool>,
85    pub pausing: Option<bool>,
86    pub resuming: Option<bool>,
87    pub seeking: Option<bool>,
88    pub skipping_next: Option<bool>,
89    pub skipping_prev: Option<bool>,
90    pub toggling_repeat_context: Option<bool>,
91    pub toggling_shuffle: Option<bool>,
92    pub toggling_repeat_track: Option<bool>,
93    pub transferring_playback: Option<bool>,
94}
95
96/// Represents the history entry of a played item.
97#[derive(Clone, Debug, Deserialize, PartialEq)]
98pub struct PlayHistory {
99    /// The track that was played.
100    pub track: Track,
101    /// The date and time the track was played.
102    pub played_at: DateTime<Utc>,
103    /// The context the track was played from.
104    pub context: Option<Context>,
105}
106
107/// A user's queue.
108#[derive(Clone, Debug, Deserialize, PartialEq)]
109pub struct Queue {
110    /// The currently playing item.
111    pub currently_playing: Option<PlayableItem>,
112    /// The items in the queue.
113    pub queue: Vec<PlayableItem>,
114}
115
116/// Represents the item that's currently playing.
117#[derive(Clone, Debug, Deserialize, PartialEq)]
118pub struct CurrentlyPlayingItem {
119    /// The context the track is being played from.
120    pub context: Option<Context>,
121    /// A Unix timestamp of when the playback state was last changed.
122    pub timestamp: u64,
123    /// The playback position in miliseconds.
124    pub progress_ms: Option<u32>,
125    /// Whether or not the track is currently playing.
126    pub is_playing: bool,
127    /// The currently playing item - a track or episode.
128    pub item: Option<PlayableItem>,
129    /// The type of the currently playing item. It may have more variants than `item`.
130    pub currently_playing_type: CurrentlyPlayingType,
131    /// Allows to update the user interface based on which playback actions
132    /// are currently available.
133    pub actions: Actions,
134}
135
136/// The repeat state of the playback.
137#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
138#[serde(rename_all = "snake_case")]
139pub enum RepeatState {
140    /// After the current item ends, it won't repeat.
141    Off,
142    /// After the current item ends, the item will be repeated.
143    Track,
144    /// After the current item ends, the context of the item will be repeated
145    /// (e.g. the playlist).
146    Context,
147}
148
149/// The type of the currently playing item.
150#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
151#[serde(rename_all = "snake_case")]
152pub enum CurrentlyPlayingType {
153    /// A track.
154    Track,
155    /// An episode.
156    Episode,
157    /// An ad.
158    Ad,
159    /// An unknown item.
160    Unknown,
161}