Removed repeated code

This commit is contained in:
Sean Kelly 2021-09-30 20:32:30 +13:00
parent 4b78b757aa
commit 5e349c6662
2 changed files with 34 additions and 35 deletions

View File

@ -59,18 +59,7 @@ namespace AaxDecrypter
protected override bool Step2_DownloadAudiobookAsSingleFile() protected override bool Step2_DownloadAudiobookAsSingleFile()
{ {
var zeroProgress = new DownloadProgress var zeroProgress = Step2_Start();
{
BytesReceived = 0,
ProgressPercentage = 0,
TotalBytesToReceive = InputFileStream.Length
};
OnDecryptProgressUpdate(zeroProgress);
aaxFile.SetDecryptionKey(downloadLicense.AudibleKey, downloadLicense.AudibleIV);
if (File.Exists(outputFileName)) if (File.Exists(outputFileName))
FileExt.SafeDelete(outputFileName); FileExt.SafeDelete(outputFileName);
@ -81,18 +70,30 @@ namespace AaxDecrypter
var decryptionResult = OutputFormat == OutputFormat.M4b ? aaxFile.ConvertToMp4a(outputFile, downloadLicense.ChapterInfo) : aaxFile.ConvertToMp3(outputFile); var decryptionResult = OutputFormat == OutputFormat.M4b ? aaxFile.ConvertToMp4a(outputFile, downloadLicense.ChapterInfo) : aaxFile.ConvertToMp3(outputFile);
aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate; aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;
aaxFile.Close();
downloadLicense.ChapterInfo = aaxFile.Chapters; downloadLicense.ChapterInfo = aaxFile.Chapters;
CloseInputFileStream(); Step2_End(zeroProgress);
OnDecryptProgressUpdate(zeroProgress);
return decryptionResult == ConversionResult.NoErrorsDetected && !isCanceled; return decryptionResult == ConversionResult.NoErrorsDetected && !isCanceled;
} }
public bool Step2_DownloadAudiobookAsMultipleFilesPerChapter() private bool Step2_DownloadAudiobookAsMultipleFilesPerChapter()
{
var zeroProgress = Step2_Start();
aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate;
if(OutputFormat == OutputFormat.M4b)
ConvertToMultiMp4b();
else
ConvertToMultiMp3();
aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;
Step2_End(zeroProgress);
return true;
}
private DownloadProgress Step2_Start()
{ {
var zeroProgress = new DownloadProgress var zeroProgress = new DownloadProgress
{ {
@ -104,17 +105,16 @@ namespace AaxDecrypter
OnDecryptProgressUpdate(zeroProgress); OnDecryptProgressUpdate(zeroProgress);
aaxFile.SetDecryptionKey(downloadLicense.AudibleKey, downloadLicense.AudibleIV); aaxFile.SetDecryptionKey(downloadLicense.AudibleKey, downloadLicense.AudibleIV);
return zeroProgress;
}
aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate; private void Step2_End(DownloadProgress zeroProgress)
if(OutputFormat == OutputFormat.M4b) {
ConvertToMultiMp4b();
else
ConvertToMultiMp3();
aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;
aaxFile.Close(); aaxFile.Close();
return true; CloseInputFileStream();
OnDecryptProgressUpdate(zeroProgress);
} }
private void ConvertToMultiMp4b() private void ConvertToMultiMp4b()
@ -122,7 +122,6 @@ namespace AaxDecrypter
var chapterCount = 0; var chapterCount = 0;
aaxFile.ConvertToMultiMp4a(downloadLicense.ChapterInfo, newSplitCallback => aaxFile.ConvertToMultiMp4a(downloadLicense.ChapterInfo, newSplitCallback =>
{ {
// TODO I need to find a way to inject the track number into the m4b file. It's easier with the MP3.
chapterCount++; chapterCount++;
var fileName = Path.ChangeExtension(outputFileName, $"{chapterCount}.m4b"); var fileName = Path.ChangeExtension(outputFileName, $"{chapterCount}.m4b");
if (File.Exists(fileName)) if (File.Exists(fileName))

View File

@ -7,10 +7,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<!--<PackageReference Include="MSBump" Version="2.3.2"> <PackageReference Include="MSBump" Version="2.3.2">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>--> </PackageReference>
<PackageReference Include="Octokit" Version="0.50.0" /> <PackageReference Include="Octokit" Version="0.50.0" />
</ItemGroup> </ItemGroup>