Add option to strip Audible brand audio

This commit is contained in:
Michael Bucari-Tovo 2022-05-07 21:29:29 -06:00
parent d595b62f13
commit 9862593f4a
7 changed files with 557 additions and 514 deletions

View File

@ -5,8 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AAXClean" Version="0.4.2" />
<PackageReference Include="AAXClean.Codecs" Version="0.2.0" />
<PackageReference Include="AAXClean" Version="0.4.4" />
<PackageReference Include="AAXClean.Codecs" Version="0.2.4" />
</ItemGroup>
<ItemGroup>

View File

@ -36,8 +36,8 @@ namespace AaxDecrypter
AaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate;
var decryptionResult
= OutputFormat == OutputFormat.M4b
? AaxFile.ConvertToMp4a(outputFile, DownloadLicense.ChapterInfo)
: AaxFile.ConvertToMp3(outputFile);
? AaxFile.ConvertToMp4a(outputFile, DownloadLicense.ChapterInfo, DownloadLicense.TrimOutputToChapterLength)
: AaxFile.ConvertToMp3(outputFile, null, DownloadLicense.ChapterInfo, DownloadLicense.TrimOutputToChapterLength);
AaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;
DownloadLicense.ChapterInfo = AaxFile.Chapters;

View File

@ -10,6 +10,7 @@ namespace AaxDecrypter
public string AudibleIV { get; }
public string UserAgent { get; }
public ChapterInfo ChapterInfo { get; set; }
public bool TrimOutputToChapterLength { get; set; }
public DownloadLicense(string downloadUrl, string audibleKey, string audibleIV, string userAgent)
{

View File

@ -86,6 +86,8 @@ namespace FileLiberator
try
{
var config = Configuration.Instance;
downloadValidation(libraryBook);
var api = await libraryBook.GetApiAsync();
@ -104,15 +106,32 @@ namespace FileLiberator
//These assumptions may be wrong, and only time and bug reports will tell.
var outputFormat =
contentLic.ContentMetadata.ContentReference.ContentFormat == "MPEG" ||
(Configuration.Instance.AllowLibationFixup && Configuration.Instance.DecryptToLossy) ?
(config.AllowLibationFixup && config.DecryptToLossy) ?
OutputFormat.Mp3 : OutputFormat.M4b;
if (Configuration.Instance.AllowLibationFixup || outputFormat == OutputFormat.Mp3)
{
audiobookDlLic.ChapterInfo = new AAXClean.ChapterInfo();
audiobookDlLic.TrimOutputToChapterLength = config.StripAudibleBrandAudio;
foreach (var chap in contentLic.ContentMetadata?.ChapterInfo?.Chapters)
audiobookDlLic.ChapterInfo.AddChapter(chap.Title, TimeSpan.FromMilliseconds(chap.LengthMs));
long startMs = config.StripAudibleBrandAudio ?
contentLic.ContentMetadata.ChapterInfo.BrandIntroDurationMs :
0;
if (config.AllowLibationFixup || outputFormat == OutputFormat.Mp3)
{
audiobookDlLic.ChapterInfo = new AAXClean.ChapterInfo(TimeSpan.FromMilliseconds(startMs));
for (int i = 0; i < contentLic.ContentMetadata.ChapterInfo.Chapters.Length; i++)
{
var chapter = contentLic.ContentMetadata.ChapterInfo.Chapters[i];
long chapLenMs = chapter.LengthMs;
if (i == 0)
chapLenMs -= startMs;
if (config.StripAudibleBrandAudio && i == contentLic.ContentMetadata.ChapterInfo.Chapters.Length - 1)
chapLenMs -= contentLic.ContentMetadata.ChapterInfo.BrandOutroDurationMs + 500; //A little more headroom at the end of the file (500 ms)
audiobookDlLic.ChapterInfo.AddChapter(chapter.Title, TimeSpan.FromMilliseconds(chapLenMs));
}
}
var outFileName = AudibleFileStorage.Audio.GetInProgressFilename(libraryBook, outputFormat.ToString().ToLower());
@ -124,12 +143,12 @@ namespace FileLiberator
else
{
AaxcDownloadConvertBase converter
= Configuration.Instance.SplitFilesByChapter ? new AaxcDownloadMultiConverter(
= config.SplitFilesByChapter ? new AaxcDownloadMultiConverter(
outFileName, cacheDir, audiobookDlLic, outputFormat,
AudibleFileStorage.Audio.CreateMultipartRenamerFunc(libraryBook))
: new AaxcDownloadSingleConverter(outFileName, cacheDir, audiobookDlLic, outputFormat);
if (Configuration.Instance.AllowLibationFixup)
if (config.AllowLibationFixup)
converter.RetrievedMetadata += (_, tags) => tags.Generes = string.Join(", ", libraryBook.Book.CategoriesNames);
abDownloader = converter;

View File

@ -96,6 +96,13 @@ namespace LibationFileManager
set => persistentDictionary.SetNonString(nameof(AllowLibationFixup), value);
}
[Description("Allow Libation to remove audible branding from the start\r\nand end of audiobooks. (e.g. \"This is Audible\")")]
public bool StripAudibleBrandAudio
{
get => persistentDictionary.GetNonString<bool>(nameof(StripAudibleBrandAudio));
set => persistentDictionary.SetNonString(nameof(StripAudibleBrandAudio), value);
}
[Description("Decrypt to lossy format?")]
public bool DecryptToLossy
{

View File

@ -40,6 +40,7 @@
this.badBookAbortRb = new System.Windows.Forms.RadioButton();
this.badBookAskRb = new System.Windows.Forms.RadioButton();
this.decryptAndConvertGb = new System.Windows.Forms.GroupBox();
this.stripAudibleBrandingCbox = new System.Windows.Forms.CheckBox();
this.splitFilesByChapterCbox = new System.Windows.Forms.CheckBox();
this.allowLibationFixupCbox = new System.Windows.Forms.CheckBox();
this.convertLossyRb = new System.Windows.Forms.RadioButton();
@ -53,6 +54,7 @@
this.tab1ImportantSettings = new System.Windows.Forms.TabPage();
this.booksGb = new System.Windows.Forms.GroupBox();
this.tab2ImportLibrary = new System.Windows.Forms.TabPage();
this.showImportedStatsCb = new System.Windows.Forms.CheckBox();
this.tab3DownloadDecrypt = new System.Windows.Forms.TabPage();
this.inProgressFilesGb = new System.Windows.Forms.GroupBox();
this.customFileNamingGb = new System.Windows.Forms.GroupBox();
@ -65,7 +67,6 @@
this.folderTemplateBtn = new System.Windows.Forms.Button();
this.folderTemplateTb = new System.Windows.Forms.TextBox();
this.folderTemplateLbl = new System.Windows.Forms.Label();
this.showImportedStatsCb = new System.Windows.Forms.CheckBox();
this.badBookGb.SuspendLayout();
this.decryptAndConvertGb.SuspendLayout();
this.tabControl.SuspendLayout();
@ -100,7 +101,7 @@
// saveBtn
//
this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.saveBtn.Location = new System.Drawing.Point(714, 496);
this.saveBtn.Location = new System.Drawing.Point(714, 523);
this.saveBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.saveBtn.Name = "saveBtn";
this.saveBtn.Size = new System.Drawing.Size(88, 27);
@ -113,7 +114,7 @@
//
this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelBtn.Location = new System.Drawing.Point(832, 496);
this.cancelBtn.Location = new System.Drawing.Point(832, 523);
this.cancelBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.cancelBtn.Name = "cancelBtn";
this.cancelBtn.Size = new System.Drawing.Size(88, 27);
@ -150,7 +151,7 @@
this.badBookGb.Controls.Add(this.badBookAskRb);
this.badBookGb.Location = new System.Drawing.Point(371, 6);
this.badBookGb.Name = "badBookGb";
this.badBookGb.Size = new System.Drawing.Size(524, 124);
this.badBookGb.Size = new System.Drawing.Size(524, 168);
this.badBookGb.TabIndex = 13;
this.badBookGb.TabStop = false;
this.badBookGb.Text = "[bad book desc]";
@ -158,7 +159,7 @@
// badBookIgnoreRb
//
this.badBookIgnoreRb.AutoSize = true;
this.badBookIgnoreRb.Location = new System.Drawing.Point(6, 97);
this.badBookIgnoreRb.Location = new System.Drawing.Point(6, 124);
this.badBookIgnoreRb.Name = "badBookIgnoreRb";
this.badBookIgnoreRb.Size = new System.Drawing.Size(94, 19);
this.badBookIgnoreRb.TabIndex = 17;
@ -169,7 +170,7 @@
// badBookRetryRb
//
this.badBookRetryRb.AutoSize = true;
this.badBookRetryRb.Location = new System.Drawing.Point(6, 72);
this.badBookRetryRb.Location = new System.Drawing.Point(6, 90);
this.badBookRetryRb.Name = "badBookRetryRb";
this.badBookRetryRb.Size = new System.Drawing.Size(84, 19);
this.badBookRetryRb.TabIndex = 16;
@ -180,7 +181,7 @@
// badBookAbortRb
//
this.badBookAbortRb.AutoSize = true;
this.badBookAbortRb.Location = new System.Drawing.Point(6, 47);
this.badBookAbortRb.Location = new System.Drawing.Point(6, 56);
this.badBookAbortRb.Name = "badBookAbortRb";
this.badBookAbortRb.Size = new System.Drawing.Size(88, 19);
this.badBookAbortRb.TabIndex = 15;
@ -201,21 +202,32 @@
//
// decryptAndConvertGb
//
this.decryptAndConvertGb.Controls.Add(this.stripAudibleBrandingCbox);
this.decryptAndConvertGb.Controls.Add(this.splitFilesByChapterCbox);
this.decryptAndConvertGb.Controls.Add(this.allowLibationFixupCbox);
this.decryptAndConvertGb.Controls.Add(this.convertLossyRb);
this.decryptAndConvertGb.Controls.Add(this.convertLosslessRb);
this.decryptAndConvertGb.Location = new System.Drawing.Point(6, 6);
this.decryptAndConvertGb.Name = "decryptAndConvertGb";
this.decryptAndConvertGb.Size = new System.Drawing.Size(359, 124);
this.decryptAndConvertGb.Size = new System.Drawing.Size(359, 168);
this.decryptAndConvertGb.TabIndex = 9;
this.decryptAndConvertGb.TabStop = false;
this.decryptAndConvertGb.Text = "Decrypt and convert";
//
// stripAudibleBrandingCbox
//
this.stripAudibleBrandingCbox.AutoSize = true;
this.stripAudibleBrandingCbox.Location = new System.Drawing.Point(6, 72);
this.stripAudibleBrandingCbox.Name = "stripAudibleBrandingCbox";
this.stripAudibleBrandingCbox.Size = new System.Drawing.Size(174, 19);
this.stripAudibleBrandingCbox.TabIndex = 13;
this.stripAudibleBrandingCbox.Text = "[StripAudibleBranding desc]";
this.stripAudibleBrandingCbox.UseVisualStyleBackColor = true;
//
// splitFilesByChapterCbox
//
this.splitFilesByChapterCbox.AutoSize = true;
this.splitFilesByChapterCbox.Location = new System.Drawing.Point(6, 46);
this.splitFilesByChapterCbox.Location = new System.Drawing.Point(6, 48);
this.splitFilesByChapterCbox.Name = "splitFilesByChapterCbox";
this.splitFilesByChapterCbox.Size = new System.Drawing.Size(162, 19);
this.splitFilesByChapterCbox.TabIndex = 13;
@ -227,7 +239,7 @@
this.allowLibationFixupCbox.AutoSize = true;
this.allowLibationFixupCbox.Checked = true;
this.allowLibationFixupCbox.CheckState = System.Windows.Forms.CheckState.Checked;
this.allowLibationFixupCbox.Location = new System.Drawing.Point(6, 22);
this.allowLibationFixupCbox.Location = new System.Drawing.Point(6, 23);
this.allowLibationFixupCbox.Name = "allowLibationFixupCbox";
this.allowLibationFixupCbox.Size = new System.Drawing.Size(163, 19);
this.allowLibationFixupCbox.TabIndex = 10;
@ -238,7 +250,7 @@
// convertLossyRb
//
this.convertLossyRb.AutoSize = true;
this.convertLossyRb.Location = new System.Drawing.Point(6, 101);
this.convertLossyRb.Location = new System.Drawing.Point(6, 143);
this.convertLossyRb.Name = "convertLossyRb";
this.convertLossyRb.Size = new System.Drawing.Size(329, 19);
this.convertLossyRb.TabIndex = 12;
@ -249,7 +261,7 @@
//
this.convertLosslessRb.AutoSize = true;
this.convertLosslessRb.Checked = true;
this.convertLosslessRb.Location = new System.Drawing.Point(6, 76);
this.convertLosslessRb.Location = new System.Drawing.Point(6, 118);
this.convertLosslessRb.Name = "convertLosslessRb";
this.convertLosslessRb.Size = new System.Drawing.Size(335, 19);
this.convertLosslessRb.TabIndex = 11;
@ -316,7 +328,7 @@
this.tabControl.Location = new System.Drawing.Point(12, 12);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
this.tabControl.Size = new System.Drawing.Size(909, 478);
this.tabControl.Size = new System.Drawing.Size(909, 505);
this.tabControl.TabIndex = 100;
//
// tab1ImportantSettings
@ -328,7 +340,7 @@
this.tab1ImportantSettings.Location = new System.Drawing.Point(4, 24);
this.tab1ImportantSettings.Name = "tab1ImportantSettings";
this.tab1ImportantSettings.Padding = new System.Windows.Forms.Padding(3);
this.tab1ImportantSettings.Size = new System.Drawing.Size(901, 450);
this.tab1ImportantSettings.Size = new System.Drawing.Size(901, 459);
this.tab1ImportantSettings.TabIndex = 0;
this.tab1ImportantSettings.Text = "Important settings";
this.tab1ImportantSettings.UseVisualStyleBackColor = true;
@ -354,11 +366,21 @@
this.tab2ImportLibrary.Location = new System.Drawing.Point(4, 24);
this.tab2ImportLibrary.Name = "tab2ImportLibrary";
this.tab2ImportLibrary.Padding = new System.Windows.Forms.Padding(3);
this.tab2ImportLibrary.Size = new System.Drawing.Size(901, 450);
this.tab2ImportLibrary.Size = new System.Drawing.Size(901, 459);
this.tab2ImportLibrary.TabIndex = 1;
this.tab2ImportLibrary.Text = "Import library";
this.tab2ImportLibrary.UseVisualStyleBackColor = true;
//
// showImportedStatsCb
//
this.showImportedStatsCb.AutoSize = true;
this.showImportedStatsCb.Location = new System.Drawing.Point(6, 6);
this.showImportedStatsCb.Name = "showImportedStatsCb";
this.showImportedStatsCb.Size = new System.Drawing.Size(168, 19);
this.showImportedStatsCb.TabIndex = 1;
this.showImportedStatsCb.Text = "[show imported stats desc]";
this.showImportedStatsCb.UseVisualStyleBackColor = true;
//
// tab3DownloadDecrypt
//
this.tab3DownloadDecrypt.Controls.Add(this.inProgressFilesGb);
@ -368,7 +390,7 @@
this.tab3DownloadDecrypt.Location = new System.Drawing.Point(4, 24);
this.tab3DownloadDecrypt.Name = "tab3DownloadDecrypt";
this.tab3DownloadDecrypt.Padding = new System.Windows.Forms.Padding(3);
this.tab3DownloadDecrypt.Size = new System.Drawing.Size(901, 450);
this.tab3DownloadDecrypt.Size = new System.Drawing.Size(901, 477);
this.tab3DownloadDecrypt.TabIndex = 2;
this.tab3DownloadDecrypt.Text = "Download/Decrypt";
this.tab3DownloadDecrypt.UseVisualStyleBackColor = true;
@ -379,7 +401,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.inProgressFilesGb.Controls.Add(this.inProgressDescLbl);
this.inProgressFilesGb.Controls.Add(this.inProgressSelectControl);
this.inProgressFilesGb.Location = new System.Drawing.Point(7, 299);
this.inProgressFilesGb.Location = new System.Drawing.Point(7, 343);
this.inProgressFilesGb.Name = "inProgressFilesGb";
this.inProgressFilesGb.Size = new System.Drawing.Size(888, 128);
this.inProgressFilesGb.TabIndex = 21;
@ -399,7 +421,7 @@
this.customFileNamingGb.Controls.Add(this.folderTemplateBtn);
this.customFileNamingGb.Controls.Add(this.folderTemplateTb);
this.customFileNamingGb.Controls.Add(this.folderTemplateLbl);
this.customFileNamingGb.Location = new System.Drawing.Point(7, 136);
this.customFileNamingGb.Location = new System.Drawing.Point(7, 180);
this.customFileNamingGb.Name = "customFileNamingGb";
this.customFileNamingGb.Size = new System.Drawing.Size(888, 157);
this.customFileNamingGb.TabIndex = 20;
@ -496,23 +518,13 @@
this.folderTemplateLbl.TabIndex = 0;
this.folderTemplateLbl.Text = "[folder template desc]";
//
// showImportedStatsCb
//
this.showImportedStatsCb.AutoSize = true;
this.showImportedStatsCb.Location = new System.Drawing.Point(6, 6);
this.showImportedStatsCb.Name = "showImportedStatsCb";
this.showImportedStatsCb.Size = new System.Drawing.Size(168, 19);
this.showImportedStatsCb.TabIndex = 1;
this.showImportedStatsCb.Text = "[show imported stats desc]";
this.showImportedStatsCb.UseVisualStyleBackColor = true;
//
// SettingsDialog
//
this.AcceptButton = this.saveBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelBtn;
this.ClientSize = new System.Drawing.Size(933, 539);
this.ClientSize = new System.Drawing.Size(933, 566);
this.Controls.Add(this.tabControl);
this.Controls.Add(this.cancelBtn);
this.Controls.Add(this.saveBtn);
@ -581,5 +593,6 @@
private System.Windows.Forms.TextBox folderTemplateTb;
private System.Windows.Forms.Label folderTemplateLbl;
private System.Windows.Forms.CheckBox showImportedStatsCb;
private System.Windows.Forms.CheckBox stripAudibleBrandingCbox;
}
}

View File

@ -34,6 +34,7 @@ namespace LibationWinForms.Dialogs
this.inProgressDescLbl.Text = desc(nameof(config.InProgress));
this.allowLibationFixupCbox.Text = desc(nameof(config.AllowLibationFixup));
this.splitFilesByChapterCbox.Text = desc(nameof(config.SplitFilesByChapter));
this.stripAudibleBrandingCbox.Text = desc(nameof(config.StripAudibleBrandAudio));
booksSelectControl.SetSearchTitle("books location");
booksSelectControl.SetDirectoryItems(
@ -54,6 +55,7 @@ namespace LibationWinForms.Dialogs
convertLosslessRb.Checked = !config.DecryptToLossy;
convertLossyRb.Checked = config.DecryptToLossy;
splitFilesByChapterCbox.Checked = config.SplitFilesByChapter;
stripAudibleBrandingCbox.Checked = config.StripAudibleBrandAudio;
allowLibationFixupCbox_CheckedChanged(this, e);
@ -174,6 +176,7 @@ namespace LibationWinForms.Dialogs
config.AllowLibationFixup = allowLibationFixupCbox.Checked;
config.DecryptToLossy = convertLossyRb.Checked;
config.SplitFilesByChapter = splitFilesByChapterCbox.Checked;
config.StripAudibleBrandAudio = stripAudibleBrandingCbox.Checked;
config.InProgress = inProgressSelectControl.SelectedDirectory;