mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02:53 -05:00
Removed unused imports, moved some tests to mod tests
This commit is contained in:
parent
c4c842e637
commit
9da9b00bef
10 changed files with 152 additions and 164 deletions
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
path::PathBuf,
|
||||
fs::{File, OpenOptions, self},
|
||||
io::{Error, Write, Read}, sync::{Arc, RwLock},
|
||||
io::{Error, Write, Read},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -9,8 +9,6 @@ use serde_json::to_string_pretty;
|
|||
use thiserror::Error;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::music_storage::library::{MusicLibrary, self};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ConfigLibrary {
|
||||
pub name: String,
|
||||
|
@ -166,47 +164,54 @@ pub enum ConfigError {
|
|||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_test() {
|
||||
let lib_a = ConfigLibrary::new(PathBuf::from("test-config/library1"), String::from("library1"), None);
|
||||
let lib_b = ConfigLibrary::new(PathBuf::from("test-config/library2"), String::from("library2"), None);
|
||||
let lib_c = ConfigLibrary::new(PathBuf::from("test-config/library3"), String::from("library3"), None);
|
||||
let config = Config {
|
||||
path: PathBuf::from("test-config/config_test.json"),
|
||||
libraries: ConfigLibraries {
|
||||
libraries: vec![
|
||||
lib_a.clone(),
|
||||
lib_b.clone(),
|
||||
lib_c.clone(),
|
||||
],
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{path::PathBuf, sync::{Arc, RwLock}};
|
||||
use crate::music_storage::library::MusicLibrary;
|
||||
use super::{Config, ConfigLibraries, ConfigLibrary};
|
||||
|
||||
#[test]
|
||||
fn config_test() {
|
||||
let lib_a = ConfigLibrary::new(PathBuf::from("test-config/library1"), String::from("library1"), None);
|
||||
let lib_b = ConfigLibrary::new(PathBuf::from("test-config/library2"), String::from("library2"), None);
|
||||
let lib_c = ConfigLibrary::new(PathBuf::from("test-config/library3"), String::from("library3"), None);
|
||||
let config = Config {
|
||||
path: PathBuf::from("test-config/config_test.json"),
|
||||
libraries: ConfigLibraries {
|
||||
libraries: vec![
|
||||
lib_a.clone(),
|
||||
lib_b.clone(),
|
||||
lib_c.clone(),
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
config.write_file();
|
||||
let arc = Arc::new(RwLock::from(config));
|
||||
MusicLibrary::init(arc.clone(), lib_a.uuid).unwrap();
|
||||
MusicLibrary::init(arc.clone(), lib_b.uuid).unwrap();
|
||||
MusicLibrary::init(arc.clone(), lib_c.uuid).unwrap();
|
||||
};
|
||||
config.write_file();
|
||||
let arc = Arc::new(RwLock::from(config));
|
||||
MusicLibrary::init(arc.clone(), lib_a.uuid).unwrap();
|
||||
MusicLibrary::init(arc.clone(), lib_b.uuid).unwrap();
|
||||
MusicLibrary::init(arc.clone(), lib_c.uuid).unwrap();
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test2() {
|
||||
let config = Config::read_file(PathBuf::from("test-config/config_test.json")).unwrap();
|
||||
let uuid = config.libraries.get_default().unwrap().uuid;
|
||||
let mut lib = MusicLibrary::init(Arc::new(RwLock::from(config.clone())), uuid).unwrap();
|
||||
lib.scan_folder("test-config/music/").unwrap();
|
||||
lib.save(config.clone()).unwrap();
|
||||
dbg!(&lib);
|
||||
dbg!(&config);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test3() {
|
||||
let config = Config::read_file(PathBuf::from("test-config/config_test.json")).unwrap();
|
||||
let uuid = config.libraries.get_default().unwrap().uuid;
|
||||
let lib = MusicLibrary::init(Arc::new(RwLock::from(config.clone())), uuid).unwrap();
|
||||
|
||||
dbg!(lib);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test2() {
|
||||
let config = Config::read_file(PathBuf::from("test-config/config_test.json")).unwrap();
|
||||
let uuid = config.libraries.get_default().unwrap().uuid;
|
||||
let mut lib = MusicLibrary::init(Arc::new(RwLock::from(config.clone())), uuid).unwrap();
|
||||
lib.scan_folder("test-config/music/").unwrap();
|
||||
lib.save(config.clone()).unwrap();
|
||||
dbg!(&lib);
|
||||
dbg!(&config);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test3() {
|
||||
let config = Config::read_file(PathBuf::from("test-config/config_test.json")).unwrap();
|
||||
let uuid = config.libraries.get_default().unwrap().uuid;
|
||||
let lib = MusicLibrary::init(Arc::new(RwLock::from(config.clone())), uuid).unwrap();
|
||||
|
||||
dbg!(lib);
|
||||
}
|
|
@ -1,7 +1,3 @@
|
|||
use std::{marker::PhantomData, fs::File, path::PathBuf};
|
||||
|
||||
use font::Font;
|
||||
|
||||
pub enum Setting {
|
||||
String {
|
||||
name: String,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![allow(unused)]
|
||||
#[allow(dead_code)]
|
||||
|
||||
pub mod music_storage {
|
||||
pub mod library;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::{env, thread, time};
|
||||
|
||||
use super::controller::Controller;
|
||||
|
||||
|
||||
|
|
|
@ -2,33 +2,23 @@
|
|||
//! player. It manages queues, playback, library access, and
|
||||
//! other functions
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::Duration;
|
||||
use crossbeam_channel::{Sender, Receiver};
|
||||
// use std::sync::mpsc;
|
||||
use crossbeam_channel;
|
||||
use gstreamer::format::Default;
|
||||
use gstreamer::query::Uri;
|
||||
use std::thread::{self, sleep, spawn};
|
||||
use std::thread::spawn;
|
||||
|
||||
use std::error::Error;
|
||||
use crossbeam_channel::unbounded;
|
||||
use rayon::iter::Rev;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::config;
|
||||
use crate::music_storage::library::{Tag, URI};
|
||||
use crate::music_storage::playlist::Playlist;
|
||||
use crate::{
|
||||
music_player::Player,
|
||||
music_storage::library::{MusicLibrary, Song},
|
||||
config::config::Config,
|
||||
music_controller::queue::Queue,
|
||||
};
|
||||
|
||||
use super::queue::{QueueItem, QueueState};
|
||||
|
||||
pub struct Controller {
|
||||
// queues: Vec<Queue>,
|
||||
config: Arc<RwLock<Config>>,
|
||||
|
@ -266,7 +256,7 @@ impl Controller {
|
|||
}
|
||||
});
|
||||
self.queue_mail.push(out_thread_queue);
|
||||
Ok((self.queue_mail.len() - 1))
|
||||
Ok(self.queue_mail.len() - 1)
|
||||
}
|
||||
|
||||
fn q_play(&self, index: usize) -> Result<(), Box<dyn Error>> {
|
||||
|
@ -306,36 +296,43 @@ impl Controller {
|
|||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn play_test() {
|
||||
let mut a = match Controller::start("test-config/config_test.json".to_string()) {
|
||||
Ok(c) => c,
|
||||
Err(e) => panic!("{e}")
|
||||
};
|
||||
sleep(Duration::from_millis(500));
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{thread::sleep, time::Duration};
|
||||
|
||||
let i = a.q_new().unwrap();
|
||||
a.q_set_volume(i, 0.04);
|
||||
// a.new_queue();
|
||||
let songs = a.lib_get_songs();
|
||||
a.q_enqueue(i, songs[2].location.clone());
|
||||
// a.enqueue(1, songs[2].location.clone());
|
||||
a.q_play(i).unwrap();
|
||||
// a.play(1).unwrap();
|
||||
use super::Controller;
|
||||
|
||||
sleep(Duration::from_secs(10));
|
||||
a.q_pause(i);
|
||||
sleep(Duration::from_secs(10));
|
||||
a.q_play(i);
|
||||
sleep(Duration::from_secs(1000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_() {
|
||||
let a = match Controller::start("test-config/config_test.json".to_string()) {
|
||||
Ok(c) => c,
|
||||
Err(e) => panic!("{e}")
|
||||
};
|
||||
a.lib_scan_folder("F:/Music/Mp3".to_string());
|
||||
a.lib_save();
|
||||
#[test]
|
||||
fn play_test() {
|
||||
let mut a = match Controller::start("test-config/config_test.json".to_string()) {
|
||||
Ok(c) => c,
|
||||
Err(e) => panic!("{e}")
|
||||
};
|
||||
sleep(Duration::from_millis(500));
|
||||
|
||||
let i = a.q_new().unwrap();
|
||||
a.q_set_volume(i, 0.04);
|
||||
// a.new_queue();
|
||||
let songs = a.lib_get_songs();
|
||||
a.q_enqueue(i, songs[2].location.clone());
|
||||
// a.enqueue(1, songs[2].location.clone());
|
||||
a.q_play(i).unwrap();
|
||||
// a.play(1).unwrap();
|
||||
|
||||
sleep(Duration::from_secs(10));
|
||||
a.q_pause(i);
|
||||
sleep(Duration::from_secs(10));
|
||||
a.q_play(i);
|
||||
sleep(Duration::from_secs(1000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_() {
|
||||
let a = match Controller::start("test-config/config_test.json".to_string()) {
|
||||
Ok(c) => c,
|
||||
Err(e) => panic!("{e}")
|
||||
};
|
||||
a.lib_scan_folder("F:/Music/Mp3".to_string());
|
||||
a.lib_save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
use font::opentype::tables::font_variations::InstanceFlags;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{music_player::Player, music_storage::library::{Album, MusicLibrary, Song, URI}};
|
||||
use std::{error::Error, ops::Add, path::Path, sync::{Arc, RwLock}, thread::sleep, time::Duration};
|
||||
use crate::{
|
||||
music_player::Player,
|
||||
music_storage::library::{Album, MusicLibrary, URI}
|
||||
};
|
||||
use std::{
|
||||
error::Error,
|
||||
sync::{Arc, RwLock}
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum QueueState {
|
||||
|
@ -169,7 +173,7 @@ impl<'a> Queue<'a> {
|
|||
let empty = self.is_empty();
|
||||
|
||||
self.items.insert(
|
||||
(ind + if !empty && ind_ == None { 1 } else { 2 }),
|
||||
ind + if !empty && ind_ == None { 1 } else { 2 },
|
||||
QueueItem {
|
||||
item,
|
||||
state: if empty {
|
||||
|
@ -282,8 +286,6 @@ impl<'a> Queue<'a> {
|
|||
pub fn prev() {}
|
||||
|
||||
pub fn enqueue_item(&mut self, item: QueueItem, lib: Arc<RwLock<MusicLibrary>>) -> Result<(), Box<dyn Error>> {
|
||||
use QueueItemType::*;
|
||||
|
||||
if let Some(uri) = item.item.get_uri(lib) {
|
||||
self.player.enqueue_next(&uri)?;
|
||||
}else {
|
||||
|
@ -359,4 +361,4 @@ fn move_test() {
|
|||
q.move_to(3).inspect_err(|e| {dbg!(e);});
|
||||
dbg!(&q.items, &q.items.len());
|
||||
// q.dbg_items();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,15 +7,13 @@ use std::collections::{BTreeMap, HashMap};
|
|||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::Duration as StdDur;
|
||||
use std::vec::Vec;
|
||||
|
||||
use chrono::prelude::*;
|
||||
|
||||
use crate::config::config::{Config, ConfigLibrary};
|
||||
use crate::music_storage::db_reader::extern_library::ExternalLibrary;
|
||||
use crate::music_storage::library::{AlbumArt, MusicLibrary, Service, Song, Tag, URI, BannedType};
|
||||
use crate::music_storage::library::{AlbumArt, Service, Song, Tag, URI};
|
||||
use crate::music_storage::utils;
|
||||
|
||||
use urlencoding::decode;
|
||||
|
@ -331,18 +329,27 @@ impl ITunesSong {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn itunes_lib_test() {
|
||||
let mut config = Config::read_file(PathBuf::from("test-config/config_test.json")).unwrap();
|
||||
let config_lib = ConfigLibrary::new(PathBuf::from("test-config/library2"), String::from("library2"), None);
|
||||
config.libraries.libraries.push(config_lib.clone());
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{path::{Path, PathBuf}, sync::{Arc, RwLock}};
|
||||
|
||||
let songs = ITunesLibrary::from_file(Path::new("test-config\\iTunesLib.xml")).to_songs();
|
||||
use crate::{config::config::{Config, ConfigLibrary}, music_storage::{db_reader::extern_library::ExternalLibrary, library::MusicLibrary}};
|
||||
|
||||
let mut library = MusicLibrary::init(Arc::new(RwLock::from(config.clone())), config_lib.uuid).unwrap();
|
||||
use super::ITunesLibrary;
|
||||
|
||||
songs.iter().for_each(|song| library.add_song(song.to_owned()).unwrap());
|
||||
#[test]
|
||||
fn itunes_lib_test() {
|
||||
let mut config = Config::read_file(PathBuf::from("test-config/config_test.json")).unwrap();
|
||||
let config_lib = ConfigLibrary::new(PathBuf::from("test-config/library2"), String::from("library2"), None);
|
||||
config.libraries.libraries.push(config_lib.clone());
|
||||
|
||||
config.write_file().unwrap();
|
||||
library.save(config).unwrap();
|
||||
}
|
||||
let songs = ITunesLibrary::from_file(Path::new("test-config\\iTunesLib.xml")).to_songs();
|
||||
|
||||
let mut library = MusicLibrary::init(Arc::new(RwLock::from(config.clone())), config_lib.uuid).unwrap();
|
||||
|
||||
songs.iter().for_each(|song| library.add_song(song.to_owned()).unwrap());
|
||||
|
||||
config.write_file().unwrap();
|
||||
library.save(config).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,7 @@ use crate::config::config::Config;
|
|||
// Various std things
|
||||
use std::collections::BTreeMap;
|
||||
use std::error::Error;
|
||||
use std::io::BufWriter;
|
||||
use std::ops::ControlFlow::{Break, Continue};
|
||||
use std::ops::Deref;
|
||||
|
||||
// Files
|
||||
use file_format::{FileFormat, Kind};
|
||||
|
@ -15,11 +13,12 @@ use glib::filename_to_uri;
|
|||
use image::guess_format;
|
||||
use lofty::{AudioFile, ItemKey, ItemValue, ParseOptions, Probe, TagType, TaggedFileExt};
|
||||
use rcue::parser::parse_from_file;
|
||||
use tempfile::tempfile;
|
||||
use uuid::Uuid;
|
||||
use std::fs::{self, OpenOptions};
|
||||
use std::fs;
|
||||
use tempfile::TempDir;
|
||||
use std::path::{Path, PathBuf};
|
||||
use walkdir::WalkDir;
|
||||
use image::ImageFormat::*;
|
||||
|
||||
// Time
|
||||
use chrono::{serde::ts_milliseconds_option, DateTime, Utc};
|
||||
|
@ -163,11 +162,8 @@ pub struct Song {
|
|||
|
||||
#[test]
|
||||
fn get_art_test() {
|
||||
use urlencoding::decode;
|
||||
|
||||
let s = Song::from_file(Path::new("F:\\Music\\Mp3\\ななひら\\Colory Starry\\05 - Fly Away!.mp3")).unwrap();
|
||||
s.open_album_art(0).inspect_err(|e| println!("{e:?}"));
|
||||
|
||||
s.open_album_art(0).inspect_err(|e| println!("{e:?}")).unwrap();
|
||||
}
|
||||
|
||||
impl Song {
|
||||
|
@ -440,22 +436,24 @@ impl Song {
|
|||
use urlencoding::decode;
|
||||
|
||||
if index >= self.album_art.len() {
|
||||
return Err("index out of bounds?".into());
|
||||
return Err("Index out of bounds".into());
|
||||
}
|
||||
|
||||
let uri: String = match &self.album_art[index] {
|
||||
let uri = match &self.album_art[index] {
|
||||
AlbumArt::External(uri) => {
|
||||
decode(match uri.as_uri().strip_prefix("file:///") { Some(e) => e, None => return Err("Invalid path?".into()) })?.into_owned()
|
||||
PathBuf::from(decode(match uri.as_uri().strip_prefix("file:///") {
|
||||
Some(e) => e,
|
||||
None => return Err("Invalid path?".into())
|
||||
})?.to_owned().to_string())
|
||||
},
|
||||
AlbumArt::Embedded(_) => {
|
||||
|
||||
let normal_options = ParseOptions::new().parsing_mode(lofty::ParsingMode::Relaxed);
|
||||
let blank_tag = &lofty::Tag::new(TagType::Id3v2);
|
||||
let tagged_file: lofty::TaggedFile;
|
||||
|
||||
let uri = dbg!(urlencoding::decode(self.location.as_uri().strip_prefix("file:///").unwrap())?.into_owned());
|
||||
let uri = urlencoding::decode(self.location.as_uri().strip_prefix("file://").unwrap())?.into_owned();
|
||||
|
||||
let tag = match Probe::open(uri)?.options(normal_options).read() {
|
||||
let tag = match Probe::open(uri).unwrap().options(normal_options).read() {
|
||||
Ok(file) => {
|
||||
tagged_file = file;
|
||||
|
||||
|
@ -476,26 +474,22 @@ impl Song {
|
|||
let format = dbg!(guess_format(data)?);
|
||||
let img = image::load_from_memory(data)?;
|
||||
|
||||
let mut location = String::new();
|
||||
let i: u32 = 0;
|
||||
loop {
|
||||
use image::ImageFormat::*;
|
||||
//TODO: create a place for temporary images
|
||||
let fmt = match format {
|
||||
Jpeg => "jpeg",
|
||||
Png => "png",
|
||||
_ => todo!(),
|
||||
};
|
||||
|
||||
location = format!("./test-config/images/tempcover{i}.{fmt}.tmp");
|
||||
break;
|
||||
let tmp_dir = TempDir::new()?;
|
||||
let fmt = match format {
|
||||
Jpeg => "jpeg",
|
||||
Png => "png",
|
||||
_ => todo!(),
|
||||
};
|
||||
img.save_with_format(&location, format)?;
|
||||
|
||||
location.to_string()
|
||||
let file_path = tmp_dir.path().join(format!("{}.{fmt}", self.uuid));
|
||||
|
||||
open(&file_path).unwrap();
|
||||
img.save_with_format(&file_path, format).unwrap();
|
||||
|
||||
file_path
|
||||
},
|
||||
};
|
||||
open(uri)?;
|
||||
dbg!(open(uri)?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1137,4 +1131,4 @@ impl MusicLibrary {
|
|||
|
||||
Ok(albums)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,10 @@
|
|||
use std::{fs::File, path::{Path, PathBuf}, io::{Read, Error}};
|
||||
use std::{fs::File, io::{Read, Error}};
|
||||
|
||||
use bincode::config;
|
||||
use chrono::Duration;
|
||||
use uuid::Uuid;
|
||||
// use walkdir::Error;
|
||||
use super::library::{AlbumArt, Song, Tag};
|
||||
|
||||
use crate::music_controller::controller::Controller;
|
||||
|
||||
use super::{
|
||||
library::{AlbumArt, Song, Tag},
|
||||
music_collection::MusicCollection, db_reader::{
|
||||
itunes::reader::ITunesLibrary,
|
||||
extern_library::ExternalLibrary
|
||||
},
|
||||
};
|
||||
|
||||
use m3u8_rs::{MediaPlaylist, MediaPlaylistType, MediaSegment, Playlist as List2, MasterPlaylist};
|
||||
use m3u8_rs::{MediaPlaylist, MediaPlaylistType, MediaSegment, Playlist as List2};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SortOrder {
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
use std::any::Any;
|
||||
use std::fs::{File, self};
|
||||
use std::io::{BufReader, BufWriter};
|
||||
use std::os::windows::fs::MetadataExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::error::Error;
|
||||
|
||||
use walkdir::WalkDir;
|
||||
use file_format::{FileFormat, Kind};
|
||||
use snap;
|
||||
|
@ -12,6 +9,9 @@ use deunicode::deunicode_with_tofu;
|
|||
|
||||
use super::library::{AlbumArt, URI};
|
||||
|
||||
#[cfg(target_family = "windows")]
|
||||
use std::os::windows::fs::MetadataExt;
|
||||
|
||||
pub(super) fn normalize(input_string: &str) -> String {
|
||||
// Normalize the string to latin characters... this needs a lot of work
|
||||
let mut normalized = deunicode_with_tofu(input_string, " ");
|
||||
|
|
Loading…
Reference in a new issue