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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! Album data model.
use {
serde::{Deserialize, Serialize},
serde_json::Value,
};
use crate::models::artist::Artist;
/// A music album with full metadata.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct Album {
/// Unique album identifier.
pub id: Option<String>,
/// Album title.
pub title: Option<String>,
/// Version/subtitle.
pub version: Option<String>,
/// Universal Product Code.
pub upc: Option<String>,
/// Qobuz web URL.
pub url: Option<String>,
/// Primary artist.
pub artist: Option<Box<Artist>>,
/// All artists.
pub artists: Option<Vec<Box<Artist>>>,
/// Primary composer.
pub composer: Option<Box<Artist>>,
/// Record label.
pub label: Option<Label>,
/// Primary genre.
pub genre: Option<Genre>,
/// All genres.
pub genres: Option<Vec<Genre>>,
/// Cover art URLs.
pub image: Option<Image>,
/// Total duration in seconds.
pub duration: Option<i32>,
/// Number of tracks.
pub tracks_count: Option<i32>,
/// Number of discs.
pub media_count: Option<i32>,
/// Original release date.
pub release_date_original: Option<String>,
/// Streaming availability date.
pub release_date_stream: Option<String>,
/// Download availability date.
pub release_date_download: Option<String>,
/// Product type identifier.
pub product_type: Option<String>,
/// Release type (album, single, etc.).
pub release_type: Option<String>,
/// Hi-Res audio available.
pub hires: Option<bool>,
/// Hi-Res streaming available.
pub hires_streamable: Option<bool>,
/// Download available.
pub downloadable: Option<bool>,
/// Streaming available.
pub streamable: Option<bool>,
/// List of track IDs (when requested with extra).
pub track_ids: Option<Vec<i32>>,
/// Product URL for commercial information.
pub product_url: Option<String>,
/// Unix timestamp of when the album was released.
pub released_at: Option<i64>,
/// Copyright notice.
pub copyright: Option<String>,
/// Sales metadata.
pub product_sales_factors: Option<Value>,
/// Maximum available bit depth.
pub maximum_bit_depth: Option<i32>,
/// Maximum available sample rate.
pub maximum_sampling_rate: Option<f64>,
/// Maximum channel count.
pub maximum_channel_count: Option<i32>,
}
impl Album {
/// Returns the file extension for the given quality format ID.
///
/// # Arguments
///
/// * `format_id` - Quality format ID (5=MP3, everything else=FLAC)
///
/// # Returns
///
/// The file extension as a static string slice (`"mp3"` or `"flac"`).
#[must_use]
pub const fn extension_for_format(format_id: i32) -> &'static str {
match format_id {
5 => "mp3",
_ => "flac",
}
}
}
/// Music genre.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct Genre {
/// Genre ID.
pub id: Option<i32>,
/// Genre name.
pub name: Option<String>,
/// URL-friendly name.
pub slug: Option<String>,
/// Display color.
pub color: Option<String>,
}
/// Cover art URLs in multiple sizes.
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
pub struct Image {
/// Small thumbnail URL.
pub small: Option<String>,
/// Thumbnail URL.
pub thumbnail: Option<String>,
/// Medium size URL.
pub medium: Option<String>,
/// Large size URL.
pub large: Option<String>,
/// Extra-large URL.
#[serde(rename = "extralarge")]
pub extra_large: Option<String>,
/// Highest resolution URL.
pub mega: Option<String>,
/// Back cover URL.
pub back: Option<String>,
/// Generic/poster URL (returned by some endpoints instead of the size-specific map).
pub url: Option<String>,
}
/// Record label.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct Label {
/// Label ID.
pub id: Option<i32>,
/// Label name.
pub name: Option<String>,
/// URL-friendly name.
pub slug: Option<String>,
}