Merge pull request #56 from Mbucari/master
Added MP3 support to settings.
This commit is contained in:
commit
730484c28c
@ -8,6 +8,11 @@ using System.IO;
|
|||||||
|
|
||||||
namespace AaxDecrypter
|
namespace AaxDecrypter
|
||||||
{
|
{
|
||||||
|
public enum OutputFormat
|
||||||
|
{
|
||||||
|
Mp4a,
|
||||||
|
Mp3
|
||||||
|
}
|
||||||
public class AaxcDownloadConverter
|
public class AaxcDownloadConverter
|
||||||
{
|
{
|
||||||
public event EventHandler<AppleTags> RetrievedTags;
|
public event EventHandler<AppleTags> RetrievedTags;
|
||||||
@ -21,6 +26,7 @@ namespace AaxDecrypter
|
|||||||
private DownloadLicense downloadLicense { get; }
|
private DownloadLicense downloadLicense { get; }
|
||||||
private AaxFile aaxFile;
|
private AaxFile aaxFile;
|
||||||
private byte[] coverArt;
|
private byte[] coverArt;
|
||||||
|
private OutputFormat OutputFormat;
|
||||||
|
|
||||||
private StepSequence steps { get; }
|
private StepSequence steps { get; }
|
||||||
private NetworkFileStreamPersister nfsPersister;
|
private NetworkFileStreamPersister nfsPersister;
|
||||||
@ -28,10 +34,10 @@ namespace AaxDecrypter
|
|||||||
private string jsonDownloadState => Path.Combine(cacheDir, Path.GetFileNameWithoutExtension(OutputFileName) + ".json");
|
private string jsonDownloadState => Path.Combine(cacheDir, Path.GetFileNameWithoutExtension(OutputFileName) + ".json");
|
||||||
private string tempFile => PathLib.ReplaceExtension(jsonDownloadState, ".aaxc");
|
private string tempFile => PathLib.ReplaceExtension(jsonDownloadState, ".aaxc");
|
||||||
|
|
||||||
public AaxcDownloadConverter(string outFileName, string cacheDirectory, DownloadLicense dlLic)
|
public AaxcDownloadConverter(string outFileName, string cacheDirectory, DownloadLicense dlLic, OutputFormat outputFormat)
|
||||||
{
|
{
|
||||||
ArgumentValidator.EnsureNotNullOrWhiteSpace(outFileName, nameof(outFileName));
|
ArgumentValidator.EnsureNotNullOrWhiteSpace(outFileName, nameof(outFileName));
|
||||||
OutputFileName = PathLib.ReplaceExtension(outFileName, ".m4b");
|
OutputFileName = outFileName;
|
||||||
var outDir = Path.GetDirectoryName(OutputFileName);
|
var outDir = Path.GetDirectoryName(OutputFileName);
|
||||||
if (!Directory.Exists(outDir))
|
if (!Directory.Exists(outDir))
|
||||||
throw new ArgumentNullException(nameof(outDir), "Directory does not exist");
|
throw new ArgumentNullException(nameof(outDir), "Directory does not exist");
|
||||||
@ -43,10 +49,11 @@ namespace AaxDecrypter
|
|||||||
cacheDir = cacheDirectory;
|
cacheDir = cacheDirectory;
|
||||||
|
|
||||||
downloadLicense = ArgumentValidator.EnsureNotNull(dlLic, nameof(dlLic));
|
downloadLicense = ArgumentValidator.EnsureNotNull(dlLic, nameof(dlLic));
|
||||||
|
OutputFormat = outputFormat;
|
||||||
|
|
||||||
steps = new StepSequence
|
steps = new StepSequence
|
||||||
{
|
{
|
||||||
Name = "Download and Convert Aaxc To M4b",
|
Name = "Download and Convert Aaxc To " + (outputFormat == OutputFormat.Mp4a ? "M4b" : "Mp3"),
|
||||||
|
|
||||||
["Step 1: Get Aaxc Metadata"] = Step1_GetMetadata,
|
["Step 1: Get Aaxc Metadata"] = Step1_GetMetadata,
|
||||||
["Step 2: Download Decrypted Audiobook"] = Step2_DownloadAndCombine,
|
["Step 2: Download Decrypted Audiobook"] = Step2_DownloadAndCombine,
|
||||||
@ -125,7 +132,6 @@ namespace AaxDecrypter
|
|||||||
|
|
||||||
public bool Step2_DownloadAndCombine()
|
public bool Step2_DownloadAndCombine()
|
||||||
{
|
{
|
||||||
OutputFormat format = OutputFormat.Mp4a;
|
|
||||||
|
|
||||||
DecryptProgressUpdate?.Invoke(this, 0);
|
DecryptProgressUpdate?.Invoke(this, 0);
|
||||||
|
|
||||||
@ -134,15 +140,20 @@ namespace AaxDecrypter
|
|||||||
|
|
||||||
FileStream outFile = File.OpenWrite(OutputFileName);
|
FileStream outFile = File.OpenWrite(OutputFileName);
|
||||||
|
|
||||||
|
aaxFile.SetDecryptionKey(downloadLicense.AudibleKey, downloadLicense.AudibleIV);
|
||||||
|
|
||||||
aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate;
|
aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate;
|
||||||
var decryptionResult = aaxFile.DecryptAaxc(outFile, downloadLicense.AudibleKey, downloadLicense.AudibleIV, format, downloadLicense.ChapterInfo);
|
|
||||||
|
var decryptionResult = OutputFormat == OutputFormat.Mp4a ? aaxFile.ConvertToMp4a(outFile, downloadLicense.ChapterInfo) : aaxFile.ConvertToMp3(outFile);
|
||||||
aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;
|
aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;
|
||||||
|
|
||||||
|
aaxFile.Close();
|
||||||
|
|
||||||
downloadLicense.ChapterInfo = aaxFile.Chapters;
|
downloadLicense.ChapterInfo = aaxFile.Chapters;
|
||||||
|
|
||||||
if (decryptionResult == ConversionResult.NoErrorsDetected
|
if (decryptionResult == ConversionResult.NoErrorsDetected
|
||||||
&& coverArt is not null
|
&& coverArt is not null
|
||||||
&& format == OutputFormat.Mp4a)
|
&& OutputFormat == OutputFormat.Mp4a)
|
||||||
{
|
{
|
||||||
//This handles a special case where the aaxc file doesn't contain cover art and
|
//This handles a special case where the aaxc file doesn't contain cover art and
|
||||||
//Libation downloaded it instead (Animal Farm). Currently only works for Mp4a files.
|
//Libation downloaded it instead (Animal Farm). Currently only works for Mp4a files.
|
||||||
|
|||||||
@ -87,8 +87,20 @@ namespace FileLiberator
|
|||||||
aaxcDecryptDlLic.ChapterInfo.AddChapter(chap.Title, TimeSpan.FromMilliseconds(chap.LengthMs));
|
aaxcDecryptDlLic.ChapterInfo.AddChapter(chap.Title, TimeSpan.FromMilliseconds(chap.LengthMs));
|
||||||
}
|
}
|
||||||
|
|
||||||
var proposedOutputFile = Path.Combine(destinationDir, $"{PathLib.ToPathSafeString(libraryBook.Book.Title)} [{libraryBook.Book.AudibleProductId}].m4b");
|
|
||||||
aaxcDownloader = new AaxcDownloadConverter(proposedOutputFile, cacheDir, aaxcDecryptDlLic) { AppName = "Libation" };
|
var format = Configuration.Instance.DecryptToLossy ? OutputFormat.Mp3 : OutputFormat.Mp4a;
|
||||||
|
|
||||||
|
var extension = format switch
|
||||||
|
{
|
||||||
|
OutputFormat.Mp4a => "m4b",
|
||||||
|
OutputFormat.Mp3 => "mp3",
|
||||||
|
_ => throw new NotImplementedException(),
|
||||||
|
};
|
||||||
|
|
||||||
|
var proposedOutputFile = Path.Combine(destinationDir, $"{PathLib.ToPathSafeString(libraryBook.Book.Title)} [{libraryBook.Book.AudibleProductId}].{extension}");
|
||||||
|
|
||||||
|
|
||||||
|
aaxcDownloader = new AaxcDownloadConverter(proposedOutputFile, cacheDir, aaxcDecryptDlLic, format) { AppName = "Libation" };
|
||||||
aaxcDownloader.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress);
|
aaxcDownloader.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress);
|
||||||
aaxcDownloader.DecryptTimeRemaining += (s, remaining) => UpdateRemainingTime?.Invoke(this, remaining);
|
aaxcDownloader.DecryptTimeRemaining += (s, remaining) => UpdateRemainingTime?.Invoke(this, remaining);
|
||||||
aaxcDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt;
|
aaxcDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt;
|
||||||
|
|||||||
@ -121,6 +121,13 @@ namespace FileManager
|
|||||||
get => persistentDictionary.Get<bool>(nameof(AllowLibationFixup));
|
get => persistentDictionary.Get<bool>(nameof(AllowLibationFixup));
|
||||||
set => persistentDictionary.Set(nameof(AllowLibationFixup), value);
|
set => persistentDictionary.Set(nameof(AllowLibationFixup), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Description("Decrypt to lossy format?")]
|
||||||
|
public bool DecryptToLossy
|
||||||
|
{
|
||||||
|
get => persistentDictionary.Get<bool>(nameof(DecryptToLossy));
|
||||||
|
set => persistentDictionary.Set(nameof(DecryptToLossy), value);
|
||||||
|
}
|
||||||
// note: any potential file manager static ctors can't compensate if storage dir is changed at run time via settings. this is partly bad architecture. but the side effect is desirable. if changing LibationFiles location: restart app
|
// note: any potential file manager static ctors can't compensate if storage dir is changed at run time via settings. this is partly bad architecture. but the side effect is desirable. if changing LibationFiles location: restart app
|
||||||
|
|
||||||
// singleton stuff
|
// singleton stuff
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
|
||||||
<Version>5.1.10.10</Version>
|
<Version>5.1.10.24</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
39
LibationWinForms/Dialogs/SettingsDialog.Designer.cs
generated
39
LibationWinForms/Dialogs/SettingsDialog.Designer.cs
generated
@ -37,6 +37,8 @@
|
|||||||
this.inProgressSelectControl = new LibationWinForms.Dialogs.DirectorySelectControl();
|
this.inProgressSelectControl = new LibationWinForms.Dialogs.DirectorySelectControl();
|
||||||
this.allowLibationFixupCbox = new System.Windows.Forms.CheckBox();
|
this.allowLibationFixupCbox = new System.Windows.Forms.CheckBox();
|
||||||
this.booksSelectControl = new LibationWinForms.Dialogs.DirectoryOrCustomSelectControl();
|
this.booksSelectControl = new LibationWinForms.Dialogs.DirectoryOrCustomSelectControl();
|
||||||
|
this.convertLosslessRb = new System.Windows.Forms.RadioButton();
|
||||||
|
this.convertLossyRb = new System.Windows.Forms.RadioButton();
|
||||||
this.groupBox1.SuspendLayout();
|
this.groupBox1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -73,7 +75,7 @@
|
|||||||
// saveBtn
|
// saveBtn
|
||||||
//
|
//
|
||||||
this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
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, 275);
|
this.saveBtn.Location = new System.Drawing.Point(714, 268);
|
||||||
this.saveBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
this.saveBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.saveBtn.Name = "saveBtn";
|
this.saveBtn.Name = "saveBtn";
|
||||||
this.saveBtn.Size = new System.Drawing.Size(88, 27);
|
this.saveBtn.Size = new System.Drawing.Size(88, 27);
|
||||||
@ -86,7 +88,7 @@
|
|||||||
//
|
//
|
||||||
this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
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.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||||
this.cancelBtn.Location = new System.Drawing.Point(832, 275);
|
this.cancelBtn.Location = new System.Drawing.Point(832, 268);
|
||||||
this.cancelBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
this.cancelBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.cancelBtn.Name = "cancelBtn";
|
this.cancelBtn.Name = "cancelBtn";
|
||||||
this.cancelBtn.Size = new System.Drawing.Size(88, 27);
|
this.cancelBtn.Size = new System.Drawing.Size(88, 27);
|
||||||
@ -97,6 +99,8 @@
|
|||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.convertLossyRb);
|
||||||
|
this.groupBox1.Controls.Add(this.convertLosslessRb);
|
||||||
this.groupBox1.Controls.Add(this.inProgressSelectControl);
|
this.groupBox1.Controls.Add(this.inProgressSelectControl);
|
||||||
this.groupBox1.Controls.Add(this.allowLibationFixupCbox);
|
this.groupBox1.Controls.Add(this.allowLibationFixupCbox);
|
||||||
this.groupBox1.Controls.Add(this.inProgressDescLbl);
|
this.groupBox1.Controls.Add(this.inProgressDescLbl);
|
||||||
@ -104,7 +108,7 @@
|
|||||||
this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.groupBox1.Name = "groupBox1";
|
this.groupBox1.Name = "groupBox1";
|
||||||
this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.groupBox1.Size = new System.Drawing.Size(902, 145);
|
this.groupBox1.Size = new System.Drawing.Size(902, 143);
|
||||||
this.groupBox1.TabIndex = 3;
|
this.groupBox1.TabIndex = 3;
|
||||||
this.groupBox1.TabStop = false;
|
this.groupBox1.TabStop = false;
|
||||||
this.groupBox1.Text = "Advanced settings for control freaks";
|
this.groupBox1.Text = "Advanced settings for control freaks";
|
||||||
@ -127,6 +131,7 @@
|
|||||||
this.allowLibationFixupCbox.TabIndex = 0;
|
this.allowLibationFixupCbox.TabIndex = 0;
|
||||||
this.allowLibationFixupCbox.Text = "Allow Libation to fix up audiobook metadata";
|
this.allowLibationFixupCbox.Text = "Allow Libation to fix up audiobook metadata";
|
||||||
this.allowLibationFixupCbox.UseVisualStyleBackColor = true;
|
this.allowLibationFixupCbox.UseVisualStyleBackColor = true;
|
||||||
|
this.allowLibationFixupCbox.CheckedChanged += new System.EventHandler(this.allowLibationFixupCbox_CheckedChanged);
|
||||||
//
|
//
|
||||||
// booksSelectControl
|
// booksSelectControl
|
||||||
//
|
//
|
||||||
@ -137,13 +142,37 @@
|
|||||||
this.booksSelectControl.Size = new System.Drawing.Size(815, 81);
|
this.booksSelectControl.Size = new System.Drawing.Size(815, 81);
|
||||||
this.booksSelectControl.TabIndex = 1;
|
this.booksSelectControl.TabIndex = 1;
|
||||||
//
|
//
|
||||||
|
// convertLosslessRb
|
||||||
|
//
|
||||||
|
this.convertLosslessRb.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.convertLosslessRb.AutoSize = true;
|
||||||
|
this.convertLosslessRb.Checked = true;
|
||||||
|
this.convertLosslessRb.Location = new System.Drawing.Point(692, 24);
|
||||||
|
this.convertLosslessRb.Name = "convertLosslessRb";
|
||||||
|
this.convertLosslessRb.Size = new System.Drawing.Size(108, 19);
|
||||||
|
this.convertLosslessRb.TabIndex = 0;
|
||||||
|
this.convertLosslessRb.TabStop = true;
|
||||||
|
this.convertLosslessRb.Text = "Mp4a (Lossless)";
|
||||||
|
this.convertLosslessRb.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// convertLossyRb
|
||||||
|
//
|
||||||
|
this.convertLossyRb.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.convertLossyRb.AutoSize = true;
|
||||||
|
this.convertLossyRb.Location = new System.Drawing.Point(806, 24);
|
||||||
|
this.convertLossyRb.Name = "convertLossyRb";
|
||||||
|
this.convertLossyRb.Size = new System.Drawing.Size(89, 19);
|
||||||
|
this.convertLossyRb.TabIndex = 0;
|
||||||
|
this.convertLossyRb.Text = "Mp3 (Lossy)";
|
||||||
|
this.convertLossyRb.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
// SettingsDialog
|
// SettingsDialog
|
||||||
//
|
//
|
||||||
this.AcceptButton = this.saveBtn;
|
this.AcceptButton = this.saveBtn;
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.CancelButton = this.cancelBtn;
|
this.CancelButton = this.cancelBtn;
|
||||||
this.ClientSize = new System.Drawing.Size(933, 316);
|
this.ClientSize = new System.Drawing.Size(933, 309);
|
||||||
this.Controls.Add(this.booksSelectControl);
|
this.Controls.Add(this.booksSelectControl);
|
||||||
this.Controls.Add(this.groupBox1);
|
this.Controls.Add(this.groupBox1);
|
||||||
this.Controls.Add(this.cancelBtn);
|
this.Controls.Add(this.cancelBtn);
|
||||||
@ -173,5 +202,7 @@
|
|||||||
private System.Windows.Forms.CheckBox allowLibationFixupCbox;
|
private System.Windows.Forms.CheckBox allowLibationFixupCbox;
|
||||||
private DirectoryOrCustomSelectControl booksSelectControl;
|
private DirectoryOrCustomSelectControl booksSelectControl;
|
||||||
private DirectorySelectControl inProgressSelectControl;
|
private DirectorySelectControl inProgressSelectControl;
|
||||||
|
private System.Windows.Forms.RadioButton convertLossyRb;
|
||||||
|
private System.Windows.Forms.RadioButton convertLosslessRb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,6 +30,10 @@ namespace LibationWinForms.Dialogs
|
|||||||
booksSelectControl.SelectDirectory(config.Books);
|
booksSelectControl.SelectDirectory(config.Books);
|
||||||
|
|
||||||
allowLibationFixupCbox.Checked = config.AllowLibationFixup;
|
allowLibationFixupCbox.Checked = config.AllowLibationFixup;
|
||||||
|
convertLosslessRb.Checked = !config.DecryptToLossy;
|
||||||
|
convertLossyRb.Checked = config.DecryptToLossy;
|
||||||
|
|
||||||
|
allowLibationFixupCbox_CheckedChanged(this, e);
|
||||||
|
|
||||||
inProgressSelectControl.SetDirectoryItems(new()
|
inProgressSelectControl.SetDirectoryItems(new()
|
||||||
{
|
{
|
||||||
@ -45,6 +49,7 @@ namespace LibationWinForms.Dialogs
|
|||||||
private void saveBtn_Click(object sender, EventArgs e)
|
private void saveBtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
config.AllowLibationFixup = allowLibationFixupCbox.Checked;
|
config.AllowLibationFixup = allowLibationFixupCbox.Checked;
|
||||||
|
config.DecryptToLossy = convertLossyRb.Checked;
|
||||||
|
|
||||||
config.InProgress = inProgressSelectControl.SelectedDirectory;
|
config.InProgress = inProgressSelectControl.SelectedDirectory;
|
||||||
|
|
||||||
@ -66,5 +71,16 @@ namespace LibationWinForms.Dialogs
|
|||||||
this.DialogResult = DialogResult.Cancel;
|
this.DialogResult = DialogResult.Cancel;
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void allowLibationFixupCbox_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
convertLosslessRb.Enabled = allowLibationFixupCbox.Checked;
|
||||||
|
convertLossyRb.Enabled = allowLibationFixupCbox.Checked;
|
||||||
|
|
||||||
|
if (!allowLibationFixupCbox.Checked)
|
||||||
|
{
|
||||||
|
convertLosslessRb.Checked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user