lavalink_rs/model/
track.rs

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use crate::model::deserialize_option_number;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyo3::pyclass(get_all, set_all))]
/// The type of data returned when loading a track.
pub enum TrackLoadType {
    Track,
    Playlist,
    Search,
    Empty,
    Error,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", untagged)]
/// The data returned when loading a track.
pub enum TrackLoadData {
    /// A track has been loaded.
    Track(TrackData),
    /// A playlist has been loaded.
    Playlist(PlaylistData),
    /// A search result has been loaded.
    Search(Vec<TrackData>),
    /// Loading has failed with an error.
    Error(TrackError),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
/// Loaded track data.
pub struct Track {
    /// The type of the result.
    pub load_type: TrackLoadType,
    /// The data of the result.
    pub data: Option<TrackLoadData>,
}

#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyo3::pyclass)]
/// Information about a track.
pub struct TrackData {
    /// The base64 encoded track data.
    pub encoded: String,
    /// Info and metadata about the track.
    pub info: TrackInfo,
    /// Addition track info provided by plugins.
    pub plugin_info: Option<serde_json::Value>,
    /// Additional track data provided via the `UpdatePlayer` endpoint.
    pub user_data: Option<serde_json::Value>,
}

#[derive(Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyo3::pyclass(get_all, set_all))]
/// Information and metadata about the track.
pub struct TrackInfo {
    /// The track identifier.
    pub identifier: String,
    /// Whether the track is seekable.
    pub is_seekable: bool,
    /// The track author.
    pub author: String,
    /// The track length in milliseconds.
    pub length: u64,
    /// Whether the track is a stream.
    pub is_stream: bool,
    /// The track starting position in milliseconds.
    pub position: u64,
    /// The track title,
    pub title: String,
    /// The track uri.
    pub uri: Option<String>,
    /// The track artwork url.
    pub artwork_url: Option<String>,
    /// The track "International Standard Recording Code".
    pub isrc: Option<String>,
    /// The track source name.
    pub source_name: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyo3::pyclass)]
pub struct PlaylistData {
    /// The information of the playlist.
    pub info: PlaylistInfo,
    /// The tracks of the playlist.
    pub tracks: Vec<TrackData>,
    /// Addition playlist information provided by plugins.
    pub plugin_info: Option<serde_json::Value>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyo3::pyclass(get_all, set_all))]
pub struct PlaylistInfo {
    /// The name of the playlist.
    pub name: String,
    #[serde(deserialize_with = "deserialize_option_number")]
    /// The selected track of the playlist.
    ///
    /// None if no track is selected.
    pub selected_track: Option<u32>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "python", pyo3::pyclass(get_all, set_all))]
pub struct TrackError {
    /// The message of the exception.
    pub message: String,
    /// The severity of the exception.
    pub severity: String,
    /// The cause of the exception.
    pub cause: String,
}