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
use crate::*;
use id3::Timestamp;

#[derive(Default)]
pub struct AnyTag<'a> {
    pub config: Config,
    pub title: Option<&'a str>,
    pub artists: Option<Vec<&'a str>>,
    pub date: Option<Timestamp>,
    pub year: Option<i32>,
    pub duration: Option<f64>,
    pub album_title: Option<&'a str>,
    pub album_artists: Option<Vec<&'a str>>,
    pub album_cover: Option<Picture<'a>>,
    pub track_number: Option<u16>,
    pub total_tracks: Option<u16>,
    pub disc_number: Option<u16>,
    pub total_discs: Option<u16>,
    pub genre: Option<&'a str>,
    pub composer: Option<&'a str>,
    pub comment: Option<&'a str>,
}

impl AudioTagConfig for AnyTag<'_> {
    fn config(&self) -> &Config {
        &self.config
    }
    fn set_config(&mut self, config: Config) {
        self.config = config;
    }
}

impl<'a> AnyTag<'a> {
    pub fn title(&self) -> Option<&str> {
        self.title
    }
    pub fn set_title(&mut self, title: &'a str) {
        self.title = Some(title);
    }
    pub fn artists(&self) -> Option<&[&str]> {
        self.artists.as_deref()
    }
    // set_artists; add_artist
    pub fn date(&self) -> Option<Timestamp> {
        self.date
    }
    pub fn set_date(&mut self, date: Timestamp) {
        self.date = Some(date);
    }
    pub fn year(&self) -> Option<i32> {
        self.year
    }
    pub fn set_year(&mut self, year: i32) {
        self.year = Some(year);
    }
    pub fn duration(&self) -> Option<f64> {
        self.duration
    }
    pub fn album_title(&self) -> Option<&str> {
        self.album_title
    }
    pub fn album_artists(&self) -> Option<&[&str]> {
        self.album_artists.as_deref()
    }
    pub fn track_number(&self) -> Option<u16> {
        self.track_number
    }
    pub fn total_tracks(&self) -> Option<u16> {
        self.total_tracks
    }
    pub fn disc_number(&self) -> Option<u16> {
        self.disc_number
    }
    pub fn total_discs(&self) -> Option<u16> {
        self.total_discs
    }
    pub fn genre(&self) -> Option<&str> {
        self.genre
    }
    pub fn composer(&self) -> Option<&str> {
        self.composer
    }
    pub fn comment(&self) -> Option<&str> {
        self.comment
    }
}

impl AnyTag<'_> {
    pub fn artists_as_string(&self) -> Option<String> {
        self.artists()
            .map(|artists| artists.join(self.config.sep_artist))
    }
    pub fn album_artists_as_string(&self) -> Option<String> {
        self.album_artists()
            .map(|artists| artists.join(self.config.sep_artist))
    }
}