diff --git a/Source/AudibleUtilities/AudibleUtilities.csproj b/Source/AudibleUtilities/AudibleUtilities.csproj index ca1bf855..0e91008b 100644 --- a/Source/AudibleUtilities/AudibleUtilities.csproj +++ b/Source/AudibleUtilities/AudibleUtilities.csproj @@ -7,7 +7,7 @@ - + diff --git a/Source/FileLiberator/DownloadFailureClassifier.cs b/Source/FileLiberator/DownloadFailureClassifier.cs index c58bd643..e79f3f06 100644 --- a/Source/FileLiberator/DownloadFailureClassifier.cs +++ b/Source/FileLiberator/DownloadFailureClassifier.cs @@ -47,10 +47,12 @@ public static class DownloadFailureClassifier /// /// Audible attaches a rejection reason per validation type it ran. GenericError is Audible - /// declining to say why, which in practice means an outage or throttling rather than a decision about the - /// title; the GUI already reads it that way when it chooses which guidance to offer. Anything else names - /// an eligibility problem with the account or the title, which will not change within the hour. Saying - /// nothing at all is also treated as an outage: a refusal with no stated reason is not a settled one. + /// declining to say why, which in practice means an outage rather than a decision about the title; + /// the GUI already reads it that way when it chooses which guidance to offer. Explicit + /// CustomerThrottled is a license denial the UI names separately; backoff still treats it as + /// a settled refusal. Anything else names an eligibility problem with the account or the title, + /// which will not change within the hour. Saying nothing at all is also treated as an outage: a + /// refusal with no stated reason is not a settled one. /// private static DownloadFailureDiagnosis ClassifyLicenseDenial(ContentLicenseDeniedException ex) { diff --git a/Source/LibationCli/ContentLicenseDeniedCliSummary.cs b/Source/LibationCli/ContentLicenseDeniedCliSummary.cs index 9cdaefe1..82073a7a 100644 --- a/Source/LibationCli/ContentLicenseDeniedCliSummary.cs +++ b/Source/LibationCli/ContentLicenseDeniedCliSummary.cs @@ -13,7 +13,9 @@ internal static class ContentLicenseDeniedCliSummary { ArgumentNullException.ThrowIfNull(ex); - yield return "Audible denied a content license (download not allowed for this account/title)."; + yield return ex.IsCustomerThrottled + ? "Audible denied a content license because this account is being throttled. Wait 24 to 48 hours before trying again. This is not a Libation bug." + : "Audible denied a content license (download not allowed for this account/title)."; yield return ex.Message; if (ex.Ownership?.Message is { } own && !string.IsNullOrWhiteSpace(own)) @@ -30,8 +32,8 @@ internal static class ContentLicenseDeniedCliSummary } /// - /// Audible never says "you are being throttled", so this suggestion relies on Libation's own record of recent - /// downloads. Silent unless that record makes throttling a plausible explanation and no limit is set yet. + /// Extra pacing hint from Libation's own download record when Audible did not name CustomerThrottled. + /// Silent unless that record makes throttling a plausible explanation and no limit is set yet. /// private static IEnumerable SuggestDailyLimitLines() { diff --git a/Source/LibationFileManager/DailyDownloadLimitUserMessage.cs b/Source/LibationFileManager/DailyDownloadLimitUserMessage.cs index 62dc746f..e40045a6 100644 --- a/Source/LibationFileManager/DailyDownloadLimitUserMessage.cs +++ b/Source/LibationFileManager/DailyDownloadLimitUserMessage.cs @@ -55,9 +55,9 @@ public static class DailyDownloadLimitUserMessage => $"Skipped {skippedCount} title(s) because of your daily download limit. They remain un-liberated and will be tried on the next run."; /// - /// Suggests turning the limit on after a license denial that looks like Audible throttling. Returns null when - /// the suggestion would be unhelpful: a limit is already configured, or too little was downloaded recently for - /// throttling to be a plausible explanation. + /// Suggests turning the limit on after a license denial that looks like Audible throttling but did not + /// name CustomerThrottled. Returns null when the suggestion would be unhelpful: a limit is already + /// configured, or too little was downloaded recently for throttling to be a plausible explanation. /// public static string? BuildSuggestionParagraph(Configuration config, IReadOnlyList history, DateTimeOffset now) { diff --git a/Source/LibationFileManager/LibationFileManager.csproj b/Source/LibationFileManager/LibationFileManager.csproj index d1fd8c3d..9472e122 100644 --- a/Source/LibationFileManager/LibationFileManager.csproj +++ b/Source/LibationFileManager/LibationFileManager.csproj @@ -6,7 +6,7 @@ - + diff --git a/Source/LibationUiBase/ContentLicenseDeniedUserMessage.cs b/Source/LibationUiBase/ContentLicenseDeniedUserMessage.cs index 8a6df300..a378ab53 100644 --- a/Source/LibationUiBase/ContentLicenseDeniedUserMessage.cs +++ b/Source/LibationUiBase/ContentLicenseDeniedUserMessage.cs @@ -6,8 +6,8 @@ namespace LibationUiBase; /// /// User-facing copy when Audible denies a content license (download/decrypt). Covers temporary -/// service issues and Audible Plus throttling — often mistaken for a Libation bug. -/// Shared by WinForms and Avalonia via the process queue. +/// service issues, explicit CustomerThrottled refusals, and Audible Plus denials — often mistaken +/// for a Libation bug. Shared by WinForms and Avalonia via the process queue. /// public static class ContentLicenseDeniedUserMessage { @@ -25,6 +25,18 @@ public static class ContentLicenseDeniedUserMessage If the problem continues after several days, open an issue on Libation's GitHub and include your logs. """ + AppendSuggestion(); + /// Audible named CustomerThrottled. Shown for any title, Plus or owned. + public static string BuildDialogBodyForThrottling(string bookTitleWithSubtitle) + => $""" + You were denied a content license for {bookTitleWithSubtitle} + + Audible refused this download because your account is being throttled. This is a temporary rate limit on Audible's side, not a Libation bug. + + Wait 24 to 48 hours before trying again. In the meantime you should still be able to play this title in the Audible app or website. + + If it still fails after several days, open an issue on Libation's GitHub and include your logs. + """ + AppendSuggestion(); + /// License denied on an Audible Plus title — often rate limiting, not a Libation defect. public static string BuildDialogBodyForPlusCatalog(string bookTitleWithSubtitle) => $""" @@ -38,9 +50,10 @@ public static class ContentLicenseDeniedUserMessage """ + AppendSuggestion(); /// - /// Audible reports no distinct "throttled" reason, so this suggestion is what turns a guess into evidence: - /// it only appears when Libation's own record shows enough recent downloads for throttling to be plausible, - /// and when the user has no daily limit configured yet. Logged as well as shown. + /// When Audible names CustomerThrottled, the throttling dialog already says so. This extra paragraph is + /// for denials without that reason: it only appears when Libation's own record shows enough recent + /// downloads for throttling to be plausible, and when the user has no daily limit configured yet. + /// Logged as well as shown. /// private static string AppendSuggestion() { diff --git a/Source/LibationUiBase/ProcessQueue/ProcessBookViewModel.cs b/Source/LibationUiBase/ProcessQueue/ProcessBookViewModel.cs index 427bbb4c..774f5371 100644 --- a/Source/LibationUiBase/ProcessQueue/ProcessBookViewModel.cs +++ b/Source/LibationUiBase/ProcessQueue/ProcessBookViewModel.cs @@ -25,6 +25,8 @@ public enum ProcessBookResult FailedAbort, LicenseDenied, LicenseDeniedPossibleOutage, + /// Audible named CustomerThrottled on the license denial. + LicenseDeniedThrottled, /// ADRM licenserequest failed with Sable acr:null; Widevine may work (see WidevineRecommendation). WidevineRecommended, /// Volume full on write; queue should stop (see ProcessQueueViewModel queue loop). @@ -86,6 +88,7 @@ public class ProcessBookViewModel : ReactiveObject (ProcessBookResult.LicenseDenied, true) => "License denied (Plus; often temporary)", (ProcessBookResult.LicenseDenied, false) => "License Denied", (ProcessBookResult.LicenseDeniedPossibleOutage, _) => "Possible Service Interruption", + (ProcessBookResult.LicenseDeniedThrottled, _) => "License denied (throttled)", (ProcessBookResult.WidevineRecommended, _) => WidevineRecommendationUserMessage.QueueStatusText, (ProcessBookResult.DiskFull, _) => "Disk full, queue stopped", _ => Status.ToString(), @@ -237,7 +240,12 @@ public class ProcessBookViewModel : ReactiveObject catch (ContentLicenseDeniedException ldex) { Serilog.Log.Logger.Error(ldex, "Content license was denied for {Book}", LibraryBook.LogFriendly()); - if (ldex.AYCL?.RejectionReason is null or RejectionReason.GenericError) + if (ldex.IsCustomerThrottled) + { + LogInfo($"{procName}: Content license denied because Audible is throttling this account. Wait 24 to 48 hours, then try again. This is not a Libation bug. - {LibraryBook.Book}"); + result = ProcessBookResult.LicenseDeniedThrottled; + } + else if (ldex.AYCL?.RejectionReason is null or RejectionReason.GenericError) { LogInfo($"{procName}: Content license was denied, but this error appears to be caused by a temporary interruption of service. - {LibraryBook.Book}"); result = ProcessBookResult.LicenseDeniedPossibleOutage; diff --git a/Source/LibationUiBase/ProcessQueue/ProcessQueueViewModel.cs b/Source/LibationUiBase/ProcessQueue/ProcessQueueViewModel.cs index 5dda9085..2b5983e8 100644 --- a/Source/LibationUiBase/ProcessQueue/ProcessQueueViewModel.cs +++ b/Source/LibationUiBase/ProcessQueue/ProcessQueueViewModel.cs @@ -814,15 +814,20 @@ public class ProcessQueueViewModel : ReactiveObject await book.LibraryBook.UpdateBookStatusAsync(LiberatedStatus.Error); } else if (result == ProcessBookResult.LicenseDeniedPossibleOutage + || result == ProcessBookResult.LicenseDeniedThrottled || (result == ProcessBookResult.LicenseDenied && book.LibraryBook.IsAudiblePlus)) { bool show; lock (resultLock) { show = !shownLicenseGuidanceMessage; shownLicenseGuidanceMessage = true; } if (show) { - var body = result == ProcessBookResult.LicenseDeniedPossibleOutage - ? ContentLicenseDeniedUserMessage.BuildDialogBodyForPossibleOutage(book.LibraryBook.Book.TitleWithSubtitle) - : ContentLicenseDeniedUserMessage.BuildDialogBodyForPlusCatalog(book.LibraryBook.Book.TitleWithSubtitle); + var title = book.LibraryBook.Book.TitleWithSubtitle; + var body = result switch + { + ProcessBookResult.LicenseDeniedPossibleOutage => ContentLicenseDeniedUserMessage.BuildDialogBodyForPossibleOutage(title), + ProcessBookResult.LicenseDeniedThrottled => ContentLicenseDeniedUserMessage.BuildDialogBodyForThrottling(title), + _ => ContentLicenseDeniedUserMessage.BuildDialogBodyForPlusCatalog(title) + }; await MessageBoxBase.Show( body, ContentLicenseDeniedUserMessage.DialogCaption, diff --git a/Source/_Tests/FileLiberator.Tests/DownloadFailureClassifierTests.cs b/Source/_Tests/FileLiberator.Tests/DownloadFailureClassifierTests.cs index 34a26457..efaeae18 100644 --- a/Source/_Tests/FileLiberator.Tests/DownloadFailureClassifierTests.cs +++ b/Source/_Tests/FileLiberator.Tests/DownloadFailureClassifierTests.cs @@ -163,4 +163,32 @@ public class DownloadFailureClassifierTests [TestMethod] public void Classifying_null_is_harmless() => Assert.IsNull(DownloadFailureClassifier.Classify(null)); + + [TestMethod] + public void CustomerThrottled_mixed_with_eligibility_is_still_a_license_denial() + { + // From Log202609: Ownership named CustomerThrottled while Membership/Client/AYCL still failed eligibility. + var ex = Denied( + ("Membership", RejectionReason.RequesterEligibility, "Customer is not part of any plans"), + ("Ownership", RejectionReason.CustomerThrottled, "Customer id [##############] being throttled"), + ("Client", RejectionReason.RequesterEligibility, "does not has access to asin[B005EGKBYK]."), + ("AYCL", RejectionReason.ContentEligibility, "Asin: [B005EGKBYK] is not eligible for AYCL")); + + Assert.IsTrue(DownloadFailureClassifier.TryClassify(ex, out var diagnosis)); + Assert.AreEqual(DownloadFailureKind.LicenseDenied, diagnosis.Kind); + Assert.IsTrue(ex.IsCustomerThrottled); + StringAssert.Contains(diagnosis.Reason, "throttled"); + } + + [TestMethod] + public void An_eligibility_refusal_without_CustomerThrottled_is_not_throttling() + { + var ex = Denied( + ("Ownership", RejectionReason.RequesterEligibility, "not owned"), + ("AYCL", RejectionReason.ContentEligibility, "Asin is not eligible for AYCL")); + + Assert.IsTrue(DownloadFailureClassifier.TryClassify(ex, out var diagnosis)); + Assert.AreEqual(DownloadFailureKind.LicenseDenied, diagnosis.Kind); + Assert.IsFalse(ex.IsCustomerThrottled); + } } diff --git a/Source/_Tests/LibationCli.Tests/ContentLicenseDeniedCliSummaryTests.cs b/Source/_Tests/LibationCli.Tests/ContentLicenseDeniedCliSummaryTests.cs new file mode 100644 index 00000000..0c036bd1 --- /dev/null +++ b/Source/_Tests/LibationCli.Tests/ContentLicenseDeniedCliSummaryTests.cs @@ -0,0 +1,58 @@ +using AudibleApi; +using AudibleApi.Common; +using LibationFileManager; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Linq; + +namespace LibationCli.Tests; + +[TestClass] +public class ContentLicenseDeniedCliSummaryTests +{ + [TestInitialize] + public void Initialize() => Configuration.CreateMockInstance(); + + [TestCleanup] + public void Cleanup() => Configuration.RestoreSingletonInstance(); + + private static ContentLicenseDeniedException Denied(params (string ValidationType, string RejectionReason, string Message)[] reasons) + => new( + new Uri("https://api.audible.com/1.0/content/B005EGKBYK/licenserequest"), + new ContentLicense + { + Asin = "B005EGKBYK", + StatusCode = "Denied", + LicenseDenialReasons = [.. Array.ConvertAll(reasons, r => new LicenseDenialReason + { + ValidationType = r.ValidationType, + RejectionReason = r.RejectionReason, + Message = r.Message + })] + }); + + [TestMethod] + public void A_throttled_denial_leads_with_throttling_guidance() + { + var ex = Denied( + ("Ownership", RejectionReason.CustomerThrottled, "Customer id [##############] being throttled"), + ("AYCL", RejectionReason.ContentEligibility, "Asin: [B005EGKBYK] is not eligible for AYCL")); + + var lines = ContentLicenseDeniedCliSummary.Lines(ex).ToList(); + + StringAssert.Contains(lines[0], "throttled"); + StringAssert.Contains(lines[0], "24 to 48 hours"); + Assert.IsTrue(lines.Any(l => l.StartsWith("Ownership:", StringComparison.Ordinal))); + } + + [TestMethod] + public void An_eligibility_denial_keeps_the_generic_opener() + { + var ex = Denied(("Ownership", RejectionReason.RequesterEligibility, "not owned")); + + var lines = ContentLicenseDeniedCliSummary.Lines(ex).ToList(); + + StringAssert.Contains(lines[0], "download not allowed"); + Assert.IsFalse(lines[0].Contains("throttled", StringComparison.Ordinal)); + } +} diff --git a/Source/_Tests/LibationUiBase.Tests/ContentLicenseDeniedUserMessageTests.cs b/Source/_Tests/LibationUiBase.Tests/ContentLicenseDeniedUserMessageTests.cs new file mode 100644 index 00000000..d5ab7736 --- /dev/null +++ b/Source/_Tests/LibationUiBase.Tests/ContentLicenseDeniedUserMessageTests.cs @@ -0,0 +1,43 @@ +using LibationFileManager; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace LibationUiBase.Tests; + +[TestClass] +public class ContentLicenseDeniedUserMessageTests +{ + [TestInitialize] + public void Initialize() => Configuration.CreateMockInstance(); + + [TestCleanup] + public void Cleanup() => Configuration.RestoreSingletonInstance(); + + [TestMethod] + public void The_throttling_dialog_names_Audible_throttling_and_says_to_wait() + { + var body = ContentLicenseDeniedUserMessage.BuildDialogBodyForThrottling("Monster Hunter Alpha"); + + StringAssert.Contains(body, "Monster Hunter Alpha"); + StringAssert.Contains(body, "throttled"); + StringAssert.Contains(body, "24 to 48 hours"); + StringAssert.Contains(body, "not a Libation bug"); + } + + [TestMethod] + public void The_outage_dialog_still_talks_about_a_service_interruption() + { + var body = ContentLicenseDeniedUserMessage.BuildDialogBodyForPossibleOutage("Monster Hunter Alpha"); + + StringAssert.Contains(body, "temporary interruption of service"); + Assert.IsFalse(body.Contains("account is being throttled", StringComparison.Ordinal)); + } + + [TestMethod] + public void The_Plus_dialog_still_names_the_Plus_catalog() + { + var body = ContentLicenseDeniedUserMessage.BuildDialogBodyForPlusCatalog("Monster Hunter Alpha"); + + StringAssert.Contains(body, "Audible Plus catalog"); + Assert.IsFalse(body.Contains("account is being throttled", StringComparison.Ordinal)); + } +}