diff --git a/Source/AaxDecrypter/AaxcDownloadConvertBase.cs b/Source/AaxDecrypter/AaxcDownloadConvertBase.cs index e8e0423f..0a879398 100644 --- a/Source/AaxDecrypter/AaxcDownloadConvertBase.cs +++ b/Source/AaxDecrypter/AaxcDownloadConvertBase.cs @@ -81,14 +81,7 @@ namespace AaxDecrypter AaxFile.AppleTags.AppleListBox.EditOrAddFreeformTag(tagDomain, "PART", part.ToString()); } - //Finishing configuring lame encoder. - if (DownloadOptions.OutputFormat == OutputFormat.Mp3) - MpegUtil.ConfigureLameOptions( - AaxFile, - DownloadOptions.LameConfig, - DownloadOptions.Downsample, - DownloadOptions.MatchSourceBitrate); - + OnInitialized(); OnRetrievedTitle(AaxFile.AppleTags.TitleSansUnabridged); OnRetrievedAuthors(AaxFile.AppleTags.FirstAuthor ?? "[unknown]"); OnRetrievedNarrators(AaxFile.AppleTags.Narrator ?? "[unknown]"); @@ -98,5 +91,7 @@ namespace AaxDecrypter return !IsCanceled; } + + protected virtual void OnInitialized() { } } } diff --git a/Source/AaxDecrypter/AaxcDownloadMultiConverter.cs b/Source/AaxDecrypter/AaxcDownloadMultiConverter.cs index 917e42c8..82027ea8 100644 --- a/Source/AaxDecrypter/AaxcDownloadMultiConverter.cs +++ b/Source/AaxDecrypter/AaxcDownloadMultiConverter.cs @@ -21,6 +21,18 @@ namespace AaxDecrypter AsyncSteps["Step 3: Download Clips and Bookmarks"] = Step_DownloadClipsBookmarksAsync; } + protected override void OnInitialized() + { + //Finishing configuring lame encoder. + if (DownloadOptions.OutputFormat == OutputFormat.Mp3) + MpegUtil.ConfigureLameOptions( + AaxFile, + DownloadOptions.LameConfig, + DownloadOptions.Downsample, + DownloadOptions.MatchSourceBitrate, + chapters: null); + } + /* https://github.com/rmcrackan/Libation/pull/127#issuecomment-939088489 diff --git a/Source/AaxDecrypter/AaxcDownloadSingleConverter.cs b/Source/AaxDecrypter/AaxcDownloadSingleConverter.cs index 4a2b60f3..153a6c8d 100644 --- a/Source/AaxDecrypter/AaxcDownloadSingleConverter.cs +++ b/Source/AaxDecrypter/AaxcDownloadSingleConverter.cs @@ -3,7 +3,6 @@ using AAXClean.Codecs; using Dinah.Core.Net.Http; using FileManager; using System; -using System.Diagnostics; using System.IO; using System.Threading.Tasks; @@ -26,6 +25,18 @@ namespace AaxDecrypter AsyncSteps[$"Step {step++}: Create Cue"] = Step_CreateCueAsync; } + protected override void OnInitialized() + { + //Finishing configuring lame encoder. + if (DownloadOptions.OutputFormat == OutputFormat.Mp3) + MpegUtil.ConfigureLameOptions( + AaxFile, + DownloadOptions.LameConfig, + DownloadOptions.Downsample, + DownloadOptions.MatchSourceBitrate, + DownloadOptions.ChapterInfo); + } + protected async override Task Step_DownloadAndDecryptAudiobookAsync() { FileUtility.SaferDelete(OutputFileName); diff --git a/Source/AaxDecrypter/MpegUtil.cs b/Source/AaxDecrypter/MpegUtil.cs index f863e963..84d99925 100644 --- a/Source/AaxDecrypter/MpegUtil.cs +++ b/Source/AaxDecrypter/MpegUtil.cs @@ -8,7 +8,12 @@ namespace AaxDecrypter public static class MpegUtil { private const string TagDomain = "com.pilabor.tone"; - public static void ConfigureLameOptions(Mp4File mp4File, LameConfig lameConfig, bool downsample, bool matchSourceBitrate) + public static void ConfigureLameOptions( + Mp4File mp4File, + LameConfig lameConfig, + bool downsample, + bool matchSourceBitrate, + ChapterInfo chapters) { double bitrateMultiple = 1; @@ -53,6 +58,12 @@ namespace AaxDecrypter if (mp4File.AppleTags.AppleListBox.GetFreeformTagString(TagDomain, "PART") is string part) lameConfig.ID3.UserDefinedText.Add("PART", part); + + if (chapters?.Count > 0) + { + var cue = Cue.CreateContents(lameConfig.ID3.Title + ".mp3", chapters); + lameConfig.ID3.UserDefinedText.Add("CUESHEET", cue); + } } } } diff --git a/Source/FileLiberator/ConvertToMp3.cs b/Source/FileLiberator/ConvertToMp3.cs index ae795c64..a03fb34e 100644 --- a/Source/FileLiberator/ConvertToMp3.cs +++ b/Source/FileLiberator/ConvertToMp3.cs @@ -51,18 +51,19 @@ namespace FileLiberator var config = Configuration.Instance; var lameConfig = GetLameOptions(config); - + var chapters = m4bBook.GetChaptersFromMetadata(); //Finishing configuring lame encoder. AaxDecrypter.MpegUtil.ConfigureLameOptions( m4bBook, lameConfig, config.LameDownsampleMono, - config.LameMatchSourceBR); + config.LameMatchSourceBR, + chapters); - using var mp3File = File.OpenWrite(Path.GetTempFileName()); + using var mp3File = File.Open(Path.GetTempFileName(), FileMode.OpenOrCreate, FileAccess.ReadWrite); try { - Mp4Operation = m4bBook.ConvertToMp3Async(mp3File, lameConfig); + Mp4Operation = m4bBook.ConvertToMp3Async(mp3File, lameConfig, chapters); Mp4Operation.ConversionProgressUpdate += M4bBook_ConversionProgressUpdate; await Mp4Operation; diff --git a/Source/FileLiberator/DownloadDecryptBook.cs b/Source/FileLiberator/DownloadDecryptBook.cs index 9ecc8ae0..cbcf2336 100644 --- a/Source/FileLiberator/DownloadDecryptBook.cs +++ b/Source/FileLiberator/DownloadDecryptBook.cs @@ -160,21 +160,16 @@ namespace FileLiberator { var metadataFile = Templates.File.GetFilename(dlOptions.LibraryBookDto, Path.GetDirectoryName(outFileName), ".metadata.json"); - saveMetadata(libraryBook, contentLic.ContentMetadata, metadataFile); + var item = await api.GetCatalogProductAsync(libraryBook.Book.AudibleProductId, AudibleApi.CatalogOptions.ResponseGroupOptions.ALL_OPTIONS); + item.SourceJson.Add(nameof(ContentMetadata.ChapterInfo), Newtonsoft.Json.Linq.JObject.FromObject(contentLic.ContentMetadata.ChapterInfo)); + item.SourceJson.Add(nameof(ContentMetadata.ContentReference), Newtonsoft.Json.Linq.JObject.FromObject(contentLic.ContentMetadata.ContentReference)); + + File.WriteAllText(metadataFile, item.SourceJson.ToString()); + OnFileCreated(libraryBook, metadataFile); } return success; } - private void saveMetadata(LibraryBook libraryBook, ContentMetadata contentMetadata, string fileName) - { - var export = Newtonsoft.Json.Linq.JObject.FromObject(LibToDtos.ToDtos(new[] { libraryBook })[0]); - export.Add(nameof(contentMetadata.ChapterInfo), Newtonsoft.Json.Linq.JObject.FromObject(contentMetadata.ChapterInfo)); - export.Add(nameof(contentMetadata.ContentReference), Newtonsoft.Json.Linq.JObject.FromObject(contentMetadata.ContentReference)); - - File.WriteAllText(fileName, export.ToString()); - OnFileCreated(libraryBook, fileName); - } - private DownloadOptions BuildDownloadOptions(LibraryBook libraryBook, Configuration config, ContentLicense contentLic) { //If DrmType != Adrm the delivered file is an unencrypted mp3. diff --git a/Source/LibationWinForms/Dialogs/SettingsDialog.Designer.cs b/Source/LibationWinForms/Dialogs/SettingsDialog.Designer.cs index 3ea7e7e7..f2c51a5e 100644 --- a/Source/LibationWinForms/Dialogs/SettingsDialog.Designer.cs +++ b/Source/LibationWinForms/Dialogs/SettingsDialog.Designer.cs @@ -428,9 +428,9 @@ // // applyDisplaySettingsBtn // - applyDisplaySettingsBtn.Location = new System.Drawing.Point(698, 34); + applyDisplaySettingsBtn.Location = new System.Drawing.Point(689, 26); applyDisplaySettingsBtn.Name = "applyDisplaySettingsBtn"; - applyDisplaySettingsBtn.Size = new System.Drawing.Size(140, 23); + applyDisplaySettingsBtn.Size = new System.Drawing.Size(148, 34); applyDisplaySettingsBtn.TabIndex = 9; applyDisplaySettingsBtn.Text = "Apply Display Settings"; applyDisplaySettingsBtn.UseVisualStyleBackColor = true; diff --git a/Source/LibationWinForms/Form1.Designer.cs b/Source/LibationWinForms/Form1.Designer.cs index 8b15fc6e..0c147389 100644 --- a/Source/LibationWinForms/Form1.Designer.cs +++ b/Source/LibationWinForms/Form1.Designer.cs @@ -316,7 +316,7 @@ this.scanningToolStripMenuItem.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; this.scanningToolStripMenuItem.Enabled = false; this.scanningToolStripMenuItem.Image = global::LibationWinForms.Properties.Resources.import_16x16; - this.scanningToolStripMenuItem.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.SizeToFit; + this.scanningToolStripMenuItem.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; this.scanningToolStripMenuItem.Name = "scanningToolStripMenuItem"; this.scanningToolStripMenuItem.Size = new System.Drawing.Size(93, 20); this.scanningToolStripMenuItem.Text = "Scanning...";