Skip to content

Commit

Permalink
Merge pull request #10 from B0SEmc/dir-per-anime
Browse files Browse the repository at this point in the history
Make a folder per anime
  • Loading branch information
B0SEmc authored Jun 21, 2024
2 parents aa593aa + 0627fc9 commit db994b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/anime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Animes {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Anime {
name: String,
pub name: String,
pub lang: String,
season: i8,
pub episodes: Vec<String>,
Expand Down
19 changes: 14 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ use data::get_file;
use directories::ProjectDirs;
use inquire::*;
use spinners::{Spinner, Spinners};
use std::path::PathBuf;
use threadpool::ThreadPool;

mod anime;
mod data;

fn download(episodes: Vec<String>) {
fn download(episodes: Vec<String>, name: &str) {
match PathBuf::from(name).exists() {
true => (),
false => std::fs::create_dir(name).unwrap(),
}
std::env::set_current_dir(name).unwrap();
let pool = ThreadPool::new(12);

for chunk in episodes.chunks(12) {
Expand All @@ -17,10 +23,13 @@ fn download(episodes: Vec<String>) {
pool.execute(move || {
let output = std::process::Command::new("yt-dlp")
.arg(&episode)
.output()
.status()
.expect("Failed to execute command");
println!("Downloaded: {}", &episode);
println!("{}", String::from_utf8_lossy(&output.stdout));
if output.success() {
println!("Téléchargement de {} terminé", episode);
} else {
println!("Échec du téléchargement de {}", episode);
}
});
}
}
Expand Down Expand Up @@ -91,7 +100,7 @@ fn main() {
let ans4 = Select::new("Voulez-vous télécharger ou regarder l'anime ?", options).prompt();

if ans4.unwrap() == "Télécharger" {
download(ans3.episodes);
download(ans3.episodes, &ans3.name);
} else {
let mut episode_numbers = vec![];
for i in 1..=ans3.episodes.len() {
Expand Down

0 comments on commit db994b4

Please sign in to comment.