mirror of
https://github.com/Crunchy-DL/Crunchy-Downloader.git
synced 2026-01-11 20:10:26 +00:00
Add - Added Custom encoding presets Add - Added Skip Muxing to muxing settings Add - Added Dubs to file name settings Add - IP check in settings to check if VPN is being used Add - Dubs to "Add Downloads" Tab Add - Series folder link to history series if it finds the folder Add - Added command line arguments Add - Added proxy settings to the Settings tab (changes require a restart to take effect) Add - Added option to set "Sign" subs forced flag Add - Added option to set "CC" subs "hearing-impaired" flag Add - Added encoding presets editing Add - Added CC subtitles font option to the settings Add - Added available dubs to history episodes Chg - Defaults to system accent color when no color is selected in the settings Chg - Audio only mux to only copy and not encode Chg - Update dialog Chg - Light mode color adjustments Chg - Http Connection change to detect proxy (Clash) Chg - Settings filename description Chg - Changed FPS on encoding presets to 24fps Chg - Adjusted encoding to allow h264_nvenc & hevc_nvenc Chg - Moved sync timing folders from the Windows temp folder to the application root's temp folder Chg - The temp folder will now be deleted automatically when empty Fix - Locale not correctly applied to Urls in the "Add Downloads" Tab Fix - Locale not correctly applied to Search in the "Add Downloads" Tab Fix - Scrolling issue in settings Fix - Fix crash when removing streaming tokens (TOO_MANY_ACTIVE_STREAMS) Fix - Search didn't reset correctly Fix - Clash proxy didn't work Fix - Chapters were always taken from the original version (mainly JP) Fix - Connection issue Fix - Fixed an issue where proxy settings were only available when history was enabled Fix - Fixed scrolling issues with certain series in the "Add Downloads" tab Fix - Fixed an issue where History Series appeared incomplete after being added then deleted and re-added Fix - Fixed a crash related to sync timing
167 lines
No EOL
7.3 KiB
C#
167 lines
No EOL
7.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace CRD.Utils.Structs;
|
|
|
|
public class Languages{
|
|
public static readonly LanguageItem[] languages ={
|
|
new(){ CrLocale = "ja-JP", Locale = "ja", Code = "jpn", Name = "Japanese" },
|
|
new(){ CrLocale = "en-US", Locale = "en", Code = "eng", Name = "English" },
|
|
new(){ CrLocale = "de-DE", Locale = "de", Code = "deu", Name = "German" },
|
|
new(){ CrLocale = "en-IN", Locale = "en-IN", Code = "eng", Name = "English (India)" },
|
|
new(){ CrLocale = "es-LA", Locale = "es-LA", Code = "spa", Name = "Spanish", Language = "Latin American Spanish" },
|
|
new(){ CrLocale = "es-419", Locale = "es-419", Code = "spa-419", Name = "Spanish", Language = "Latin American Spanish" },
|
|
new(){ CrLocale = "es-ES", Locale = "es-ES", Code = "spa-ES", Name = "Castilian", Language = "European Spanish" },
|
|
new(){ CrLocale = "pt-BR", Locale = "pt-BR", Code = "por", Name = "Portuguese", Language = "Brazilian Portuguese" },
|
|
new(){ CrLocale = "pt-PT", Locale = "pt-PT", Code = "por", Name = "Portuguese (Portugal)", Language = "Portugues (Portugal)" },
|
|
new(){ CrLocale = "fr-FR", Locale = "fr", Code = "fra", Name = "French" },
|
|
new(){ CrLocale = "ar-ME", Locale = "ar", Code = "ara-ME", Name = "Arabic" },
|
|
new(){ CrLocale = "ar-SA", Locale = "ar", Code = "ara", Name = "Arabic (Saudi Arabia)" },
|
|
new(){ CrLocale = "it-IT", Locale = "it", Code = "ita", Name = "Italian" },
|
|
new(){ CrLocale = "ru-RU", Locale = "ru", Code = "rus", Name = "Russian" },
|
|
new(){ CrLocale = "tr-TR", Locale = "tr", Code = "tur", Name = "Turkish" },
|
|
new(){ CrLocale = "hi-IN", Locale = "hi", Code = "hin", Name = "Hindi" },
|
|
// new(){ locale = "zh", code = "cmn", name = "Chinese (Mandarin, PRC)" },
|
|
new(){ CrLocale = "zh-CN", Locale = "zh-CN", Code = "zho", Name = "Chinese (Mainland China)" },
|
|
new(){ CrLocale = "zh-TW", Locale = "zh-TW", Code = "chi", Name = "Chinese (Taiwan)" },
|
|
new(){ CrLocale = "zh-HK", Locale = "zh-HK", Code = "zho-HK", Name = "Chinese (Hong Kong)" },
|
|
new(){ CrLocale = "ko-KR", Locale = "ko", Code = "kor", Name = "Korean" },
|
|
new(){ CrLocale = "ca-ES", Locale = "ca-ES", Code = "cat", Name = "Catalan" },
|
|
new(){ CrLocale = "pl-PL", Locale = "pl-PL", Code = "pol", Name = "Polish" },
|
|
new(){ CrLocale = "th-TH", Locale = "th-TH", Code = "tha", Name = "Thai", Language = "ไทย" },
|
|
new(){ CrLocale = "ta-IN", Locale = "ta-IN", Code = "tam", Name = "Tamil (India)", Language = "தமிழ்" },
|
|
new(){ CrLocale = "ms-MY", Locale = "ms-MY", Code = "may", Name = "Malay (Malaysia)", Language = "Bahasa Melayu" },
|
|
new(){ CrLocale = "vi-VN", Locale = "vi-VN", Code = "vie", Name = "Vietnamese", Language = "Tiếng Việt" },
|
|
new(){ CrLocale = "id-ID", Locale = "id-ID", Code = "ind", Name = "Indonesian", Language = "Bahasa Indonesia" },
|
|
new(){ CrLocale = "te-IN", Locale = "te-IN", Code = "tel", Name = "Telugu (India)", Language = "తెలుగు" },
|
|
};
|
|
|
|
public static List<string> SortListByLangList(List<string> langList){
|
|
var orderMap = languages.Select((value, index) => new { Value = value.CrLocale, Index = index })
|
|
.ToDictionary(x => x.Value, x => x.Index);
|
|
langList.Sort((x, y) =>
|
|
{
|
|
bool xExists = orderMap.ContainsKey(x);
|
|
bool yExists = orderMap.ContainsKey(y);
|
|
|
|
if (xExists && yExists)
|
|
return orderMap[x].CompareTo(orderMap[y]); // Sort by main list order
|
|
else if (xExists)
|
|
return -1; // x comes before any missing value
|
|
else if (yExists)
|
|
return 1; // y comes before any missing value
|
|
else
|
|
return string.Compare(x, y); // Sort alphabetically or by another logic for missing values
|
|
});
|
|
|
|
return langList;
|
|
}
|
|
|
|
public static LanguageItem FixAndFindCrLc(string cr_locale){
|
|
if (string.IsNullOrEmpty(cr_locale)){
|
|
return new LanguageItem();
|
|
}
|
|
|
|
string str = FixLanguageTag(cr_locale);
|
|
return FindLang(str);
|
|
}
|
|
|
|
public static string SubsFile(string fnOutput, string subsIndex, LanguageItem langItem, bool isCC, string ccTag , bool? isSigns = false, string? format = "ass", bool addIndexAndLangCode = true){
|
|
subsIndex = (int.Parse(subsIndex) + 1).ToString().PadLeft(2, '0');
|
|
string fileName = $"{fnOutput}";
|
|
|
|
if (addIndexAndLangCode){
|
|
fileName += $".{subsIndex}.{langItem.CrLocale}";
|
|
}
|
|
|
|
//removed .{langItem.language} from file name at end
|
|
|
|
if (isCC){
|
|
fileName += $".{ccTag}";
|
|
}
|
|
|
|
if (isSigns == true){
|
|
fileName += ".signs";
|
|
}
|
|
|
|
fileName += $".{format}";
|
|
return fileName;
|
|
}
|
|
|
|
public static string FixLanguageTag(string tag){
|
|
tag = tag ?? "und";
|
|
|
|
var match = Regex.Match(tag, @"^(\w{2})-?(\w{2})$");
|
|
if (match.Success){
|
|
string tagLang = $"{match.Groups[1].Value}-{match.Groups[2].Value.ToUpper()}";
|
|
|
|
var langObj = FindLang(tagLang);
|
|
if (langObj.CrLocale != "und"){
|
|
return langObj.CrLocale;
|
|
}
|
|
|
|
return tagLang;
|
|
}
|
|
|
|
return tag;
|
|
}
|
|
|
|
public static List<string> SortTags(List<string> data){
|
|
var retData = data.Select(e => new LanguageItem{ Locale = e }).ToList();
|
|
var sorted = SortSubtitles(retData);
|
|
return sorted.Select(e => e.Locale).ToList();
|
|
}
|
|
|
|
public static LanguageItem FindLang(string crLocale){
|
|
LanguageItem lang = languages.FirstOrDefault(l => l.CrLocale == crLocale);
|
|
if (lang.CrLocale != null){
|
|
return lang;
|
|
} else{
|
|
return new LanguageItem{
|
|
CrLocale = "und",
|
|
Locale = "un",
|
|
Code = "und",
|
|
Name = string.Empty,
|
|
Language = string.Empty
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
public static LanguageItem Locale2language(string locale){
|
|
LanguageItem? filteredLocale = languages.FirstOrDefault(l => { return l.Locale == locale || l.CrLocale == locale; });
|
|
if (filteredLocale != null){
|
|
return (LanguageItem)filteredLocale;
|
|
} else{
|
|
return new LanguageItem{
|
|
CrLocale = "und",
|
|
Locale = "un",
|
|
Code = "und",
|
|
Name = string.Empty,
|
|
Language = string.Empty
|
|
};
|
|
}
|
|
}
|
|
|
|
public static List<T> SortSubtitles<T>(List<T> data, string sortKey = "locale"){
|
|
var idx = new Dictionary<string, int>();
|
|
var tags = new HashSet<string>(languages.Select(e => e.Locale));
|
|
|
|
int order = 1;
|
|
foreach (var l in tags){
|
|
idx[l] = order++;
|
|
}
|
|
|
|
return data.OrderBy(item => {
|
|
var property = typeof(T).GetProperty(sortKey, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
|
|
if (property == null) throw new ArgumentException($"Property '{sortKey}' not found on type '{typeof(T).Name}'.");
|
|
|
|
var value = property.GetValue(item) as string;
|
|
int index = idx.ContainsKey(value) ? idx[value] : 50;
|
|
return index;
|
|
}).ToList();
|
|
}
|
|
} |