Merge pull request #134 from Mbucari/master

Fix splitting audiobooks on chapters
This commit is contained in:
rmcrackan 2021-10-06 15:55:02 -04:00 committed by GitHub
commit 5a40c7370f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 6 deletions

View File

@ -4,11 +4,13 @@ using Dinah.Core.Net.Http;
using Dinah.Core.StepRunner; using Dinah.Core.StepRunner;
using System; using System;
using System.IO; using System.IO;
using System.Linq;
namespace AaxDecrypter namespace AaxDecrypter
{ {
public class AaxcDownloadConverter : AudiobookDownloadBase public class AaxcDownloadConverter : AudiobookDownloadBase
{ {
private static readonly TimeSpan minChapterLength = TimeSpan.FromSeconds(15);
protected override StepSequence steps { get; } protected override StepSequence steps { get; }
private AaxFile aaxFile; private AaxFile aaxFile;
@ -81,11 +83,30 @@ namespace AaxDecrypter
{ {
var zeroProgress = Step2_Start(); var zeroProgress = Step2_Start();
var chapters = downloadLicense.ChapterInfo.Chapters.ToList();
//Ensure split files are at least minChapterLength in duration.
var splitChapters = new ChapterInfo();
splitChapters.AddChapter(chapters[0].Title, chapters[0].Duration);
var runningTotal = chapters[0].Duration;
for (int i = 1; i < chapters.Count; i++)
{
if (runningTotal >= minChapterLength)
{
splitChapters.AddChapter(chapters[i].Title, chapters[i].Duration);
runningTotal = chapters[i].Duration;
}
else
runningTotal += chapters[i].Duration;
}
aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate; aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate;
if(OutputFormat == OutputFormat.M4b) if(OutputFormat == OutputFormat.M4b)
ConvertToMultiMp4b(); ConvertToMultiMp4b(splitChapters);
else else
ConvertToMultiMp3(); ConvertToMultiMp3(splitChapters);
aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate; aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;
Step2_End(zeroProgress); Step2_End(zeroProgress);
@ -117,10 +138,10 @@ namespace AaxDecrypter
OnDecryptProgressUpdate(zeroProgress); OnDecryptProgressUpdate(zeroProgress);
} }
private void ConvertToMultiMp4b() private void ConvertToMultiMp4b(ChapterInfo splitChapters)
{ {
var chapterCount = 0; var chapterCount = 0;
aaxFile.ConvertToMultiMp4a(downloadLicense.ChapterInfo, newSplitCallback => aaxFile.ConvertToMultiMp4a(splitChapters, newSplitCallback =>
{ {
chapterCount++; chapterCount++;
var fileName = Path.ChangeExtension(outputFileName, $"{chapterCount}.m4b"); var fileName = Path.ChangeExtension(outputFileName, $"{chapterCount}.m4b");
@ -130,10 +151,11 @@ namespace AaxDecrypter
}); });
} }
private void ConvertToMultiMp3() private void ConvertToMultiMp3(ChapterInfo splitChapters)
{ {
var chapterCount = 0; var chapterCount = 0;
aaxFile.ConvertToMultiMp3(downloadLicense.ChapterInfo, newSplitCallback =>
aaxFile.ConvertToMultiMp3(splitChapters, newSplitCallback =>
{ {
chapterCount++; chapterCount++;
var fileName = Path.ChangeExtension(outputFileName, $"{chapterCount}.mp3"); var fileName = Path.ChangeExtension(outputFileName, $"{chapterCount}.mp3");

View File

@ -84,10 +84,12 @@ namespace LibationWinForms.Dialogs
{ {
convertLosslessRb.Enabled = allowLibationFixupCbox.Checked; convertLosslessRb.Enabled = allowLibationFixupCbox.Checked;
convertLossyRb.Enabled = allowLibationFixupCbox.Checked; convertLossyRb.Enabled = allowLibationFixupCbox.Checked;
splitFilesByChapterCbox.Enabled = allowLibationFixupCbox.Checked;
if (!allowLibationFixupCbox.Checked) if (!allowLibationFixupCbox.Checked)
{ {
convertLosslessRb.Checked = true; convertLosslessRb.Checked = true;
splitFilesByChapterCbox.Checked = false;
} }
} }