aboutsummaryrefslogtreecommitdiff
path: root/src/song.rs
blob: f1a10ebd7ad7cb31bf2c5b388e2cad93340801ab (plain)
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
use mpd::{Client, Song};

#[derive(Debug)]
#[derive(Clone )]
pub struct RSong {
    pub file: String,
    pub artist: Option<String>,
    pub title: Option<String>,
    pub duration: Option<u32>,
    pub last_mod: Option<String>,
    pub name: Option<String>,
    pub place: Option<String>,
    pub range: Option<String>,
    pub tags: Vec<(String, String)>,
}

impl RSong {
    pub fn new(c: &mut Client, filename: String) -> Self {
        let mut s = RSong {
            file: filename.clone(),
            artist: None,
            title: None,
            duration: None,
            last_mod: None,
            name: None,
            place: None,
            range: None,
            tags: vec![],
        };

        // Dummy song

        let song = Song {
            file: filename.clone(),
            artist: None,
            title: None,
            duration: None,
            last_mod: None,
            name: None,
            place: None,
            range: None,
            tags: vec![("".to_string(), "".to_string())],
        };

        for (k, v) in (c.readcomments(song).unwrap()).flatten() {
            if k.to_lowercase().contains("artist") {
                s.artist = Some(v);
            } else if k.to_lowercase().contains("title") {
                s.title = Some(v);
            } else if k.to_lowercase().contains("duration") {
                s.duration = Some(v.parse::<u32>().unwrap());
            } else if k.to_lowercase().contains("lastmod") {
                s.last_mod = Some(v);
            } else if k.to_lowercase().contains("name") {
                s.name = Some(v);
            } else if k.to_lowercase().contains("place") {
                s.place = Some(v);
            } else if k.to_lowercase().contains("range") {
                s.range = Some(v);
            } else {
                s.tags.push((k, v));
            }
        }

        s
    }
}