Files
Libation/Source/LibationUiBase/ContentLicenseDeniedUserMessage.cs
William Tanksley Jr 3e40e0f268 feat: first-class account re-registration lifecycle with automatic throttling recovery (#2126) (#2145)
* feat(domain): add RequiresReRegistration and ThrottledDeviceRecovery policy

- Add Account.RequiresReRegistration property and HasObsoleteDeviceRegistration predicate
- Update AccountCredentialStatus to treat RequiresReRegistration as missing credentials
- Introduce ThrottledDeviceRecovery service to detect throttling on obsolete profiles and mark accounts for re-registration
- Add unit tests for Account, AccountCredentialStatus, and ThrottledDeviceRecovery

* feat(core): enforce interactive re-registration across API and download queue

- Intercept RequiresReRegistration in ApiExtended, invalidate tokens during login, and reset flag upon success
- Add LicenseDeniedThrottledRecovered queue status and user message
- Update ProcessBookViewModel, ProcessQueueViewModel, and _ProcessableOptionsBase to handle throttled recovery during liberation

* feat(ui): add Widevine re-registration prompts and CLI status reporting

- Prompt to mark accounts for re-registration when Widevine is enabled in Avalonia and WinForms
- Guard settings toggle against passive navigation/loading events and revert cleanly on cancel
- Show 're-login needed' in 'list-accounts' and automatically re-register in 'login-external'
- Add CLI tests for re-registration detection and flow in LoginExternalOptionsTests

* docs: document automatic registration recovery and rate limiting guidance

- Clarify distinction between device-registration throttling and volume rate limits
- Document automatic settings migration and re-registration flow across GUI and CLI
- Advise using Daily Download Limit when bulk re-downloading after scanning for higher quality audio
- Remove obsolete manual account deletion and JSON editing instructions

* feat(ui): automatically enable Widevine and re-register accounts when upgrading book quality

When upgrading audio quality via 'Scan Audible for Higher Quality Audio',
marking books for re-download previously left Widevine disabled and accounts
under legacy registrations, causing subsequent downloads to re-acquire the
existing lower-quality AAC-LC stream.

- Update FindBetterQualityBooksViewModel.MarkBooksAsync() to return a
  MarkBooksResult and automatically enable Widevine and Request xHE-AAC
  when higher-quality streams are selected.
- Thunk accounts to CurrentAndroid and mark them for re-registration via
  ThrottledDeviceRecovery so that Widevine-protected and higher-quality
  codecs can be licensed without manual troubleshooting.
- Alert user in Avalonia and WinForms dialogs when settings and
  registrations have been automatically upgraded.
- Fix broken sentence and note daily download limits and rate limiting in
  FindBetterQualityBooksViewModel.InitialMessage.
- Add unit tests in FindBetterQualityBooksViewModelTests covering clean and
  upgraded re-registration paths.

* feat(accounts): add 'Signed in?' checkbox to mark accounts for re-registration on save

* docs & fix(recovery): modernize license recovery guidance and document 'Signed in?'

* feat(recovery): automatically enable Widevine and thunk account when ADRM fails (#2083)

- Detects missing ADRM asset (Sable 000307 acr:null) and missing AAX fallback codecs in titles that only deliver via Widevine.
- Instead of merely advising the user to change settings manually, automatically applies recovery via ThrottledDeviceRecovery.ApplyRecovery (sets UseWidevine = true, CurrentAndroid, and marks the account for re-registration).
- Modernizes user-facing dialogs, process queue status, and CLI feedback to explain that Widevine DRM was enabled and a fresh login is required.
2026-11-12 09:54:23 -07:00

76 lines
4.4 KiB
C#

using ApplicationServices;
using LibationFileManager;
using System;
namespace LibationUiBase;
/// <summary>
/// User-facing copy when Audible denies a content license (download/decrypt). Covers temporary
/// service issues, explicit CustomerThrottled refusals, and Audible Plus denials — often mistaken
/// for a Libation bug. Shared by WinForms and Avalonia via the process queue.
/// </summary>
public static class ContentLicenseDeniedUserMessage
{
public const string DialogCaption = "Content license denied";
/// <summary>Generic outage / GenericError-style denial: not specific to Plus titles.</summary>
public static string BuildDialogBodyForPossibleOutage(string bookTitleWithSubtitle, AudibleApi.Locale? locale = null,
AppScaffolding.VersionCheckOutcome updateStatus = AppScaffolding.VersionCheckOutcome.UnableToDetermine, bool hasAdditionalMarketplaces = false)
=> BuildBody(bookTitleWithSubtitle,
"This may be a temporary interruption of service. If Audible's app can play the title, try these registration recovery steps.", locale, updateStatus, hasAdditionalMarketplaces);
/// <summary>Audible named CustomerThrottled. Shown for any title, Plus or owned.</summary>
public static string BuildDialogBodyForThrottling(string bookTitleWithSubtitle, AudibleApi.Locale? locale = null,
AppScaffolding.VersionCheckOutcome updateStatus = AppScaffolding.VersionCheckOutcome.UnableToDetermine, bool hasAdditionalMarketplaces = false)
=> BuildBody(bookTitleWithSubtitle,
"Audible says this account is being throttled. This can also happen with an old device registration. Try these recovery steps first.", locale, updateStatus, hasAdditionalMarketplaces);
/// <summary>Audible throttled on legacy or non-Widevine registration; settings updated and account marked for re-registration.</summary>
public static string BuildDialogBodyForThrottlingRecovered(string bookTitleWithSubtitle)
=> $"You were denied a content license for {bookTitleWithSubtitle}\n\n"
+ "Audible reported throttling on your account's legacy device registration.\n\n"
+ "Libation has automatically updated your settings to Android emulator and Widevine DRM, and marked your account for a fresh sign-in.\n\n"
+ "No accounts need to be deleted. Next time you Scan or Liberate, you will be prompted to sign in once to establish the new device registration.";
/// <summary>Plus denials may indicate registration trouble, rate limits, or lost access.</summary>
public static string BuildDialogBodyForPlusCatalog(string bookTitleWithSubtitle, AudibleApi.Locale? locale = null,
AppScaffolding.VersionCheckOutcome updateStatus = AppScaffolding.VersionCheckOutcome.UnableToDetermine, bool hasAdditionalMarketplaces = false)
=> BuildBody(bookTitleWithSubtitle,
"This title is from the Audible Plus catalog. It may have left Plus, or Audible may be limiting downloads. Check your access in Audible's app; if it plays, try these recovery steps.", locale, updateStatus, hasAdditionalMarketplaces);
private static string BuildBody(string title, string diagnosis, AudibleApi.Locale? locale, AppScaffolding.VersionCheckOutcome updateStatus, bool hasAdditionalMarketplaces)
=> $"You were denied a content license for {title}\n\n{diagnosis}\n\n"
+ AppScaffolding.LicenseRecoveryGuidance.Explanation + "\n\n"
+ AppScaffolding.LicenseRecoveryGuidance.BuildSteps(locale, updateStatus, hasAdditionalMarketplaces: hasAdditionalMarketplaces) + "\n\n"
+ AppScaffolding.LicenseRecoveryGuidance.Fallback + AppendSuggestion();
/// <summary>
/// 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.
/// </summary>
private static string AppendSuggestion()
{
try
{
var now = DateTimeOffset.Now;
var suggestion = DailyDownloadLimitUserMessage.BuildSuggestionParagraph(
Configuration.Instance,
DownloadHistoryStore.GetCurrentWindow(now),
now);
if (suggestion is null)
return string.Empty;
Serilog.Log.Logger.Information("Suggesting a daily download limit after a license denial. {Suggestion}", suggestion);
return Environment.NewLine + Environment.NewLine + suggestion;
}
catch (Exception ex)
{
Serilog.Log.Logger.Error(ex, "Failed to build the daily download limit suggestion");
return string.Empty;
}
}
}