Major update
too lazy to describe
This commit is contained in:
@@ -30,11 +30,12 @@ impl IconCacheDl {
|
||||
pub fn download(&mut self, sid: uuid::Uuid, song: Song) -> crate::Result<()> {
|
||||
match song.icon_type().clone() {
|
||||
IconType::FromSource => {
|
||||
let tooling = xmpd_settings::Settings::get()?.tooling.clone();
|
||||
let settings = xmpd_settings::Settings::get()?.clone();
|
||||
let tooling = settings.tooling.clone();
|
||||
match song.source_type() {
|
||||
SourceType::Youtube => {
|
||||
self.jobs.insert(sid.clone(), DlStatus::Downloading);
|
||||
let mut path = xmpd_cliargs::CLIARGS.cache_path();
|
||||
let mut path = settings.cache_settings.cache_path.clone();
|
||||
path.push("icons");
|
||||
path.push(sid.to_string());
|
||||
|
||||
@@ -91,7 +92,7 @@ impl IconCacheDl {
|
||||
anyhow::bail!("Url without extension, cant continue");
|
||||
};
|
||||
let ext = ext.to_string_lossy().to_string();
|
||||
let mut path = xmpd_cliargs::CLIARGS.cache_path();
|
||||
let mut path = xmpd_settings::Settings::get()?.clone().cache_settings.cache_path;
|
||||
path.push("icons");
|
||||
path.push(sid.to_string());
|
||||
path.set_extension(ext);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::{collections::HashMap, ffi::OsStr, process::{Command, Stdio}, sync::{Arc, Mutex, MutexGuard}};
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
use xmpd_manifest::song::{Song, SourceType};
|
||||
|
||||
|
||||
@@ -14,6 +15,12 @@ pub enum SongStatus {
|
||||
Done
|
||||
}
|
||||
|
||||
#[cfg(target_family = "windows")]
|
||||
const PATH_SEP: char = ';';
|
||||
#[cfg(target_family = "unix")]
|
||||
const PATH_SEP: char = ':';
|
||||
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct SongCacheDl {
|
||||
pub jobs: HashMap<uuid::Uuid, SongStatus>,
|
||||
@@ -30,12 +37,15 @@ impl SongCacheDl {
|
||||
pub fn is_job_list_full(&self) -> bool {
|
||||
self.current_jobs >= 5
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn download(&mut self, sid: uuid::Uuid, song: Song) -> crate::Result<()> {
|
||||
self.current_jobs += 1;
|
||||
let song_format = xmpd_settings::Settings::get().unwrap().tooling.song_format.clone();
|
||||
let tooling = xmpd_settings::Settings::get()?.tooling.clone();
|
||||
let mut song_cache_d = xmpd_cliargs::CLIARGS.cache_path();
|
||||
let settings = xmpd_settings::Settings::get()?.clone();
|
||||
let tooling = settings.tooling.clone();
|
||||
let mut song_cache_d = settings.cache_settings.cache_path.clone();
|
||||
song_cache_d.push("songs");
|
||||
match song.source_type() {
|
||||
SourceType::Youtube |
|
||||
@@ -49,7 +59,7 @@ impl SongCacheDl {
|
||||
dl_cmd.args(["-x", "--audio-format", &song_format]);
|
||||
dl_cmd.arg("-o");
|
||||
dl_cmd.arg(&song_p);
|
||||
|
||||
|
||||
if xmpd_cliargs::CLIARGS.debug {
|
||||
dl_cmd.stdout(Stdio::piped());
|
||||
dl_cmd.stderr(Stdio::piped());
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::{collections::HashMap, path::PathBuf, str::FromStr, sync::{mpsc::{self, Receiver, Sender}, Arc, Mutex, MutexGuard}, time::Duration};
|
||||
use anyhow::anyhow;
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
use downloader::song::SongStatus;
|
||||
use xmpd_manifest::song::Song;
|
||||
|
||||
@@ -41,18 +43,40 @@ impl Cache {
|
||||
Err(e) => Err(anyhow::anyhow!(format!("{e:?}"))),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_if_tool_exists(&self, tool_path: &Utf8Path) -> crate::Result<()> {
|
||||
if std::fs::metadata(tool_path).is_ok() {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(path) = std::env::var("PATH") {
|
||||
for p in path.split(":") {
|
||||
let p_str = Utf8PathBuf::from(p).join(tool_path);
|
||||
if std::fs::metadata(p_str).is_ok() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
anyhow::bail!("Tool {} was not found", tool_path)
|
||||
}
|
||||
pub fn init(&mut self) -> Result<Receiver<Message>> {
|
||||
// Check for missing tooling
|
||||
|
||||
let tooling = xmpd_settings::Settings::get()?.tooling.clone();
|
||||
self.check_if_tool_exists(&tooling.ytdlp_path)?;
|
||||
self.check_if_tool_exists(&tooling.spotdl_path)?;
|
||||
self.check_if_tool_exists(&tooling.ffmpeg_path)?;
|
||||
|
||||
|
||||
|
||||
let (internal_tx, cache_rx) = mpsc::channel::<Message>();
|
||||
// let (internal_rx, cache_tx) = mpsc::channel::<Message>();
|
||||
start_cache_mv_thread(internal_tx);
|
||||
self.cache_dir = xmpd_cliargs::CLIARGS.cache_path();
|
||||
|
||||
self.cache_dir = xmpd_settings::Settings::get()?.cache_settings.cache_path.clone();
|
||||
std::fs::create_dir_all(&self.cache_dir)?;
|
||||
{ // Get cached songs
|
||||
let mut song_cache_dir = self.cache_dir.clone();
|
||||
std::fs::create_dir_all(&song_cache_dir)?;
|
||||
song_cache_dir.push("songs");
|
||||
for file in song_cache_dir.read_dir_utf8()? {
|
||||
std::fs::create_dir_all(&song_cache_dir)?;
|
||||
for file in song_cache_dir.read_dir_utf8().map_err(|e| anyhow!("failed to read cache dir: {e}"))? {
|
||||
if let Ok(file) = file {
|
||||
if !file.file_type()?.is_file() {
|
||||
log::warn!("Non song file in: {}", file.path());
|
||||
@@ -126,7 +150,7 @@ fn start_cache_mv_thread(tx: Sender<Message>) {
|
||||
for (sid, status) in &dlc.jobs {
|
||||
if *status == SongStatus::Done {
|
||||
let mut cache = he!(tx, CACHE.lock());
|
||||
let mut song_p = xmpd_cliargs::CLIARGS.cache_path().clone();
|
||||
let mut song_p = he!(tx, xmpd_settings::Settings::get()).cache_settings.cache_path.clone();
|
||||
song_p.push("songs");
|
||||
song_p.push(sid.clone().to_string());
|
||||
let song_p = song_p.with_extension(&song_format);
|
||||
|
||||
Reference in New Issue
Block a user