mirror of
https://github.com/SinTan1729/movie-rename.git
synced 2024-12-26 12:18:37 -06:00
Detect subtitle language from the old filename
This commit is contained in:
parent
17300e0362
commit
c52643033f
3 changed files with 20 additions and 9 deletions
|
@ -6,7 +6,7 @@ use std::{collections::HashMap, fs, path::Path, process::exit};
|
||||||
use tmdb::{model::*, themoviedb::*};
|
use tmdb::{model::*, themoviedb::*};
|
||||||
use torrent_name_parser::Metadata;
|
use torrent_name_parser::Metadata;
|
||||||
|
|
||||||
use crate::structs::{Language, MovieEntry};
|
use crate::structs::{get_long_lang, Language, MovieEntry};
|
||||||
|
|
||||||
// Get the version from Cargo.toml
|
// Get the version from Cargo.toml
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
@ -89,12 +89,22 @@ pub fn process_file(
|
||||||
// Handle the case for subtitle files
|
// Handle the case for subtitle files
|
||||||
let mut is_subtitle = false;
|
let mut is_subtitle = false;
|
||||||
if ["srt", "ssa"].contains(&extension.as_str()) {
|
if ["srt", "ssa"].contains(&extension.as_str()) {
|
||||||
let lang_list = Language::generate_list();
|
// Try to detect if there's already language info in the filename, else ask user to choose
|
||||||
let lang_choice = Select::new("Choose the language for the subtitle file:", lang_list)
|
let filename_parts: Vec<&str> = filename.rsplit(".").collect();
|
||||||
.prompt()
|
if filename_parts.len() >= 3 && filename_parts[1].len() == 2 {
|
||||||
.expect("Invalid choice!");
|
println!(
|
||||||
if lang_choice.short != "none".to_string() {
|
"Keeping language {} as detected in the subtitle file's extension...",
|
||||||
extension = format!("{}.{}", lang_choice.short, 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;
|
is_subtitle = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,8 @@ fn main() {
|
||||||
|
|
||||||
// Iterate over entries
|
// Iterate over entries
|
||||||
for entry in 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"] {
|
match settings["directory"] {
|
||||||
// Normal file
|
// Normal file
|
||||||
false => {
|
false => {
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl fmt::Display for Language {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get long name of a 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 {
|
let long = match short {
|
||||||
"en" => "English",
|
"en" => "English",
|
||||||
"hi" => "Hindi",
|
"hi" => "Hindi",
|
||||||
|
|
Loading…
Reference in a new issue