Add - Added missing languages

Add -  Added log mode to settings
This commit is contained in:
Elwador 2024-06-15 15:55:39 +02:00
parent d405c9e7d9
commit 8fc0812448
17 changed files with 138 additions and 37 deletions

View File

@ -153,6 +153,10 @@ public class CrAuth{
}
}
if (crunInstance.Profile.Username == "???"){
return;
}
var formData = new Dictionary<string, string>{
{ "refresh_token", crunInstance.Token?.refresh_token ?? string.Empty },
{ "grant_type", "refresh_token" },

View File

@ -163,6 +163,12 @@ public class Crunchyroll{
RefreshSonarr();
}
if (CrunOptions.LogMode){
CfgManager.EnableLogMode();
} else{
CfgManager.DisableLogMode();
}
calendarLanguage = new(){
{ "en-us", "https://www.crunchyroll.com/simulcastcalendar" },
@ -559,7 +565,7 @@ public class Crunchyroll{
List<DownloadedMedia> files = new List<DownloadedMedia>();
if (data.Data != null && data.Data.All(a => a.Playback == null)){
Console.WriteLine("Video not available!");
Console.WriteLine("No Video Data found - Are you trying to download a premium episode without havíng a premium account?");
MainWindow.Instance.ShowError("No Video Data found - Are you trying to download a premium episode without havíng a premium account?");
return new DownloadResponse{
Data = files,
@ -765,7 +771,7 @@ public class Crunchyroll{
: 1;
for (int i = 0; i < streams.Count; i++){
string isSelected = options.Kstream == i + 1 ? "" : " ";
string isSelected = options.Kstream == i + 1 ? "+" : " ";
Console.WriteLine($"Full stream found! ({isSelected}{i + 1}: {streams[i].Type})");
}
@ -922,7 +928,10 @@ public class Crunchyroll{
};
}
Console.WriteLine($"Selected quality: \n\tVideo: {chosenVideoSegments.resolutionText}\n\tAudio: {chosenAudioSegments.resolutionText}\n\tServer: {selectedServer}");
Console.WriteLine($"Selected quality:");
Console.WriteLine($"\tVideo: {chosenVideoSegments.resolutionText}");
Console.WriteLine($"\tAudio: {chosenAudioSegments.resolutionText}");
Console.WriteLine($"\tServer: {selectedServer}");
Console.WriteLine("Stream URL:" + chosenVideoSegments.segments[0].uri.Split(new[]{ ",.urlset" }, StringSplitOptions.None)[0]);
fileName = Path.Combine(FileNameManager.ParseFileName(options.FileName, variables, options.Numbers, options.Override).ToArray());

View File

@ -420,7 +420,7 @@ public class History(){
historyEpisode.SonarrSeasonNumber = episode2.SeasonNumber + "";
episodes.Remove(episode2);
} else{
Console.WriteLine("Could not match episode to sonarr episode");
Console.WriteLine($"Could not match episode {historyEpisode.EpisodeTitle} to sonarr episode");
}
}
}

View File

@ -67,7 +67,7 @@ public class Widevine{
canDecrypt = false;
}
} catch (Exception e){
Console.WriteLine(e);
Console.WriteLine("Widevine: " + e);
canDecrypt = false;
}
}

View File

@ -64,6 +64,39 @@ public enum Locale{
[EnumMember(Value = "id-ID")]
IdId,
[EnumMember(Value = "en-IN")]
EnIn,
[EnumMember(Value = "pt-PT")]
PtPt,
[EnumMember(Value = "zh-TW")]
ZhTw,
[EnumMember(Value = "ca-ES")]
CaEs,
[EnumMember(Value = "pl-PL")]
PlPl,
[EnumMember(Value = "th-TH")]
ThTh,
[EnumMember(Value = "ta-IN")]
TaIn,
[EnumMember(Value = "ms-MY")]
MsMy,
[EnumMember(Value = "vi-VN")]
ViVn,
[EnumMember(Value = "te-IN")]
TeIn,
[EnumMember(Value = "id-ID")]
idID,
}
public static class EnumExtensions{

View File

@ -23,8 +23,33 @@ public class CfgManager{
public static readonly string PathVIDEOS_DIR = WorkingDirectory + "/video/";
public static readonly string PathFONTS_DIR = WorkingDirectory + "/video/";
public static readonly string PathLogFile = WorkingDirectory + "/logfile.txt";
private static StreamWriter logFile;
private static bool isLogModeEnabled = false;
public static void EnableLogMode(){
if (!isLogModeEnabled){
logFile = new StreamWriter(PathLogFile);
logFile.AutoFlush = true;
Console.SetOut(logFile);
isLogModeEnabled = true;
Console.WriteLine("Log mode enabled.");
}
}
public static void DisableLogMode(){
if (isLogModeEnabled){
logFile.Close();
StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
standardOutput.AutoFlush = true;
Console.SetOut(standardOutput);
isLogModeEnabled = false;
Console.WriteLine("Log mode disabled.");
}
}
public static void WriteJsonResponseToYamlFile(string jsonResponse, string filePath){
// Convert JSON to an object
var deserializer = new DeserializerBuilder()
@ -143,6 +168,7 @@ public class CfgManager{
Crunchyroll.Instance.CrunOptions.History = loadedOptions.History;
Crunchyroll.Instance.CrunOptions.UseNonDrmStreams = loadedOptions.UseNonDrmStreams;
Crunchyroll.Instance.CrunOptions.SonarrProperties = loadedOptions.SonarrProperties;
Crunchyroll.Instance.CrunOptions.LogMode = loadedOptions.LogMode;
}
private static object fileLock = new object();

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@ -66,30 +66,26 @@ public class Helpers{
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
process.OutputDataReceived += (sender, e) => {
if (!string.IsNullOrEmpty(e.Data)){
Console.WriteLine(e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
process.ErrorDataReceived += (sender, e) => {
if (!string.IsNullOrEmpty(e.Data)){
Console.WriteLine($"ERROR: {e.Data}");
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
await process.WaitForExitAsync();
// Define success condition more appropriately based on the application
bool isSuccess = process.ExitCode == 0;

View File

@ -97,7 +97,7 @@ public class HttpClientReq{
return (IsOk: true, ResponseContent: content);
} catch (Exception e){
Console.WriteLine(e);
Console.WriteLine($"Error: {e} \n Response: {content}");
return (IsOk: false, ResponseContent: content);
}
}

View File

@ -24,8 +24,6 @@ public class DashParser{
return ToM3u8Class.ToM3u8(parsedElement);
// string jsonString = JsonConvert.SerializeObject(M3u8);
Console.WriteLine("Hallo");
}
private static XmlElement StringToMpdXml(string manifestString){

View File

@ -92,7 +92,7 @@ public class SonarrClient{
series = JsonConvert.DeserializeObject<List<SonarrSeries>>(json) ?? [];
} catch (Exception e){
MainWindow.Instance.ShowError("Sonarr GetSeries error \n" + e);
Console.WriteLine(e);
Console.WriteLine("Sonarr GetSeries error \n" + e);
}
return series;
@ -106,8 +106,8 @@ public class SonarrClient{
try{
episodes = JsonConvert.DeserializeObject<List<SonarrEpisode>>(json) ?? [];
} catch (Exception e){
MainWindow.Instance.ShowError("Sonarr GetSeries error \n" + e);
Console.WriteLine(e);
MainWindow.Instance.ShowError("Sonarr GetEpisodes error \n" + e);
Console.WriteLine("Sonarr GetEpisodes error \n" + e);
}
return episodes;
@ -120,8 +120,8 @@ public class SonarrClient{
try{
episode = JsonConvert.DeserializeObject<SonarrEpisode>(json) ?? new SonarrEpisode();
} catch (Exception e){
MainWindow.Instance.ShowError("Sonarr GetSeries error \n" + e);
Console.WriteLine(e);
MainWindow.Instance.ShowError("Sonarr GetEpisode error \n" + e);
Console.WriteLine("Sonarr GetEpisode error \n" + e);
}
return episode;

View File

@ -119,4 +119,7 @@ public class CrDownloadOptions{
[YamlMember(Alias = "sonarr_properties", ApplyNamingConventions = false)]
public SonarrProperties? SonarrProperties{ get; set; }
[YamlMember(Alias = "log_mode", ApplyNamingConventions = false)]
public bool LogMode{ get; set; }
}

View File

@ -8,7 +8,9 @@ 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-419", Code = "spa", Name = "Spanish", Language = "Latin American Spanish" },
new(){ CrLocale = "es-419", Locale = "es-419", Code = "spa-419", Name = "Spanish", Language = "Latin American Spanish" },
@ -16,7 +18,6 @@ public class Languages{
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 = "de-DE", Locale = "de", Code = "deu", Name = "German" },
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" },
@ -35,14 +36,14 @@ public class Languages{
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 = "తెలుగు" },
new(){ CrLocale = "ja-JP", Locale = "ja", Code = "jpn", Name = "Japanese" },
new(){ CrLocale = "id-ID", Locale = "id", Code = "in", Name = "Indonesian " },
new(){ CrLocale = "id-ID", Locale = "id", Code = "in", Name = "Indonesian " }
};
public static LanguageItem FixAndFindCrLc(string cr_locale){
if (string.IsNullOrEmpty(cr_locale)){
return new LanguageItem();
}
string str = FixLanguageTag(cr_locale);
return FindLang(str);
}
@ -50,7 +51,7 @@ public class Languages{
public static string SubsFile(string fnOutput, string subsIndex, LanguageItem langItem, bool isCC, string ccTag, bool? isSigns = false, string? format = "ass"){
subsIndex = (int.Parse(subsIndex) + 1).ToString().PadLeft(2, '0');
string fileName = $"{fnOutput}.{subsIndex}.{langItem.Code}";
//removed .{langItem.language} from file name at end
if (isCC){
@ -67,12 +68,11 @@ public class Languages{
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;
@ -104,7 +104,7 @@ public class Languages{
};
}
}
public static LanguageItem Locale2language(string locale){
LanguageItem? filteredLocale = languages.FirstOrDefault(l => { return l.Locale == locale; });

View File

@ -156,7 +156,7 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
}
}
} else{
Console.WriteLine("Probably not a url");
Console.WriteLine("Unnkown input");
}
}

View File

@ -42,7 +42,7 @@ public partial class DownloadsPageViewModel : ViewModelBase{
if (downloadItem != null){
Crunchyroll.Instance.DownloadItemModels.Remove(downloadItem);
} else{
Console.WriteLine("Failed to Remove From Preview");
Console.WriteLine("Failed to Remove Episode from list");
}
}
}
@ -145,6 +145,15 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
var softSubs = "Softsub: ";
if (Crunchyroll.Instance.CrunOptions.DlSubs.Contains("all")){
if (epMeta.AvailableSubs != null){
foreach (var epMetaAvailableSub in epMeta.AvailableSubs){
softSubs += epMetaAvailableSub + " ";
}
return softSubs;
}
}
foreach (var crunOptionsDlSub in Crunchyroll.Instance.CrunOptions.DlSubs){
if (epMeta.AvailableSubs != null && epMeta.AvailableSubs.Contains(crunOptionsDlSub)){

View File

@ -87,7 +87,7 @@ public partial class SeriesPageViewModel : ViewModelBase{
UseShellExecute = true
});
} catch (Exception e){
Console.WriteLine($"An error occurred: {e.Message}");
Console.WriteLine($"An error occurred while trying to open URL - {url} : {e.Message}");
}
}
}

View File

@ -103,6 +103,9 @@ public partial class SettingsPageViewModel : ViewModelBase{
[ObservableProperty]
private bool _sonarrUseSonarrNumbering = false;
[ObservableProperty]
private bool _logMode = false;
public ObservableCollection<Color> PredefinedColors{ get; } = new(){
Color.FromRgb(255, 185, 0),
@ -248,6 +251,7 @@ public partial class SettingsPageViewModel : ViewModelBase{
LeadingNumbers = options.Numbers;
FileName = options.FileName;
SimultaneousDownloads = options.SimultaneousDownloads;
LogMode = options.LogMode;
ComboBoxItem? qualityAudio = AudioQualityList.FirstOrDefault(a => a.Content != null && (string)a.Content == options.QualityAudio) ?? null;
SelectedAudioQuality = qualityAudio ?? AudioQualityList[0];
@ -335,6 +339,7 @@ public partial class SettingsPageViewModel : ViewModelBase{
Crunchyroll.Instance.CrunOptions.SonarrProperties = props;
Crunchyroll.Instance.CrunOptions.LogMode = LogMode;
//TODO - Mux Options
@ -486,4 +491,13 @@ public partial class SettingsPageViewModel : ViewModelBase{
partial void OnSonarrUseSonarrNumberingChanged(bool value){
UpdateSettings();
}
partial void OnLogModeChanged(bool value){
UpdateSettings();
if (value){
CfgManager.EnableLogMode();
} else{
CfgManager.DisableLogMode();
}
}
}

View File

@ -446,6 +446,15 @@
</controls:SettingsExpander>
<controls:SettingsExpander Header="Log Mode"
IconSource="Help"
Description="Should only be enabled if something isn't working">
<controls:SettingsExpander.Footer>
<CheckBox IsChecked="{Binding LogMode}"> </CheckBox>
</controls:SettingsExpander.Footer>
</controls:SettingsExpander>
<Grid Margin="0 0 0 10"
ColumnDefinitions="*,Auto" RowDefinitions="*,Auto">