diff --git a/src/config/config.rs b/src/config/config.rs index ee86c15..cac729d 100644 --- a/src/config/config.rs +++ b/src/config/config.rs @@ -2,7 +2,7 @@ use std::{path::PathBuf, marker::PhantomData}; #[derive(Debug, Default)] pub struct Config { - db_path: Option, + pub db_path: Option, } impl Config { @@ -13,4 +13,4 @@ impl Config { pub fn load(&self) { } -} \ No newline at end of file +} diff --git a/src/music_controller/controller.rs b/src/music_controller/controller.rs index 8d1c8b6..94509d8 100644 --- a/src/music_controller/controller.rs +++ b/src/music_controller/controller.rs @@ -1 +1,24 @@ - +//! The [Controller] is the input and output for the entire +//! player. It manages queues, playback, library access, and +//! other functions + +use crate::{ + music_player::Player, + music_storage::library::Song, + config::config::Config +}; + +struct Queue { + player: Player, + name: String, + songs: Vec, +} + +pub struct Controller { + queues: Vec, + config: Config, +} + +impl Controller { + // more stuff to come +} diff --git a/src/music_storage/library.rs b/src/music_storage/library.rs index 5394652..873865f 100644 --- a/src/music_storage/library.rs +++ b/src/music_storage/library.rs @@ -1,6 +1,7 @@ -use super::music_collection::MusicCollection; // Crate things use super::utils::{find_images, normalize, read_library, write_library}; +use super::music_collection::MusicCollection; +use crate::config::config::Config; // Various std things use std::collections::BTreeMap; @@ -269,6 +270,16 @@ pub struct Album<'a> { #[allow(clippy::len_without_is_empty)] impl Album<'_> { + //returns the Album title + fn title(&self) -> &String { + self.title + } + + /// Returns the album cover as an AlbumArt struct, if it exists + fn cover(&self) -> Option<&AlbumArt> { + self.cover + } + /// Returns the Album Artist, if they exist pub fn artist(&self) -> Option<&String> { self.artist @@ -283,6 +294,14 @@ impl Album<'_> { Some(self.discs.get(&disc)?[index]) } + fn tracks(&self) -> Vec<&Song> { + let mut songs = Vec::new(); + for disc in &self.discs { + songs.append(&mut disc.1.clone()) + } + songs + } + /// Returns the number of songs in the album pub fn len(&self) -> usize { let mut total = 0; @@ -292,23 +311,6 @@ impl Album<'_> { total } } -impl MusicCollection for Album<'_> { - //returns the Album title - fn title(&self) -> &String { - self.title - } - /// Returns the album cover as an AlbumArt struct, if it exists - fn cover(&self) -> Option<&AlbumArt> { - self.cover - } - fn tracks(&self) -> Vec<&Song> { - let mut songs = Vec::new(); - for disc in &self.discs { - songs.append(&mut disc.1.clone()) - } - songs - } -} const BLOCKED_EXTENSIONS: [&str; 4] = ["vob", "log", "txt", "sf2"]; @@ -327,20 +329,20 @@ impl MusicLibrary { let global_config = &*config.read().unwrap(); let mut library: Vec = Vec::new(); let mut backup_path = global_config.db_path.clone(); - backup_path.set_extension("bkp"); + backup_path.unwrap().set_extension("bkp"); - match global_config.db_path.exists() { + match global_config.db_path.unwrap().exists() { true => { - library = read_library(global_config.db_path.clone())?; + library = read_library(global_config.db_path.unwrap().clone())?; } false => { // Create the database if it does not exist // possibly from the backup file - if backup_path.exists() { - library = read_library(backup_path.clone())?; - write_library(&library, global_config.db_path.to_path_buf(), false)?; + if backup_path.unwrap().exists() { + library = read_library(backup_path.unwrap().clone())?; + write_library(&library, global_config.db_path.unwrap().to_path_buf(), false)?; } else { - write_library(&library, global_config.db_path.to_path_buf(), false)?; + write_library(&library, global_config.db_path.unwrap().to_path_buf(), false)?; } } }; @@ -350,9 +352,9 @@ impl MusicLibrary { /// Serializes the database out to the file specified in the config pub fn save(&self, config: &Config) -> Result<(), Box> { - match config.db_path.try_exists() { + match config.db_path.unwrap().try_exists() { Ok(exists) => { - write_library(&self.library, config.db_path.to_path_buf(), exists)?; + write_library(&self.library, config.db_path.unwrap().to_path_buf(), exists)?; } Err(error) => return Err(error.into()), } diff --git a/src/music_storage/music_collection.rs b/src/music_storage/music_collection.rs index 9b1c7ca..964c79a 100644 --- a/src/music_storage/music_collection.rs +++ b/src/music_storage/music_collection.rs @@ -3,5 +3,5 @@ use crate::music_storage::library::{AlbumArt, Song}; pub trait MusicCollection { fn title(&self) -> &String; fn cover(&self) -> Option<&AlbumArt>; - fn tracks(&self) -> Vec<&Song>; + fn tracks(&self) -> Vec; } diff --git a/src/music_storage/playlist.rs b/src/music_storage/playlist.rs index 4ad49dd..62b3aa9 100644 --- a/src/music_storage/playlist.rs +++ b/src/music_storage/playlist.rs @@ -1,15 +1,15 @@ +use std::path::Path; + use chrono::Duration; use walkdir::Error; use super::{ - db_reader::extern_library::ExternalLibrary, - library::{self, AlbumArt, Song, Tag}, - music_collection::MusicCollection, + library::{AlbumArt, Song, Tag}, + music_collection::MusicCollection, db_reader::{ + xml::reader::XmlLibrary, + extern_library::ExternalLibrary + }, }; -use crate::music_storage::db_reader::xml::reader::XmlLibrary; - -use std::io::Read; -use std::{default, path::Path, path::PathBuf, thread::AccessError}; use m3u8_rs::{MediaPlaylist, MediaPlaylistType, MediaSegment}; // use nom::IResult; @@ -18,7 +18,7 @@ use m3u8_rs::{MediaPlaylist, MediaPlaylistType, MediaSegment}; pub struct Playlist<'a> { title: String, cover: Option<&'a AlbumArt>, - tracks: Vec<&'a Song>, + tracks: Vec, play_count: i32, play_time: Duration, } @@ -32,11 +32,11 @@ impl<'a> Playlist<'a> { pub fn play_time(&self) -> chrono::Duration { self.play_time } - pub fn set_tracks(&mut self, songs: Vec<&'a Song>) -> Result<(), Error> { + pub fn set_tracks(&mut self, songs: Vec) -> Result<(), Error> { self.tracks = songs; Ok(()) } - pub fn add_track(&mut self, song: &'a Song) -> Result<(), Error> { + pub fn add_track(&mut self, song: Song) -> Result<(), Error> { self.tracks.push(song); Ok(()) } @@ -79,14 +79,7 @@ impl<'a> Playlist<'a> { |track| MediaSegment { uri: track.location.to_string().into(), duration: track.duration.as_millis() as f32, - title: Some( - track - .tags - .get_key_value(&Tag::Title) - .unwrap() - .1 - .into(), - ), + title: Some(track.tags.get_key_value(&Tag::Title).unwrap().1.into()), ..Default::default() } }) @@ -125,8 +118,8 @@ impl MusicCollection for Playlist<'_> { None => None, } } - fn tracks(&self) -> Vec<&Song> { - self.tracks.clone() + fn tracks(&self) -> Vec { + self.tracks } } impl Default for Playlist<'_> { @@ -148,7 +141,7 @@ fn list_to_m3u8() { )); let mut a = Playlist::new(); let c = lib.to_songs(); - let mut b = c.iter().map( |song| song ).collect::>(); + let mut b = c.iter().map(|song| song).collect::>(); a.tracks.append(&mut b); a.to_m3u8() }