diff --git a/src/lib.rs b/src/lib.rs index d98209c..31538fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,8 @@ pub mod music_storage { - pub mod music_db; + pub mod library; pub mod playlist; mod utils; + pub mod music_collection; } pub mod music_controller { diff --git a/src/music_controller/controller.rs b/src/music_controller/controller.rs index 333db0b..6d0acb4 100644 --- a/src/music_controller/controller.rs +++ b/src/music_controller/controller.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use std::sync::{Arc, RwLock}; use crate::music_controller::config::Config; -use crate::music_storage::music_db::{MusicLibrary, Song, Tag}; +use crate::music_storage::library::{MusicLibrary, Song, Tag}; pub struct MusicController { pub config: Arc>, diff --git a/src/music_player.rs b/src/music_player.rs index 0c9b2d6..ecafff6 100644 --- a/src/music_player.rs +++ b/src/music_player.rs @@ -1,6 +1,6 @@ // Crate things //use crate::music_controller::config::Config; -use crate::music_storage::music_db::{Tag, URI}; +use crate::music_storage::library::{Tag, URI}; use crossbeam_channel::bounded; use std::error::Error; use std::sync::{Arc, RwLock}; @@ -180,7 +180,6 @@ impl Player { gst::MessageView::Eos(_) => {} gst::MessageView::StreamStart(_) => println!("Stream start"), gst::MessageView::Error(e) => { - println!("ERROR: {}", e.error()); playbin_bus_ctrl .write() .unwrap() @@ -193,14 +192,6 @@ impl Player { .set_state(gst::State::Playing) .unwrap(); }, - gst::MessageView::Tag(tag) => { - if let Some(title) = tag.tags().get::() { - println!(" Title: {}", title.get()); - } - if let Some(album) = tag.tags().get::() { - println!(" Album: {}", album.get()); - } - } gst::MessageView::Buffering(buffering) => { let percent = buffering.percent(); if percent < 100 { diff --git a/src/music_storage/library.rs b/src/music_storage/library.rs index 41d2e22..4fdcabd 100644 --- a/src/music_storage/library.rs +++ b/src/music_storage/library.rs @@ -1,3 +1,4 @@ +use super::music_collection::MusicCollection; // Crate things use super::utils::{find_images, normalize, read_library, write_library}; use crate::music_controller::config::Config; @@ -269,33 +270,16 @@ pub struct Album<'a> { #[allow(clippy::len_without_is_empty)] impl Album<'_> { - /// Returns the album title - pub fn title(&self) -> &String { - self.title - } - /// Returns the Album Artist, if they exist pub fn artist(&self) -> Option<&String> { self.artist } - /// Returns the album cover as an AlbumArt struct, if it exists - pub fn cover(&self) -> Option<&AlbumArt> { - self.cover - } - - pub fn tracks(&self) -> Vec<&Song> { - let mut songs = Vec::new(); - for disc in &self.discs { - songs.append(&mut disc.1.clone()) - } - songs - } + pub fn discs(&self) -> &BTreeMap> { &self.discs } - /// Returns the specified track at `index` from the album, returning /// an error if the track index is out of range pub fn track(&self, disc: usize, index: usize) -> Option<&Song> { @@ -311,6 +295,23 @@ 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"]; diff --git a/src/music_storage/music_collection.rs b/src/music_storage/music_collection.rs new file mode 100644 index 0000000..8abcd71 --- /dev/null +++ b/src/music_storage/music_collection.rs @@ -0,0 +1,8 @@ +use crate::music_storage::library::{ AlbumArt, Song }; + +pub trait MusicCollection { + fn title(&self) -> &String; + fn cover(&self) -> Option<&AlbumArt>; + fn tracks(&self) -> Vec<&Song>; +} + diff --git a/src/music_storage/playlist.rs b/src/music_storage/playlist.rs index 4f8892d..2ad4742 100644 --- a/src/music_storage/playlist.rs +++ b/src/music_storage/playlist.rs @@ -1,6 +1,27 @@ -use crate::music_controller::config::Config; -use std::path::Path; +use walkdir::Error; -pub fn playlist_add(_config: &Config, _playlist_name: &str, _song_paths: &[&Path]) { - unimplemented!() +use crate::music_controller::config::Config; +use std::{path::Path, default, thread::AccessError}; + +use super::{library::{AlbumArt, Song}, music_collection::MusicCollection}; + +#[derive(Debug, Default)] +pub struct Playlist<'a> { + title: String, + cover: Option<&'a AlbumArt>, + tracks: Vec<&'a Song>, +} +impl MusicCollection for Playlist<'_> { + fn title(&self) -> &String { + &self.title + } + fn cover(&self) -> Option<&AlbumArt> { + match self.cover { + Some(e) => Some(e), + None => None, + } + } + fn tracks(&self) -> Vec<&Song> { + self.tracks.clone() + } } diff --git a/src/music_storage/utils.rs b/src/music_storage/utils.rs index 03e9740..a25313a 100644 --- a/src/music_storage/utils.rs +++ b/src/music_storage/utils.rs @@ -6,7 +6,7 @@ use walkdir::WalkDir; use snap; -use super::music_db::{AlbumArt, Song, URI}; +use super::library::{AlbumArt, Song, URI}; use unidecode::unidecode; pub(super) fn normalize(input_string: &str) -> String {