-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.rs
More file actions
53 lines (46 loc) · 1.28 KB
/
Copy pathutils.rs
File metadata and controls
53 lines (46 loc) · 1.28 KB
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
use std::sync::MutexGuard;
use crate::music::player::MusicPlayer;
// Tag and Audio struct are used because
// serde_json can't serialize AudioStatus, but this can be changed in the future
// by changing how audio works
#[derive(serde::Serialize)]
pub struct Tag {
title: String,
artist: String,
album: String,
genre: String,
}
#[derive(serde::Serialize)]
pub struct Audio {
title: String,
artist: String,
album: String,
path: String,
id: usize,
duration: u64,
cover: String,
}
pub fn create_audio_list(player: MutexGuard<'_, MusicPlayer>, str: &str) -> Vec<Audio> {
let mut audios = Vec::new();
if !str.is_empty() {
for (id, audio) in player.playlists[str].iter().enumerate() {
audios.push(create_audio(audio, &id));
}
} else {
for (id, audio) in player.audios.iter().enumerate() {
audios.push(create_audio(audio, &id));
}
}
audios
}
pub fn create_audio(audio: &crate::music::audio::_Audio, id: &usize) -> Audio {
Audio {
path: audio.path.clone(),
title: audio.tag.title.clone(),
artist: audio.tag.artist.clone(),
album: audio.tag.album.clone(),
duration: audio.duration.as_secs(),
id: *id,
cover: audio.cover.clone(),
}
}