diff --git a/src/functions.rs b/src/functions.rs index a2d7248..6af49ca 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -6,7 +6,7 @@ use std::{collections::HashMap, fs, path::Path, process::exit}; use tmdb::{model::*, themoviedb::*}; use torrent_name_parser::Metadata; -use crate::structs::{Language, MovieEntry}; +use crate::structs::{get_long_lang, Language, MovieEntry}; // Get the version from Cargo.toml const VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -89,12 +89,22 @@ pub fn process_file( // Handle the case for subtitle files let mut is_subtitle = false; if ["srt", "ssa"].contains(&extension.as_str()) { - let lang_list = Language::generate_list(); - let lang_choice = Select::new("Choose the language for the subtitle file:", lang_list) - .prompt() - .expect("Invalid choice!"); - if lang_choice.short != "none".to_string() { - extension = format!("{}.{}", lang_choice.short, extension); + // Try to detect if there's already language info in the filename, else ask user to choose + let filename_parts: Vec<&str> = filename.rsplit(".").collect(); + if filename_parts.len() >= 3 && filename_parts[1].len() == 2 { + println!( + "Keeping language {} as detected in the subtitle file's extension...", + get_long_lang(filename_parts[1]) + ); + extension = format!("{}.{}", filename_parts[1], extension); + } else { + let lang_list = Language::generate_list(); + let lang_choice = Select::new("Choose the language for the subtitle file:", lang_list) + .prompt() + .expect("Invalid choice!"); + if lang_choice.short != "none".to_string() { + extension = format!("{}.{}", lang_choice.short, extension); + } } is_subtitle = true; } diff --git a/src/main.rs b/src/main.rs index fd9c4a0..d10d257 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,8 @@ fn main() { // Iterate over entries for entry in entries { - // Check if the file/directory exists on disk + // Check if the file/directory exists on disk and run necessary commands + // TODO: Detect subtitle files with same name/metadata and process them automatically without repeated input match settings["directory"] { // Normal file false => { diff --git a/src/structs.rs b/src/structs.rs index 5f89646..0438d33 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -80,7 +80,7 @@ impl fmt::Display for Language { } // Get long name of a language -fn get_long_lang(short: &str) -> String { +pub fn get_long_lang(short: &str) -> String { let long = match short { "en" => "English", "hi" => "Hindi",