Get chapter infor from file is no downloaded chapters were supplied.
This commit is contained in:
parent
d564876eaa
commit
b5389c67ea
@ -135,9 +135,11 @@ namespace AaxDecrypter
|
||||
var aaxcProcesser = new FFMpegAaxcProcesser(downloadLicense);
|
||||
aaxcProcesser.ProgressUpdate += AaxcProcesser_ProgressUpdate;
|
||||
|
||||
bool userSuppliedChapters = chapters != null;
|
||||
|
||||
string metadataPath = null;
|
||||
|
||||
if (chapters != null)
|
||||
if (userSuppliedChapters)
|
||||
{
|
||||
//Only write chaopters to the metadata file. All other aaxc metadata will be
|
||||
//wiped out but is restored in Step 3.
|
||||
@ -151,7 +153,10 @@ namespace AaxDecrypter
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
if (chapters != null)
|
||||
if (!userSuppliedChapters && aaxcProcesser.Succeeded)
|
||||
chapters = new ChapterInfo(outputFileName);
|
||||
|
||||
if (userSuppliedChapters)
|
||||
FileExt.SafeDelete(metadataPath);
|
||||
|
||||
DecryptProgressUpdate?.Invoke(this, 0);
|
||||
@ -187,6 +192,7 @@ namespace AaxDecrypter
|
||||
destTags.SetData(stag.BoxType, stag.Children.Cast<TagLib.Mpeg4.AppleDataBox>().ToArray());
|
||||
}
|
||||
outFile.Save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
using Dinah.Core;
|
||||
using Dinah.Core.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@ -10,6 +13,37 @@ namespace AaxDecrypter
|
||||
private List<Chapter> _chapterList = new List<Chapter>();
|
||||
public IEnumerable<Chapter> Chapters => _chapterList.AsEnumerable();
|
||||
public int Count => _chapterList.Count;
|
||||
|
||||
public ChapterInfo() { }
|
||||
public ChapterInfo(string audiobookFile)
|
||||
{
|
||||
var info = new ProcessStartInfo
|
||||
{
|
||||
FileName = DecryptSupportLibraries.ffprobePath,
|
||||
Arguments = "-loglevel panic -show_chapters -print_format xml \"" + audiobookFile + "\""
|
||||
};
|
||||
var xml = info.RunHidden().Output;
|
||||
|
||||
var xmlDocument = new System.Xml.XmlDocument();
|
||||
xmlDocument.LoadXml(xml);
|
||||
var chaptersXml = xmlDocument.SelectNodes("/ffprobe/chapters/chapter")
|
||||
.Cast<System.Xml.XmlNode>()
|
||||
.Where(n => n.Name == "chapter");
|
||||
|
||||
foreach (var cnode in chaptersXml)
|
||||
{
|
||||
double startTime = double.Parse(cnode.Attributes["start_time"].Value.Replace(",", "."), CultureInfo.InvariantCulture);
|
||||
double endTime = double.Parse(cnode.Attributes["end_time"].Value.Replace(",", "."), CultureInfo.InvariantCulture);
|
||||
|
||||
string chapterTitle = cnode.ChildNodes
|
||||
.Cast<System.Xml.XmlNode>()
|
||||
.Where(childnode => childnode.Attributes["key"].Value == "title")
|
||||
.Select(childnode => childnode.Attributes["value"].Value)
|
||||
.FirstOrDefault();
|
||||
|
||||
AddChapter(new Chapter(chapterTitle, (long)(startTime * 1000), (long)((endTime - startTime) * 1000)));
|
||||
}
|
||||
}
|
||||
public void AddChapter(Chapter chapter)
|
||||
{
|
||||
ArgumentValidator.EnsureNotNull(chapter, nameof(chapter));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user