using AudibleApi.Common; using System; using System.Linq; namespace AudibleUtilities; public static class Extensions { extension(Item item) { /// /// Determines when your audible plus or free book will expire from your library /// plan.IsAyce from underlying AudibleApi project determines the plans to look at, first plan found is used. /// In some cases current date is later than end date so exclude. /// /// The DateTime that this title will become unavailable, otherwise null public DateTime? GetExpirationDate() => item.Plans ?.Where(p => p.IsAyce) .Select(p => p.EndDate) .FirstOrDefault(end => end.HasValue && end.Value.Year is not (2099 or 9999) && end.Value.LocalDateTime >= DateTime.Now) ?.DateTime; /// /// The book's summary with Audible's HTML markup flattened away, ready to be stored and used /// as-is. See . /// public string PlainTextDescription() => HtmlText.ToPlainText(item.Description); /// /// The publisher's copyright line, e.g. "©2024 Bentley Little (P)2025 Journalstone". /// Only present when the product_details response group was requested, and often null anyway. /// /// is typed as because Audible has /// never been observed returning anything but a string or null there. Anything else is /// discarded rather than stringified, so a shape we do not understand cannot reach a file tag. /// public string? CopyrightString() => item.Copyright is string copyright && !string.IsNullOrWhiteSpace(copyright) ? copyright.Trim() : null; } }