From 8fc08124483cfd081be712bb8abeb9d6f2226629 Mon Sep 17 00:00:00 2001 From: Elwador <75888166+Elwador@users.noreply.github.com> Date: Sat, 15 Jun 2024 15:55:39 +0200 Subject: [PATCH] Add - Added missing languages Add - Added log mode to settings --- CRD/Downloader/CRAuth.cs | 4 +++ CRD/Downloader/Crunchyroll.cs | 15 ++++++++-- CRD/Downloader/History.cs | 2 +- CRD/Utils/DRM/Widevine.cs | 2 +- CRD/Utils/Enums/EnumCollection.cs | 33 ++++++++++++++++++++++ CRD/Utils/Files/CfgManager.cs | 26 +++++++++++++++++ CRD/Utils/Helpers.cs | 22 ++++++--------- CRD/Utils/Http/HttpClientReq.cs | 2 +- CRD/Utils/Parser/DashParser.cs | 2 -- CRD/Utils/Sonarr/SonarrClient.cs | 10 +++---- CRD/Utils/Structs/CrDownloadOptions.cs | 3 ++ CRD/Utils/Structs/Languages.cs | 16 +++++------ CRD/ViewModels/AddDownloadPageViewModel.cs | 2 +- CRD/ViewModels/DownloadsPageViewModel.cs | 11 +++++++- CRD/ViewModels/SeriesPageViewModel.cs | 2 +- CRD/ViewModels/SettingsPageViewModel.cs | 14 +++++++++ CRD/Views/SettingsPageView.axaml | 9 ++++++ 17 files changed, 138 insertions(+), 37 deletions(-) diff --git a/CRD/Downloader/CRAuth.cs b/CRD/Downloader/CRAuth.cs index 4202951..b9aedf6 100644 --- a/CRD/Downloader/CRAuth.cs +++ b/CRD/Downloader/CRAuth.cs @@ -153,6 +153,10 @@ public class CrAuth{ } } + if (crunInstance.Profile.Username == "???"){ + return; + } + var formData = new Dictionary{ { "refresh_token", crunInstance.Token?.refresh_token ?? string.Empty }, { "grant_type", "refresh_token" }, diff --git a/CRD/Downloader/Crunchyroll.cs b/CRD/Downloader/Crunchyroll.cs index 67d5a51..5b18c06 100644 --- a/CRD/Downloader/Crunchyroll.cs +++ b/CRD/Downloader/Crunchyroll.cs @@ -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 files = new List(); 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()); diff --git a/CRD/Downloader/History.cs b/CRD/Downloader/History.cs index 886f44a..e7d1321 100644 --- a/CRD/Downloader/History.cs +++ b/CRD/Downloader/History.cs @@ -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"); } } } diff --git a/CRD/Utils/DRM/Widevine.cs b/CRD/Utils/DRM/Widevine.cs index 5f6ba47..d952b4d 100644 --- a/CRD/Utils/DRM/Widevine.cs +++ b/CRD/Utils/DRM/Widevine.cs @@ -67,7 +67,7 @@ public class Widevine{ canDecrypt = false; } } catch (Exception e){ - Console.WriteLine(e); + Console.WriteLine("Widevine: " + e); canDecrypt = false; } } diff --git a/CRD/Utils/Enums/EnumCollection.cs b/CRD/Utils/Enums/EnumCollection.cs index e18a745..6080970 100644 --- a/CRD/Utils/Enums/EnumCollection.cs +++ b/CRD/Utils/Enums/EnumCollection.cs @@ -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{ diff --git a/CRD/Utils/Files/CfgManager.cs b/CRD/Utils/Files/CfgManager.cs index 5bc0fde..987951d 100644 --- a/CRD/Utils/Files/CfgManager.cs +++ b/CRD/Utils/Files/CfgManager.cs @@ -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(); diff --git a/CRD/Utils/Helpers.cs b/CRD/Utils/Helpers.cs index cb8f65c..0cfe291 100644 --- a/CRD/Utils/Helpers.cs +++ b/CRD/Utils/Helpers.cs @@ -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; diff --git a/CRD/Utils/Http/HttpClientReq.cs b/CRD/Utils/Http/HttpClientReq.cs index 26ec3bd..4ab83fa 100644 --- a/CRD/Utils/Http/HttpClientReq.cs +++ b/CRD/Utils/Http/HttpClientReq.cs @@ -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); } } diff --git a/CRD/Utils/Parser/DashParser.cs b/CRD/Utils/Parser/DashParser.cs index 15ec54f..a7f0bc8 100644 --- a/CRD/Utils/Parser/DashParser.cs +++ b/CRD/Utils/Parser/DashParser.cs @@ -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){ diff --git a/CRD/Utils/Sonarr/SonarrClient.cs b/CRD/Utils/Sonarr/SonarrClient.cs index 8a578cb..7ed7ed0 100644 --- a/CRD/Utils/Sonarr/SonarrClient.cs +++ b/CRD/Utils/Sonarr/SonarrClient.cs @@ -92,7 +92,7 @@ public class SonarrClient{ series = JsonConvert.DeserializeObject>(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>(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(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; diff --git a/CRD/Utils/Structs/CrDownloadOptions.cs b/CRD/Utils/Structs/CrDownloadOptions.cs index 05eac33..f7f68e7 100644 --- a/CRD/Utils/Structs/CrDownloadOptions.cs +++ b/CRD/Utils/Structs/CrDownloadOptions.cs @@ -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; } + } \ No newline at end of file diff --git a/CRD/Utils/Structs/Languages.cs b/CRD/Utils/Structs/Languages.cs index a505cc9..47398e6 100644 --- a/CRD/Utils/Structs/Languages.cs +++ b/CRD/Utils/Structs/Languages.cs @@ -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; }); diff --git a/CRD/ViewModels/AddDownloadPageViewModel.cs b/CRD/ViewModels/AddDownloadPageViewModel.cs index 5b693b2..8594960 100644 --- a/CRD/ViewModels/AddDownloadPageViewModel.cs +++ b/CRD/ViewModels/AddDownloadPageViewModel.cs @@ -156,7 +156,7 @@ public partial class AddDownloadPageViewModel : ViewModelBase{ } } } else{ - Console.WriteLine("Probably not a url"); + Console.WriteLine("Unnkown input"); } } diff --git a/CRD/ViewModels/DownloadsPageViewModel.cs b/CRD/ViewModels/DownloadsPageViewModel.cs index 005b702..65b730d 100644 --- a/CRD/ViewModels/DownloadsPageViewModel.cs +++ b/CRD/ViewModels/DownloadsPageViewModel.cs @@ -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)){ diff --git a/CRD/ViewModels/SeriesPageViewModel.cs b/CRD/ViewModels/SeriesPageViewModel.cs index e228e46..3f93e9c 100644 --- a/CRD/ViewModels/SeriesPageViewModel.cs +++ b/CRD/ViewModels/SeriesPageViewModel.cs @@ -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}"); } } } \ No newline at end of file diff --git a/CRD/ViewModels/SettingsPageViewModel.cs b/CRD/ViewModels/SettingsPageViewModel.cs index e24be2e..c322b0b 100644 --- a/CRD/ViewModels/SettingsPageViewModel.cs +++ b/CRD/ViewModels/SettingsPageViewModel.cs @@ -103,6 +103,9 @@ public partial class SettingsPageViewModel : ViewModelBase{ [ObservableProperty] private bool _sonarrUseSonarrNumbering = false; + + [ObservableProperty] + private bool _logMode = false; public ObservableCollection 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(); + } + } } \ No newline at end of file diff --git a/CRD/Views/SettingsPageView.axaml b/CRD/Views/SettingsPageView.axaml index bbb7cf7..fd20940 100644 --- a/CRD/Views/SettingsPageView.axaml +++ b/CRD/Views/SettingsPageView.axaml @@ -446,6 +446,15 @@ + + + + + + +