From 5fc2d207e94f241161f65482346d56e8445c4914 Mon Sep 17 00:00:00 2001 From: Elwador <75888166+Elwador@users.noreply.github.com> Date: Fri, 26 Jul 2024 06:05:05 +0200 Subject: [PATCH] Add - Added forced display option to default subs Fix - Grace period of third party subscription not detected --- CRD/Downloader/Crunchyroll/CRAuth.cs | 7 ++++--- CRD/Utils/Muxing/Merger.cs | 3 +++ CRD/Utils/Structs/CrDownloadOptions.cs | 3 +++ CRD/Utils/Structs/CrProfile.cs | 3 +++ CRD/ViewModels/SettingsPageViewModel.cs | 5 +++++ CRD/Views/SettingsPageView.axaml | 12 ++++++++---- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CRD/Downloader/Crunchyroll/CRAuth.cs b/CRD/Downloader/Crunchyroll/CRAuth.cs index 4298b70..bea3979 100644 --- a/CRD/Downloader/Crunchyroll/CRAuth.cs +++ b/CRD/Downloader/Crunchyroll/CRAuth.cs @@ -108,16 +108,17 @@ public class CrAuth{ var requestSubs = HttpClientReq.CreateRequestMessage(Api.Subscription + crunInstance.Token.account_id, HttpMethod.Get, true, false, null); var responseSubs = await HttpClientReq.Instance.SendHttpRequest(requestSubs); - + if (responseSubs.IsOk){ var subsc = Helpers.Deserialize(responseSubs.ResponseContent, crunInstance.SettingsJsonSerializerSettings); crunInstance.Profile.Subscription = subsc; if ( subsc is{ SubscriptionProducts:{ Count: 0 }, ThirdPartySubscriptionProducts.Count: > 0 }){ var thirdPartySub = subsc.ThirdPartySubscriptionProducts.First(); - var remaining = thirdPartySub.ExpirationDate - DateTime.UtcNow; + var expiration = thirdPartySub.InGrace ? thirdPartySub.InGraceExpirationDate : thirdPartySub.ExpirationDate; + var remaining = expiration - DateTime.UtcNow; crunInstance.Profile.HasPremium = remaining > TimeSpan.Zero; crunInstance.Profile.Subscription.IsActive = remaining > TimeSpan.Zero; - crunInstance.Profile.Subscription.NextRenewalDate = thirdPartySub.ExpirationDate; + crunInstance.Profile.Subscription.NextRenewalDate = expiration; } else if(subsc is{ SubscriptionProducts:{ Count: 0 }, NonrecurringSubscriptionProducts.Count: > 0 }){ var nonRecurringSub = subsc.NonrecurringSubscriptionProducts.First(); var remaining = nonRecurringSub.EndDate - DateTime.UtcNow; diff --git a/CRD/Utils/Muxing/Merger.cs b/CRD/Utils/Muxing/Merger.cs index c05170c..04da6e2 100644 --- a/CRD/Utils/Muxing/Merger.cs +++ b/CRD/Utils/Muxing/Merger.cs @@ -194,6 +194,9 @@ public class Merger{ if (options.Defaults.Sub.Code == subObj.Language.Code && CrunchyrollManager.Instance.CrunOptions.DefaultSubSigns == subObj.Signs && subObj.ClosedCaption == false){ args.Add("--default-track 0"); + if (CrunchyrollManager.Instance.CrunOptions.DefaultSubForcedDisplay){ + args.Add("--forced-track 0:yes"); + } } else{ args.Add("--default-track 0:0"); } diff --git a/CRD/Utils/Structs/CrDownloadOptions.cs b/CRD/Utils/Structs/CrDownloadOptions.cs index c8df7db..c49ad2e 100644 --- a/CRD/Utils/Structs/CrDownloadOptions.cs +++ b/CRD/Utils/Structs/CrDownloadOptions.cs @@ -98,6 +98,9 @@ public class CrDownloadOptions{ [YamlMember(Alias = "mux_default_sub_signs", ApplyNamingConventions = false)] public bool DefaultSubSigns{ get; set; } + + [YamlMember(Alias = "mux_default_sub_forced_display", ApplyNamingConventions = false)] + public bool DefaultSubForcedDisplay{ get; set; } [YamlMember(Alias = "mux_default_dub", ApplyNamingConventions = false)] public string DefaultAudio{ get; set; } diff --git a/CRD/Utils/Structs/CrProfile.cs b/CRD/Utils/Structs/CrProfile.cs index 16d7e0a..50bca00 100644 --- a/CRD/Utils/Structs/CrProfile.cs +++ b/CRD/Utils/Structs/CrProfile.cs @@ -90,5 +90,8 @@ public class ThirdPartySubscriptionProduct{ public bool AutoRenew{ get; set; } [JsonProperty("expiration_date")] public DateTime ExpirationDate{ get; set; } + + [JsonProperty("in_grace_expiration_date")] + public DateTime InGraceExpirationDate{ get; set; } } \ No newline at end of file diff --git a/CRD/ViewModels/SettingsPageViewModel.cs b/CRD/ViewModels/SettingsPageViewModel.cs index 0ff7d0d..d4e0b20 100644 --- a/CRD/ViewModels/SettingsPageViewModel.cs +++ b/CRD/ViewModels/SettingsPageViewModel.cs @@ -59,6 +59,9 @@ public partial class SettingsPageViewModel : ViewModelBase{ [ObservableProperty] private bool _defaultSubSigns; + + [ObservableProperty] + private bool _defaultSubForcedDisplay; [ObservableProperty] private bool _includeEpisodeDescription; @@ -382,6 +385,7 @@ public partial class SettingsPageViewModel : ViewModelBase{ AddScaledBorderAndShadow = options.SubsAddScaledBorder is ScaledBorderAndShadowSelection.ScaledBorderAndShadowNo or ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes; SelectedScaledBorderAndShadow = GetScaledBorderAndShadowFromOptions(options); + DefaultSubForcedDisplay = options.DefaultSubForcedDisplay; DefaultSubSigns = options.DefaultSubSigns; HistoryAddSpecials = options.HistoryAddSpecials; DownloadSpeed = options.DownloadSpeedLimit; @@ -450,6 +454,7 @@ public partial class SettingsPageViewModel : ViewModelBase{ } CrunchyrollManager.Instance.CrunOptions.DefaultSubSigns = DefaultSubSigns; + CrunchyrollManager.Instance.CrunOptions.DefaultSubForcedDisplay = DefaultSubForcedDisplay; CrunchyrollManager.Instance.CrunOptions.IncludeVideoDescription = IncludeEpisodeDescription; CrunchyrollManager.Instance.CrunOptions.HistoryAddSpecials = HistoryAddSpecials; CrunchyrollManager.Instance.CrunOptions.VideoTitle = FileTitle; diff --git a/CRD/Views/SettingsPageView.axaml b/CRD/Views/SettingsPageView.axaml index 519db64..abee0c6 100644 --- a/CRD/Views/SettingsPageView.axaml +++ b/CRD/Views/SettingsPageView.axaml @@ -309,10 +309,14 @@ - - + + + + + +