From 9fac9ef777b3317ef2bd4b72bbe59c8b751de4a7 Mon Sep 17 00:00:00 2001 From: MrDulfin Date: Mon, 20 May 2024 00:39:51 -0400 Subject: [PATCH] updated Playlist functions --- src/music_storage/playlist.rs | 53 ++++++++++++----------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/src/music_storage/playlist.rs b/src/music_storage/playlist.rs index 788e59b..1f04860 100644 --- a/src/music_storage/playlist.rs +++ b/src/music_storage/playlist.rs @@ -1,4 +1,3 @@ -use std::default; use std::error::Error; use std::{ fs::File, @@ -60,66 +59,50 @@ impl Playlist { self.play_time } - fn title(&self) -> &String { + pub fn title(&self) -> &String { &self.title } - fn cover(&self) -> Option<&AlbumArt> { + pub fn cover(&self) -> Option<&AlbumArt> { match &self.cover { Some(e) => Some(e), None => None, } } - fn tracks(&self) -> Vec { + pub fn tracks(&self) -> Vec { self.tracks.to_owned() } + pub fn set_tracks(&mut self, tracks: Vec) { self.tracks = tracks; } + pub fn add_track(&mut self, track: Uuid) { self.tracks.push(track); } + pub fn remove_track(&mut self, index: i32) { let index = index as usize; if (self.tracks.len() - 1) >= index { self.tracks.remove(index); } } - // pub fn get_index(&self, song_name: &str) -> Option { - // let mut index = 0; - // if self.contains_value(&Tag::Title, song_name) { - // for track in &self.tracks { - // index += 1; - // if song_name == track.tags.get_key_value(&Tag::Title).unwrap().1 { - // dbg!("Index gotted! ", index); - // return Some(index); - // } - // } - // } - // None - // } - pub fn contains_value( - &self, - tag: &Tag, - value: &String, - lib: Arc>, - ) -> bool { - let lib = lib.read().unwrap(); - let items = match lib.query_tracks(value, &vec![tag.to_owned()], &vec![tag.to_owned()]) { - Some(e) => e, - None => return false, - }; - - for item in items { - for uuid in &self.tracks { - if uuid == &item.uuid { - return true; + pub fn get_index(&self, uuid: Uuid) -> Option { + let mut i = 0; + if self.contains(uuid) { + for track in &self.tracks { + i += 1; + if &uuid == track { + dbg!("Index gotted! ", i); + return Some(i); } } } - - false + None + } + pub fn contains(&self, uuid: Uuid) -> bool { + self.get_index(uuid).is_some() } pub fn to_file(&self, path: &str) -> Result<(), Box> {