From 5f4551822b5e7674a6cfd9914c808f7a3d76e53a Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 May 2025 12:39:12 -0600 Subject: [PATCH] Remove Book.AudioFormat property This property was set to the highest quality returned by the library scan. Since adding quality option settings, it is no longer guaranteed to reflect the file that is downloaded. Also, the library scan qualities don't contain spatial audio or widevine-specific qualities., only ADRM. --- Source/ApplicationServices/LibraryExporter.cs | 1 - Source/DataLayer/Configurations/BookConfig.cs | 1 - Source/DataLayer/EfClasses/AudioFormat.cs | 65 ------------------- Source/DataLayer/EfClasses/Book.cs | 6 +- Source/DtoImporterService/BookImporter.cs | 3 - .../FileLiberator/DownloadOptions.Factory.cs | 3 - .../Dialogs/BookDetailsDialog.axaml.cs | 1 - .../Dialogs/BookDetailsDialog.cs | 1 - 8 files changed, 3 insertions(+), 78 deletions(-) delete mode 100644 Source/DataLayer/EfClasses/AudioFormat.cs diff --git a/Source/ApplicationServices/LibraryExporter.cs b/Source/ApplicationServices/LibraryExporter.cs index e2373e53..b299c1b2 100644 --- a/Source/ApplicationServices/LibraryExporter.cs +++ b/Source/ApplicationServices/LibraryExporter.cs @@ -152,7 +152,6 @@ namespace ApplicationServices BookStatus = a.Book.UserDefinedItem.BookStatus.ToString(), PdfStatus = a.Book.UserDefinedItem.PdfStatus.ToString(), ContentType = a.Book.ContentType.ToString(), - AudioFormat = a.Book.AudioFormat.ToString(), Language = a.Book.Language, LastDownloaded = a.Book.UserDefinedItem.LastDownloaded, LastDownloadedVersion = a.Book.UserDefinedItem.LastDownloadedVersion?.ToString() ?? "", diff --git a/Source/DataLayer/Configurations/BookConfig.cs b/Source/DataLayer/Configurations/BookConfig.cs index f19e490d..bafa27e6 100644 --- a/Source/DataLayer/Configurations/BookConfig.cs +++ b/Source/DataLayer/Configurations/BookConfig.cs @@ -19,7 +19,6 @@ namespace DataLayer.Configurations // entity.Ignore(nameof(Book.Authors)); entity.Ignore(nameof(Book.Narrators)); - entity.Ignore(nameof(Book.AudioFormat)); entity.Ignore(nameof(Book.TitleWithSubtitle)); entity.Ignore(b => b.Categories); diff --git a/Source/DataLayer/EfClasses/AudioFormat.cs b/Source/DataLayer/EfClasses/AudioFormat.cs deleted file mode 100644 index b0f3374c..00000000 --- a/Source/DataLayer/EfClasses/AudioFormat.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; - -namespace DataLayer -{ - internal enum AudioFormatEnum : long - { - //Defining the enum this way ensures that when comparing: - //LC_128_44100_stereo > LC_64_44100_stereo > LC_64_22050_stereo > LC_64_22050_stereo - //This matches how audible interprets these codecs when specifying quality using AudibleApi.DownloadQuality - //I've never seen mono formats. - Unknown = 0, - LC_32_22050_stereo = (32L << 18) | (22050 << 2) | 2, - LC_64_22050_stereo = (64L << 18) | (22050 << 2) | 2, - LC_64_44100_stereo = (64L << 18) | (44100 << 2) | 2, - LC_128_44100_stereo = (128L << 18) | (44100 << 2) | 2, - AAX_22_32 = LC_32_22050_stereo, - AAX_22_64 = LC_64_22050_stereo, - AAX_44_64 = LC_64_44100_stereo, - AAX_44_128 = LC_128_44100_stereo - } - - public class AudioFormat : IComparable, IComparable - { - internal int AudioFormatID { get; private set; } - public int Bitrate { get; private init; } - public int SampleRate { get; private init; } - public int Channels { get; private init; } - public bool IsValid => Bitrate != 0 && SampleRate != 0 && Channels != 0; - - public static AudioFormat FromString(string formatStr) - { - if (Enum.TryParse(formatStr, ignoreCase: true, out AudioFormatEnum enumVal)) - return FromEnum(enumVal); - return FromEnum(AudioFormatEnum.Unknown); - } - - internal static AudioFormat FromEnum(AudioFormatEnum enumVal) - { - var val = (long)enumVal; - - return new() - { - Bitrate = (int)(val >> 18), - SampleRate = (int)(val >> 2) & ushort.MaxValue, - Channels = (int)(val & 3) - }; - } - internal AudioFormatEnum ToEnum() - { - var val = (AudioFormatEnum)(((long)Bitrate << 18) | ((long)SampleRate << 2) | (long)Channels); - - return Enum.IsDefined(val) ? - val : AudioFormatEnum.Unknown; - } - - public override string ToString() - => IsValid ? - $"{Bitrate} Kbps, {SampleRate / 1000d:F1} kHz, {(Channels == 2 ? "Stereo" : Channels)}" : - "Unknown"; - - public int CompareTo(AudioFormat other) => ToEnum().CompareTo(other.ToEnum()); - - public int CompareTo(object obj) => CompareTo(obj as AudioFormat); - } -} diff --git a/Source/DataLayer/EfClasses/Book.cs b/Source/DataLayer/EfClasses/Book.cs index 21c178fa..05ccd9e6 100644 --- a/Source/DataLayer/EfClasses/Book.cs +++ b/Source/DataLayer/EfClasses/Book.cs @@ -43,9 +43,9 @@ namespace DataLayer public ContentType ContentType { get; private set; } public string Locale { get; private set; } - internal AudioFormatEnum _audioFormat; - - public AudioFormat AudioFormat { get => AudioFormat.FromEnum(_audioFormat); set => _audioFormat = value.ToEnum(); } + //This field is now unused, however, there is little sense in adding a + //database migration to remove an unused field. Leave it for compatibility. + internal long _audioFormat; // mutable public string PictureId { get; set; } diff --git a/Source/DtoImporterService/BookImporter.cs b/Source/DtoImporterService/BookImporter.cs index 92ead237..95c86a64 100644 --- a/Source/DtoImporterService/BookImporter.cs +++ b/Source/DtoImporterService/BookImporter.cs @@ -154,9 +154,6 @@ namespace DtoImporterService // Update the book titles, since formatting can change book.UpdateTitle(item.Title, item.Subtitle); - var codec = item.AvailableCodecs?.Max(f => AudioFormat.FromString(f.EnhancedCodec)) ?? new AudioFormat(); - book.AudioFormat = codec; - // set/update book-specific info which may have changed if (item.PictureId is not null) book.PictureId = item.PictureId; diff --git a/Source/FileLiberator/DownloadOptions.Factory.cs b/Source/FileLiberator/DownloadOptions.Factory.cs index 63db1f4f..6e9d71ac 100644 --- a/Source/FileLiberator/DownloadOptions.Factory.cs +++ b/Source/FileLiberator/DownloadOptions.Factory.cs @@ -157,9 +157,6 @@ public partial class DownloadOptions : contentLic.DrmType is DrmType.Adrm && contentLic.Voucher?.Key.Length == 32 && contentLic.Voucher?.Iv.Length == 32 ? AAXClean.FileType.Aaxc : null; - //Set the requested AudioFormat for use in file naming templates - libraryBook.Book.AudioFormat = AudioFormat.FromString(contentLic.ContentMetadata.ContentReference.ContentFormat); - var dlOptions = new DownloadOptions(config, libraryBook, contentLic.ContentMetadata.ContentUrl?.OfflineUrl) { AudibleKey = contentLic.Voucher?.Key, diff --git a/Source/LibationAvalonia/Dialogs/BookDetailsDialog.axaml.cs b/Source/LibationAvalonia/Dialogs/BookDetailsDialog.axaml.cs index da6f5fbb..fe30623c 100644 --- a/Source/LibationAvalonia/Dialogs/BookDetailsDialog.axaml.cs +++ b/Source/LibationAvalonia/Dialogs/BookDetailsDialog.axaml.cs @@ -114,7 +114,6 @@ Title: {title} Author(s): {Book.AuthorNames()} Narrator(s): {Book.NarratorNames()} Length: {(Book.LengthInMinutes == 0 ? "" : $"{Book.LengthInMinutes / 60} hr {Book.LengthInMinutes % 60} min")} -Audio Bitrate: {Book.AudioFormat} Category: {string.Join(", ", Book.LowestCategoryNames())} Purchase Date: {libraryBook.DateAdded:d} Language: {Book.Language} diff --git a/Source/LibationWinForms/Dialogs/BookDetailsDialog.cs b/Source/LibationWinForms/Dialogs/BookDetailsDialog.cs index c534e40b..93d91e8d 100644 --- a/Source/LibationWinForms/Dialogs/BookDetailsDialog.cs +++ b/Source/LibationWinForms/Dialogs/BookDetailsDialog.cs @@ -49,7 +49,6 @@ Title: {title} Author(s): {Book.AuthorNames()} Narrator(s): {Book.NarratorNames()} Length: {(Book.LengthInMinutes == 0 ? "" : $"{Book.LengthInMinutes / 60} hr {Book.LengthInMinutes % 60} min")} -Audio Bitrate: {Book.AudioFormat} Category: {string.Join(", ", Book.LowestCategoryNames())} Purchase Date: {_libraryBook.DateAdded:d} Language: {Book.Language}