1mod albums;
2mod artists;
3pub mod auth;
4pub mod batch;
5mod favourites;
6pub mod history;
7pub mod lyrics;
8pub mod playback_state;
9pub mod playlists;
10pub mod radio;
11mod scan_cache;
12mod search;
13mod stats;
14pub mod tracks;
15pub mod vectors;
16
17use std::path::PathBuf;
18
19pub use albums::*;
21pub use artists::*;
22pub use batch::*;
23pub use favourites::*;
24pub use history::*;
25pub use lyrics::*;
26pub use playback_state::*;
27pub use playlists::*;
28pub use radio::*;
29pub use scan_cache::*;
30pub use search::*;
31pub use stats::*;
32pub use tracks::*;
33pub use vectors::*;
34
35pub fn folder_prefix_range(folder: &std::path::Path) -> (String, String) {
48 let prefix = format!(
49 "{}{}",
50 folder
51 .to_string_lossy()
52 .trim_end_matches(std::path::MAIN_SEPARATOR),
53 std::path::MAIN_SEPARATOR
54 );
55 let upper = format!("{prefix}\u{10FFFF}");
56 (prefix, upper)
57}
58
59#[derive(Debug, Clone)]
62pub struct ArtistRow {
63 pub id: i64,
64 pub name: String,
65 pub sort_name: Option<String>,
66 pub remote_id: Option<String>,
67 pub album_count: i64,
71 pub track_count: i64,
72}
73
74#[derive(Debug, Clone)]
75pub struct AlbumRow {
76 pub id: i64,
77 pub title: String,
78 pub artist_id: i64,
79 pub artist_name: String,
80 pub date: Option<String>,
81 pub total_discs: Option<i32>,
82 pub total_tracks: Option<i32>,
83 pub codec: Option<String>,
84 pub label: Option<String>,
85 pub remote_id: Option<String>,
86 pub added_at: Option<String>,
89}
90
91#[derive(Debug, Clone)]
92pub struct TrackRow {
93 pub id: i64,
94 pub album_id: Option<i64>,
95 pub artist_id: Option<i64>,
96 pub artist_name: String,
97 pub album_artist_name: String,
98 pub album_title: String,
99 pub disc: Option<i32>,
100 pub track_number: Option<i32>,
101 pub title: String,
102 pub duration_ms: Option<i64>,
103 pub path: Option<String>,
104 pub codec: Option<String>,
105 pub sample_rate: Option<i32>,
106 pub bit_depth: Option<i32>,
107 pub channels: Option<i32>,
108 pub bitrate: Option<i32>,
109 pub genre: Option<String>,
110 pub source: String,
111 pub remote_id: Option<String>,
112 pub cached_path: Option<String>,
113}
114
115#[derive(Debug, Clone)]
117pub enum PlaybackSource {
118 Local(PathBuf),
119 Cached(PathBuf),
120 Remote(String),
121}
122
123#[derive(Debug, Clone, Default)]
124pub struct LibraryStats {
125 pub total_tracks: i64,
126 pub local_tracks: i64,
127 pub remote_tracks: i64,
128 pub cached_tracks: i64,
129 pub total_albums: i64,
130 pub total_artists: i64,
131}
132
133#[derive(Debug, Clone)]
135pub struct TrackMeta {
136 pub title: String,
137 pub artist: String,
138 pub album_artist: Option<String>,
139 pub album: String,
140 pub date: Option<String>,
141 pub disc: Option<i32>,
142 pub track_number: Option<i32>,
143 pub genre: Option<String>,
144 pub label: Option<String>,
145 pub duration_ms: Option<i64>,
146 pub codec: Option<String>,
147 pub sample_rate: Option<i32>,
148 pub bit_depth: Option<i32>,
149 pub channels: Option<i32>,
150 pub bitrate: Option<i32>,
151 pub size_bytes: Option<i64>,
152 pub mtime: Option<i64>,
153 pub path: Option<String>,
154 pub source: String,
155 pub remote_id: Option<String>,
156 pub remote_url: Option<String>,
157 pub album_remote_id: Option<String>,
163 pub artist_remote_id: Option<String>,
164 pub mbid: Option<String>,
167 pub album_added_at: Option<String>,
171}
172
173#[cfg(test)]
175pub fn sample_meta(title: &str, artist: &str, album: &str) -> TrackMeta {
176 TrackMeta {
177 title: title.into(),
178 artist: artist.into(),
179 album_artist: Some(artist.into()),
180 album: album.into(),
181 date: Some("2024".into()),
182 disc: Some(1),
183 track_number: Some(1),
184 genre: Some("Electronic".into()),
185 label: None,
186 duration_ms: Some(240_000),
187 codec: Some("FLAC".into()),
188 sample_rate: Some(44100),
189 bit_depth: Some(16),
190 channels: Some(2),
191 bitrate: Some(1000),
192 size_bytes: Some(30_000_000),
193 mtime: Some(1700000000),
194 path: Some(format!("/music/{}/{}.flac", album, title)),
195 source: "local".into(),
196 remote_id: None,
197 album_remote_id: None,
198 artist_remote_id: None,
199 mbid: None,
200 remote_url: None,
201 album_added_at: None,
202 }
203}