song updates
This commit is contained in:
@@ -4,26 +4,33 @@ use crate::{config::ConfigWrapper, downloader::Downloader, manifest::{Manifest,
|
||||
|
||||
pub async fn add(cfg: &ConfigWrapper, manifest: &mut Manifest, downloader: &mut Downloader, url: &Option<String>, name: &Option<String>, genre: &Option<String>) -> anyhow::Result<()> {
|
||||
|
||||
let genres = manifest.genres.keys().map(|f| f.clone()).collect::<Vec<String>>();
|
||||
log::debug!("Genre: {genre:?}");
|
||||
log::debug!("url: {url:?}");
|
||||
log::debug!("name: {name:?}");
|
||||
|
||||
let genre = genre.clone().unwrap_or(
|
||||
crate::prompt::prompt_with_list_or_str("Enter song genre", &genres)
|
||||
);
|
||||
let mut genres = manifest.genres.keys().map(|f| f.clone()).collect::<Vec<String>>();
|
||||
|
||||
log::debug!("Genre: {genre}");
|
||||
genres.sort();
|
||||
|
||||
let url = url.clone().unwrap_or(
|
||||
let genre = genre.clone().unwrap_or_else( || {
|
||||
let g = crate::prompt::prompt_with_list_or_str("Enter song genre", &genres);
|
||||
log::info!("Genre: {g}");
|
||||
g
|
||||
});
|
||||
|
||||
|
||||
let url = url.clone().unwrap_or_else( ||
|
||||
crate::prompt::simple_prompt("Enter song youtube url, make sure its not a playlist, (yt only for now)")
|
||||
);
|
||||
|
||||
let name = name.clone().unwrap_or(
|
||||
let name = name.clone().unwrap_or_else( ||
|
||||
crate::prompt::simple_prompt("Enter song name with like this: {Author} - {Song name}")
|
||||
);
|
||||
|
||||
manifest.add_song(genre.clone(), name.clone(), url.clone())?;
|
||||
manifest.save()?;
|
||||
|
||||
let should_download = crate::prompt::prompt_bool("Download song now?", Some(true));
|
||||
let should_download = crate::prompt::prompt_bool("Download song now?", Some(false));
|
||||
|
||||
if should_download {
|
||||
let song = &ManifestSong {
|
||||
@@ -32,6 +39,7 @@ pub async fn add(cfg: &ConfigWrapper, manifest: &mut Manifest, downloader: &mut
|
||||
};
|
||||
|
||||
downloader.download_song(cfg, song, &genre, &manifest.format()?).await?;
|
||||
downloader.wait_for_procs(0).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -31,8 +31,11 @@ pub enum CliCommand {
|
||||
#[default]
|
||||
Download,
|
||||
Add {
|
||||
#[arg(long, short)]
|
||||
url: Option<String>,
|
||||
#[arg(long, short)]
|
||||
name: Option<String>,
|
||||
#[arg(long, short)]
|
||||
genre: Option<String>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ impl Downloader {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn wait_for_procs(&mut self, until: usize) -> anyhow::Result<()> {
|
||||
pub async fn wait_for_procs(&mut self, until: usize) -> anyhow::Result<()> {
|
||||
// NOTE: This looks really fucked because i dont want to deadlock the processes so i lock PROCESSES for as little as possible
|
||||
// NOTE: So its also kinda really slow
|
||||
loop {
|
||||
|
||||
@@ -50,6 +50,11 @@ impl Manifest {
|
||||
}
|
||||
|
||||
pub fn add_song(&mut self, genre: String, name: String, url: String) -> anyhow::Result<()> {
|
||||
|
||||
if !self.genres.contains_key(&genre) {
|
||||
self.genres.insert(genre.clone(), Vec::new());
|
||||
}
|
||||
|
||||
let Some(genre_ref) = self.genres.get_mut(&genre) else {
|
||||
log::error!("Invalid genre '{}'", genre);
|
||||
bail!("Invalid genre")
|
||||
|
||||
Reference in New Issue
Block a user