mirror of
https://github.com/Dangoware/dmp-core.git
synced 2025-04-20 01:22:53 -05:00
addded small changes
This commit is contained in:
parent
0a68a12546
commit
4a7a6096d6
3 changed files with 41 additions and 28 deletions
|
@ -92,6 +92,7 @@ impl ConfigLibraries {
|
||||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
|
pub backup_folder: Option<PathBuf>,
|
||||||
pub libraries: ConfigLibraries,
|
pub libraries: ConfigLibraries,
|
||||||
pub volume: f32,
|
pub volume: f32,
|
||||||
}
|
}
|
||||||
|
@ -144,7 +145,6 @@ pub enum ConfigError {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn config_test() {
|
fn config_test() {
|
||||||
let lib_a = ConfigLibrary::new(PathBuf::from("test-config/library1"), String::from("library1"), None);
|
let lib_a = ConfigLibrary::new(PathBuf::from("test-config/library1"), String::from("library1"), None);
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::config::config::Config;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::ops::ControlFlow::{Break, Continue};
|
use std::ops::ControlFlow::{Break, Continue};
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
use file_format::{FileFormat, Kind};
|
use file_format::{FileFormat, Kind};
|
||||||
|
@ -273,7 +274,7 @@ impl Song {
|
||||||
|
|
||||||
/// creates a `Vec<Song>` from a cue file
|
/// creates a `Vec<Song>` from a cue file
|
||||||
|
|
||||||
pub fn from_cue(cuesheet: &Path) -> Result<(Vec<(Self, &PathBuf)>), Box<dyn Error>> {
|
pub fn from_cue(cuesheet: &Path) -> Result<(Vec<(Self, PathBuf)>), Box<dyn Error>> {
|
||||||
let mut tracks = Vec::new();
|
let mut tracks = Vec::new();
|
||||||
|
|
||||||
let cue_data = parse_from_file(&cuesheet.to_string_lossy(), false).unwrap();
|
let cue_data = parse_from_file(&cuesheet.to_string_lossy(), false).unwrap();
|
||||||
|
@ -286,6 +287,7 @@ impl Song {
|
||||||
for file in cue_data.files.iter() {
|
for file in cue_data.files.iter() {
|
||||||
let audio_location = &parent_dir.join(file.file.clone());
|
let audio_location = &parent_dir.join(file.file.clone());
|
||||||
|
|
||||||
|
|
||||||
if !audio_location.exists() {
|
if !audio_location.exists() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -389,7 +391,7 @@ impl Song {
|
||||||
tags,
|
tags,
|
||||||
album_art,
|
album_art,
|
||||||
};
|
};
|
||||||
tracks.push((new_song, audio_location));
|
tracks.push((new_song, audio_location.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok((tracks))
|
Ok((tracks))
|
||||||
|
|
|
@ -5,6 +5,8 @@ use chrono::Duration;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
// use walkdir::Error;
|
// use walkdir::Error;
|
||||||
|
|
||||||
|
use crate::music_controller::controller::Controller;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
library::{AlbumArt, Song, Tag},
|
library::{AlbumArt, Song, Tag},
|
||||||
music_collection::MusicCollection, db_reader::{
|
music_collection::MusicCollection, db_reader::{
|
||||||
|
@ -15,12 +17,17 @@ use super::{
|
||||||
|
|
||||||
use m3u8_rs::{MediaPlaylist, MediaPlaylistType, MediaSegment, Playlist as List2, MasterPlaylist};
|
use m3u8_rs::{MediaPlaylist, MediaPlaylistType, MediaSegment, Playlist as List2, MasterPlaylist};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum SortOrder {
|
||||||
|
Manual,
|
||||||
|
Tag(Tag)
|
||||||
|
}
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Playlist<'a> {
|
pub struct Playlist<'a> {
|
||||||
title: String,
|
title: String,
|
||||||
cover: Option<&'a AlbumArt>,
|
cover: Option<&'a AlbumArt>,
|
||||||
tracks: Vec<Uuid>,
|
tracks: Vec<Uuid>,
|
||||||
|
sort_order: SortOrder,
|
||||||
play_count: i32,
|
play_count: i32,
|
||||||
play_time: Duration,
|
play_time: Duration,
|
||||||
}
|
}
|
||||||
|
@ -35,10 +42,10 @@ impl<'a> Playlist<'a> {
|
||||||
self.play_time
|
self.play_time
|
||||||
}
|
}
|
||||||
pub fn set_tracks(&mut self, tracks: Vec<Uuid>) {
|
pub fn set_tracks(&mut self, tracks: Vec<Uuid>) {
|
||||||
self.tracks = songs;
|
self.tracks = tracks;
|
||||||
}
|
}
|
||||||
pub fn add_track(&mut self, track: Uuid) -> Result<(), Error> {
|
pub fn add_track(&mut self, track: Uuid) -> Result<(), Error> {
|
||||||
self.tracks.push(song);
|
self.tracks.push(track);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn remove_track(&mut self, index: i32) -> Result<(), Error> {
|
pub fn remove_track(&mut self, index: i32) -> Result<(), Error> {
|
||||||
|
@ -67,17 +74,19 @@ impl<'a> Playlist<'a> {
|
||||||
});
|
});
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
pub fn to_m3u8(&mut self) {
|
pub fn to_m3u8(&mut self, tracks: Vec<Song>) {
|
||||||
let seg = &self
|
let seg = tracks
|
||||||
.tracks
|
|
||||||
.iter()
|
.iter()
|
||||||
.map({
|
.map({
|
||||||
|track| MediaSegment {
|
|track| {
|
||||||
|
|
||||||
|
MediaSegment {
|
||||||
uri: track.location.to_string().into(),
|
uri: track.location.to_string().into(),
|
||||||
duration: track.duration.as_millis() as f32,
|
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()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<MediaSegment>>();
|
.collect::<Vec<MediaSegment>>();
|
||||||
|
|
||||||
|
@ -124,8 +133,6 @@ impl<'a> Playlist<'a> {
|
||||||
|
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
impl MusicCollection for Playlist<'_> {
|
|
||||||
fn title(&self) -> &String {
|
fn title(&self) -> &String {
|
||||||
&self.title
|
&self.title
|
||||||
}
|
}
|
||||||
|
@ -135,30 +142,34 @@ impl MusicCollection for Playlist<'_> {
|
||||||
None => None,
|
None => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn tracks(&self) -> Vec<Song> {
|
fn tracks(&self) -> Vec<Uuid> {
|
||||||
self.tracks.to_owned()
|
self.tracks.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Default for Playlist<'_> {
|
impl Default for Playlist<'_> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Playlist {
|
Playlist {
|
||||||
title: String::default(),
|
title: String::default(),
|
||||||
cover: None,
|
cover: None,
|
||||||
tracks: Vec::default(),
|
tracks: Vec::default(),
|
||||||
|
sort_order: SortOrder::Manual,
|
||||||
play_count: 0,
|
play_count: 0,
|
||||||
play_time: Duration::zero(),
|
play_time: Duration::zero(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
// #[test]
|
||||||
fn list_to_m3u8() {
|
// fn list_to_m3u8() {
|
||||||
let lib = ITunesLibrary::from_file(Path::new(
|
// let lib = ITunesLibrary::from_file(Path::new(
|
||||||
"F:\\Music\\Mp3\\Music Main\\iTunes Music Library.xml",
|
// "F:\\Music\\Mp3\\Music Main\\iTunes Music Library.xml",
|
||||||
));
|
// ));
|
||||||
let mut a = Playlist::new();
|
// let mut a = Playlist::new();
|
||||||
let c = lib.to_songs();
|
// let c = lib.to_songs();
|
||||||
let mut b = c.iter().map(|song| song.to_owned()).collect::<Vec<Song>>();
|
// let mut b = c.iter().map(|song| song.to_owned()).collect::<Vec<Song>>();
|
||||||
a.tracks.append(&mut b);
|
// a.tracks.append(&mut b);
|
||||||
a.to_m3u8()
|
// a.to_m3u8()
|
||||||
}
|
// }
|
||||||
|
|
Loading…
Reference in a new issue