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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
use crate::testing_prelude::*;
/// Configuration for generating a test album.
#[derive(Debug, Clone)]
pub struct AlbumConfig {
/// Track configurations for the album.
pub tracks: Vec<TrackConfig>,
/// Artist name.
pub artist: &'static str,
/// Album title.
pub album: &'static str,
/// Release year.
pub year: u16,
/// Audio format (bit depth and sample rate).
pub format: SampleFormat,
/// Place tracks in disc subdirectories (e.g., "Disc 1/", "Disc 2/").
pub use_disc_subdirs: bool,
}
/// Configuration for a single track within an album.
#[derive(Debug, Clone)]
pub struct TrackConfig {
/// Track title.
pub title: &'static str,
/// Track number (numeric like "1" or vinyl-style like "A1").
pub track_number: &'static str,
/// Disc number for multi-disc albums.
pub disc_number: Option<&'static str>,
/// Sine wave frequency in Hz for the generated audio.
pub frequency: u32,
/// Duration in seconds (default: 65 if None).
pub duration_secs: Option<u32>,
}
impl Default for AlbumConfig {
fn default() -> Self {
Self {
artist: "Test Artist",
album: "Test Album",
year: 2020,
format: SampleFormat::default(),
use_disc_subdirs: false,
tracks: vec![
TrackConfig {
title: "Track One",
track_number: "1",
disc_number: None,
frequency: 440,
duration_secs: None,
},
TrackConfig {
title: "Track Two",
track_number: "2",
disc_number: None,
frequency: 880,
duration_secs: None,
},
],
}
}
}
impl AlbumConfig {
/// Mock torrent ID used in tests.
pub const TORRENT_ID: u32 = 12345;
/// Create config with specific format, using default metadata.
#[must_use]
pub fn with_format(format: SampleFormat) -> Self {
Self {
format,
..Self::default()
}
}
/// Create a single-disc album configuration for rename tests.
pub fn single_disc() -> Self {
Self {
artist: "Rename Artist",
album: "Single Disc Album",
year: 2024,
format: SampleFormat::default(),
use_disc_subdirs: false,
tracks: vec![
TrackConfig {
title: "Track One",
track_number: "1",
disc_number: None,
frequency: 440,
duration_secs: None,
},
TrackConfig {
title: "Track Two",
track_number: "2",
disc_number: None,
frequency: 880,
duration_secs: None,
},
],
}
}
/// Create a multi-disc album with all files in a flat directory (no disc subdirs).
///
/// Used to test that transcode correctly creates disc subdirectories from flat input.
pub fn multi_disc_flat() -> Self {
Self {
artist: "Rename Artist",
album: "Multi Disc Album Flat",
year: 2024,
format: SampleFormat::default(),
use_disc_subdirs: false,
tracks: vec![
TrackConfig {
title: "First Track",
track_number: "1",
disc_number: Some("1"),
frequency: 440,
duration_secs: None,
},
TrackConfig {
title: "Second Track",
track_number: "2",
disc_number: Some("1"),
frequency: 550,
duration_secs: None,
},
TrackConfig {
title: "Third Track",
track_number: "1",
disc_number: Some("2"),
frequency: 660,
duration_secs: None,
},
TrackConfig {
title: "Fourth Track",
track_number: "2",
disc_number: Some("2"),
frequency: 770,
duration_secs: None,
},
],
}
}
/// Create a multi-disc album with tracks in disc subdirectories.
///
/// Structure: `Disc 1/01 First Track.flac`, `Disc 2/01 Third Track.flac`, etc.
pub fn multi_disc() -> Self {
Self {
artist: "Rename Artist",
album: "Multi Disc Album",
year: 2024,
format: SampleFormat::default(),
use_disc_subdirs: true,
tracks: vec![
TrackConfig {
title: "First Track",
track_number: "1",
disc_number: Some("1"),
frequency: 440,
duration_secs: None,
},
TrackConfig {
title: "Second Track",
track_number: "2",
disc_number: Some("1"),
frequency: 550,
duration_secs: None,
},
TrackConfig {
title: "Third Track",
track_number: "1",
disc_number: Some("2"),
frequency: 660,
duration_secs: None,
},
TrackConfig {
title: "Fourth Track",
track_number: "2",
disc_number: Some("2"),
frequency: 770,
duration_secs: None,
},
],
}
}
/// Create an album with 10 tracks for testing zero-padded track numbers.
pub fn double_digit_tracks() -> Self {
Self {
artist: "Rename Artist",
album: "Double Digit Album",
year: 2024,
format: SampleFormat::default(),
use_disc_subdirs: false,
tracks: (1..=10_u32)
.map(|i| {
let title = match i {
1 => "Track One",
2 => "Track Two",
3 => "Track Three",
4 => "Track Four",
5 => "Track Five",
6 => "Track Six",
7 => "Track Seven",
8 => "Track Eight",
9 => "Track Nine",
10 => "Track Ten",
_ => unreachable!(),
};
TrackConfig {
title,
track_number: Box::leak(i.to_string().into_boxed_str()),
disc_number: None,
frequency: 440 + i * 50,
duration_secs: None,
}
})
.collect(),
}
}
/// Create an album with vinyl-style track numbers (A1, A2, B1, B2).
pub fn vinyl_tracks() -> Self {
Self {
artist: "Rename Artist",
album: "Vinyl Album",
year: 2024,
format: SampleFormat::default(),
use_disc_subdirs: false,
tracks: vec![
TrackConfig {
title: "Side A Track One",
track_number: "A1",
disc_number: None,
frequency: 440,
duration_secs: None,
},
TrackConfig {
title: "Side A Track Two",
track_number: "A2",
disc_number: None,
frequency: 550,
duration_secs: None,
},
TrackConfig {
title: "Side B Track One",
track_number: "B1",
disc_number: None,
frequency: 660,
duration_secs: None,
},
TrackConfig {
title: "Side B Track Two",
track_number: "B2",
disc_number: None,
frequency: 770,
duration_secs: None,
},
],
}
}
/// Create an album with "N of M" track numbers (1 of 4, 2 of 4, etc.).
pub fn of_total_tracks() -> Self {
Self {
artist: "Rename Artist",
album: "Of Total Album",
year: 2024,
format: SampleFormat::default(),
use_disc_subdirs: false,
tracks: vec![
TrackConfig {
title: "First Track",
track_number: "1 of 4",
disc_number: None,
frequency: 440,
duration_secs: None,
},
TrackConfig {
title: "Second Track",
track_number: "2 of 4",
disc_number: None,
frequency: 550,
duration_secs: None,
},
TrackConfig {
title: "Third Track",
track_number: "3 of 4",
disc_number: None,
frequency: 660,
duration_secs: None,
},
TrackConfig {
title: "Fourth Track",
track_number: "4 of 4",
disc_number: None,
frequency: 770,
duration_secs: None,
},
],
}
}
/// Create an album with a 30-second track for testing zoom spectrogram behavior
/// on tracks shorter than the standard 60-second start position.
pub fn track_30s() -> Self {
Self {
artist: "Short Artist",
album: "Short Album",
year: 2024,
format: SampleFormat::default(),
use_disc_subdirs: false,
tracks: vec![TrackConfig {
title: "Short Track",
track_number: "1",
disc_number: None,
frequency: 440,
duration_secs: Some(30),
}],
}
}
/// Create an album with a 1-second track for testing edge case
/// where track is shorter than the 2-second zoom capture window.
pub fn track_1s() -> Self {
Self {
artist: "Very Short Artist",
album: "Very Short Album",
year: 2024,
format: SampleFormat::default(),
use_disc_subdirs: false,
tracks: vec![TrackConfig {
title: "Very Short Track",
track_number: "1",
disc_number: None,
frequency: 440,
duration_secs: Some(1),
}],
}
}
/// Directory name in standard format: `Artist - Album (Year) [WEB] {16-44.1} (FLAC)`
pub fn dir_name(&self) -> String {
format!(
"{} - {} ({}) [WEB] {} (FLAC)",
self.artist,
self.album,
self.year,
self.format.dir_suffix()
)
}
/// Create a temp directory containing only this album's torrent file.
///
/// - Returns [`TempDirectory`] to ensure cleanup when the caller drops it
#[must_use]
pub fn single_torrent_dir(&self) -> TempDirectory {
let dir = TempDirectory::create("single_torrent");
let dest = dir.join(self.torrent_filename());
let src = SAMPLE_SOURCES_DIR.join(self.torrent_filename());
copy(src, &dest).expect("should copy torrent file");
dir
}
/// Torrent filename for this sample set.
#[must_use]
pub fn torrent_filename(&self) -> String {
format!("{}.torrent", self.dir_name())
}
/// Track filename in format: `Artist - Album - 01 Title.flac`
#[must_use]
pub fn track_filename(&self, track: &TrackConfig) -> String {
format!(
"{} - {} - {:02} {}.flac",
self.artist,
self.album,
track.track_number.parse::<u8>().unwrap_or(0),
track.title
)
}
/// Disc subdirectory for a track (e.g., "Disc 1"), if using disc subdirs.
#[must_use]
pub fn disc_subdir(&self, track: &TrackConfig) -> Option<String> {
if self.use_disc_subdirs {
track.disc_number.map(|d| format!("Disc {d}"))
} else {
None
}
}
/// File list in Gazelle API format.
fn file_list(&self) -> String {
self.tracks
.iter()
.map(|t| {
let path = match self.disc_subdir(t) {
Some(subdir) => format!("{}/{}", subdir, self.track_filename(t)),
None => self.track_filename(t),
};
format!("{path}{{{{{{8972941}}}}}}")
})
.collect::<Vec<_>>()
.join("|||")
+ "|||"
}
/// Build a mock API client configured for this album.
///
/// - Reads the generated torrent file
/// - Panics if torrent doesn't exist (call [`AlbumProvider::get`] first)
#[must_use]
pub fn api(&self) -> MockGazelleClient {
let torrent_path = SAMPLE_SOURCES_DIR.join(self.torrent_filename());
let torrent_bytes = read(torrent_path)
.expect("torrent file should exist - ensure AlbumProvider::get() was called first");
build_mock_client(self, torrent_bytes, Self::TORRENT_ID, 123)
}
}
fn build_mock_client(
config: &AlbumConfig,
torrent_bytes: Vec<u8>,
torrent_id: u32,
group_id: u32,
) -> MockGazelleClient {
let torrent = Torrent {
id: torrent_id,
format: Format::FLAC,
encoding: config.format.encoding(),
media: Media::WEB,
remastered: Some(true),
remaster_year: Some(config.year),
file_path: config.dir_name(),
file_list: config.file_list(),
file_count: u32::try_from(config.tracks.len()).expect("track count fits in u32"),
..Torrent::default()
};
let group = Group {
id: group_id,
name: config.album.to_owned(),
year: config.year,
category_name: "Music".to_owned(),
music_info: Some(Credits {
artists: vec![Credit {
id: 1,
name: config.artist.to_owned(),
}],
..Credits::default()
}),
..Group::default()
};
MockGazelleClient::new()
.with_get_torrent(Ok(TorrentResponse {
group: group.clone(),
torrent: torrent.clone(),
}))
.with_get_torrent_group(Ok(GroupResponse {
group,
torrents: vec![torrent],
}))
.with_download_torrent(Ok(torrent_bytes))
.with_upload_torrent(Ok(UploadResponse {
torrent_id: 99999,
group_id,
private: true,
request_id: None,
source: false,
}))
}