diff --git a/Source/AaxDecrypter/AaxDecrypter.csproj b/Source/AaxDecrypter/AaxDecrypter.csproj index 5498c67f..3e8af26e 100644 --- a/Source/AaxDecrypter/AaxDecrypter.csproj +++ b/Source/AaxDecrypter/AaxDecrypter.csproj @@ -13,7 +13,7 @@ - + diff --git a/Source/AaxDecrypter/AaxcDownloadMultiConverter.cs b/Source/AaxDecrypter/AaxcDownloadMultiConverter.cs index 325bdd8c..8b198665 100644 --- a/Source/AaxDecrypter/AaxcDownloadMultiConverter.cs +++ b/Source/AaxDecrypter/AaxcDownloadMultiConverter.cs @@ -140,6 +140,10 @@ That naming may not be desirable for everyone, but it's an easy change to instea aaxConversion.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate; await aaxConversion; + + if (aaxConversion.IsCompletedSuccessfully) + moveMoovToBeginning(workingFileStream?.Name); + return aaxConversion.IsCompletedSuccessfully; } catch(Exception ex) @@ -195,12 +199,26 @@ That naming may not be desirable for everyone, but it's an easy change to instea PartsTotal = splitChapters.Count, Title = newSplitCallback?.Chapter?.Title, }; + + moveMoovToBeginning(workingFileStream?.Name); + newSplitCallback.OutputFile = createOutputFileStream(props); newSplitCallback.TrackTitle = DownloadOptions.GetMultipartTitleName(props); newSplitCallback.TrackNumber = currentChapter; newSplitCallback.TrackCount = splitChapters.Count; } + private void moveMoovToBeginning(string filename) + { + if (DownloadOptions.OutputFormat is OutputFormat.M4b + && DownloadOptions.MoveMoovToBeginning + && filename is not null + && File.Exists(filename)) + { + Mp4File.RelocateMoovAsync(filename).GetAwaiter().GetResult(); + } + } + private FileStream createOutputFileStream(MultiConvertFileProperties multiConvertFileProperties) { var fileName = DownloadOptions.GetMultipartFileName(multiConvertFileProperties); diff --git a/Source/AaxDecrypter/AaxcDownloadSingleConverter.cs b/Source/AaxDecrypter/AaxcDownloadSingleConverter.cs index e41389a6..b0348f7d 100644 --- a/Source/AaxDecrypter/AaxcDownloadSingleConverter.cs +++ b/Source/AaxDecrypter/AaxcDownloadSingleConverter.cs @@ -98,12 +98,21 @@ namespace AaxDecrypter aaxConversion.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate; await aaxConversion; - if (aaxConversion.IsCompletedSuccessfully) + outputFile.Close(); + + if (aaxConversion.IsCompletedSuccessfully + && DownloadOptions.OutputFormat is OutputFormat.M4b + && DownloadOptions.MoveMoovToBeginning) { - outputFile.Close(); - base.OnFileCreated(OutputFileName); + aaxConversion.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate; + aaxConversion = Mp4File.RelocateMoovAsync(OutputFileName); + aaxConversion.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate; + await aaxConversion; } + if (aaxConversion.IsCompletedSuccessfully) + base.OnFileCreated(OutputFileName); + return aaxConversion.IsCompletedSuccessfully; } catch(Exception ex) @@ -117,7 +126,7 @@ namespace AaxDecrypter outputFile.Close(); if (aaxConversion is not null) - aaxConversion.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate; + aaxConversion.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate; Step_DownloadAudiobook_End(zeroProgress); } diff --git a/Source/AaxDecrypter/IDownloadOptions.cs b/Source/AaxDecrypter/IDownloadOptions.cs index 6972f067..f67e2040 100644 --- a/Source/AaxDecrypter/IDownloadOptions.cs +++ b/Source/AaxDecrypter/IDownloadOptions.cs @@ -24,6 +24,7 @@ namespace AaxDecrypter NAudio.Lame.LameConfig LameConfig { get; } bool Downsample { get; } bool MatchSourceBitrate { get; } + bool MoveMoovToBeginning { get; } string GetMultipartFileName(MultiConvertFileProperties props); string GetMultipartTitleName(MultiConvertFileProperties props); Task SaveClipsAndBookmarks(string fileName); diff --git a/Source/FileLiberator/DownloadDecryptBook.cs b/Source/FileLiberator/DownloadDecryptBook.cs index ea430c5d..d0010170 100644 --- a/Source/FileLiberator/DownloadDecryptBook.cs +++ b/Source/FileLiberator/DownloadDecryptBook.cs @@ -160,6 +160,7 @@ namespace FileLiberator AudibleKey = contentLic?.Voucher?.Key, AudibleIV = contentLic?.Voucher?.Iv, OutputFormat = outputFormat, + MoveMoovToBeginning = config.MoveMoovToBeginning, TrimOutputToChapterLength = config.AllowLibationFixup && config.StripAudibleBrandAudio, RetainEncryptedFile = config.RetainAaxFile && encrypted, StripUnabridged = config.AllowLibationFixup && config.StripUnabridged, diff --git a/Source/FileLiberator/DownloadOptions.cs b/Source/FileLiberator/DownloadOptions.cs index 7520ed15..c43d1bcd 100644 --- a/Source/FileLiberator/DownloadOptions.cs +++ b/Source/FileLiberator/DownloadOptions.cs @@ -34,6 +34,8 @@ namespace FileLiberator public bool MatchSourceBitrate { get; init; } public ReplacementCharacters ReplacementCharacters => Configuration.Instance.ReplacementCharacters; + public bool MoveMoovToBeginning { get; init; } + public string GetMultipartFileName(MultiConvertFileProperties props) => Templates.ChapterFile.GetFilename(LibraryBookDto, props); diff --git a/Source/LibationAvalonia/Dialogs/SettingsDialog.axaml b/Source/LibationAvalonia/Dialogs/SettingsDialog.axaml index ba5d1d62..b1e973ff 100644 --- a/Source/LibationAvalonia/Dialogs/SettingsDialog.axaml +++ b/Source/LibationAvalonia/Dialogs/SettingsDialog.axaml @@ -2,8 +2,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" d:DesignWidth="850" d:DesignHeight="620" - MinWidth="800" MinHeight="620" + mc:Ignorable="d" d:DesignWidth="900" d:DesignHeight="680" + MinWidth="900" MinHeight="680" x:Class="LibationAvalonia.Dialogs.SettingsDialog" xmlns:controls="clr-namespace:LibationAvalonia.Controls" Title="Edit Settings" @@ -34,6 +34,378 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +