aboutsummaryrefslogtreecommitdiff
path: root/src/song.rs
diff options
context:
space:
mode:
authorkrolxon <krolyxon@tutanota.com>2024-04-26 14:32:58 +0530
committerkrolxon <krolyxon@tutanota.com>2024-04-26 14:32:58 +0530
commit04e5d2ad28af2c0b561ed4443eabddc4ee70d1f2 (patch)
tree771937cfad99e1fed9d0aeead9d5f88e28c6f8e9 /src/song.rs
parent59e8e8cbe67b969d120035a642dc99ccb0dff5eb (diff)
alot of edge cases removed, ui improvments
Diffstat (limited to 'src/song.rs')
-rwxr-xr-xsrc/song.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/song.rs b/src/song.rs
new file mode 100755
index 0000000..f1a10eb
--- /dev/null
+++ b/src/song.rs
@@ -0,0 +1,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
+ }
+}