mirror of
https://github.com/Dangoware/dmp-core.git
synced 2025-04-20 06:12:53 -05:00
changed music_db.rs to library.rs
This commit is contained in:
parent
7a93974f5b
commit
15b4984054
7 changed files with 57 additions and 35 deletions
|
@ -1,7 +1,8 @@
|
||||||
pub mod music_storage {
|
pub mod music_storage {
|
||||||
pub mod music_db;
|
pub mod library;
|
||||||
pub mod playlist;
|
pub mod playlist;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
pub mod music_collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod music_controller {
|
pub mod music_controller {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::path::PathBuf;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
use crate::music_controller::config::Config;
|
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 struct MusicController {
|
||||||
pub config: Arc<RwLock<Config>>,
|
pub config: Arc<RwLock<Config>>,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Crate things
|
// Crate things
|
||||||
//use crate::music_controller::config::Config;
|
//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 crossbeam_channel::bounded;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
@ -180,7 +180,6 @@ impl Player {
|
||||||
gst::MessageView::Eos(_) => {}
|
gst::MessageView::Eos(_) => {}
|
||||||
gst::MessageView::StreamStart(_) => println!("Stream start"),
|
gst::MessageView::StreamStart(_) => println!("Stream start"),
|
||||||
gst::MessageView::Error(e) => {
|
gst::MessageView::Error(e) => {
|
||||||
println!("ERROR: {}", e.error());
|
|
||||||
playbin_bus_ctrl
|
playbin_bus_ctrl
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -193,14 +192,6 @@ impl Player {
|
||||||
.set_state(gst::State::Playing)
|
.set_state(gst::State::Playing)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
},
|
},
|
||||||
gst::MessageView::Tag(tag) => {
|
|
||||||
if let Some(title) = tag.tags().get::<gst::tags::Title>() {
|
|
||||||
println!(" Title: {}", title.get());
|
|
||||||
}
|
|
||||||
if let Some(album) = tag.tags().get::<gst::tags::Album>() {
|
|
||||||
println!(" Album: {}", album.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gst::MessageView::Buffering(buffering) => {
|
gst::MessageView::Buffering(buffering) => {
|
||||||
let percent = buffering.percent();
|
let percent = buffering.percent();
|
||||||
if percent < 100 {
|
if percent < 100 {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use super::music_collection::MusicCollection;
|
||||||
// Crate things
|
// Crate things
|
||||||
use super::utils::{find_images, normalize, read_library, write_library};
|
use super::utils::{find_images, normalize, read_library, write_library};
|
||||||
use crate::music_controller::config::Config;
|
use crate::music_controller::config::Config;
|
||||||
|
@ -269,33 +270,16 @@ pub struct Album<'a> {
|
||||||
|
|
||||||
#[allow(clippy::len_without_is_empty)]
|
#[allow(clippy::len_without_is_empty)]
|
||||||
impl Album<'_> {
|
impl Album<'_> {
|
||||||
/// Returns the album title
|
|
||||||
pub fn title(&self) -> &String {
|
|
||||||
self.title
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the Album Artist, if they exist
|
/// Returns the Album Artist, if they exist
|
||||||
pub fn artist(&self) -> Option<&String> {
|
pub fn artist(&self) -> Option<&String> {
|
||||||
self.artist
|
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<usize, Vec<&Song>> {
|
pub fn discs(&self) -> &BTreeMap<usize, Vec<&Song>> {
|
||||||
&self.discs
|
&self.discs
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the specified track at `index` from the album, returning
|
/// Returns the specified track at `index` from the album, returning
|
||||||
/// an error if the track index is out of range
|
/// an error if the track index is out of range
|
||||||
pub fn track(&self, disc: usize, index: usize) -> Option<&Song> {
|
pub fn track(&self, disc: usize, index: usize) -> Option<&Song> {
|
||||||
|
@ -311,6 +295,23 @@ impl Album<'_> {
|
||||||
total
|
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"];
|
const BLOCKED_EXTENSIONS: [&str; 4] = ["vob", "log", "txt", "sf2"];
|
||||||
|
|
||||||
|
|
8
src/music_storage/music_collection.rs
Normal file
8
src/music_storage/music_collection.rs
Normal file
|
@ -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>;
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,27 @@
|
||||||
use crate::music_controller::config::Config;
|
use walkdir::Error;
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
pub fn playlist_add(_config: &Config, _playlist_name: &str, _song_paths: &[&Path]) {
|
use crate::music_controller::config::Config;
|
||||||
unimplemented!()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use walkdir::WalkDir;
|
||||||
|
|
||||||
use snap;
|
use snap;
|
||||||
|
|
||||||
use super::music_db::{AlbumArt, Song, URI};
|
use super::library::{AlbumArt, Song, URI};
|
||||||
use unidecode::unidecode;
|
use unidecode::unidecode;
|
||||||
|
|
||||||
pub(super) fn normalize(input_string: &str) -> String {
|
pub(super) fn normalize(input_string: &str) -> String {
|
||||||
|
|
Loading…
Reference in a new issue