From 6dafa035542ee6ae140cb7772bd6d06e3572c32f Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Thu, 1 Jul 2021 13:14:54 -0600 Subject: [PATCH 1/5] Replaced property name string with nameof. --- LibationLauncher/Program.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/LibationLauncher/Program.cs b/LibationLauncher/Program.cs index 9fc3815d..dd90d97a 100644 --- a/LibationLauncher/Program.cs +++ b/LibationLauncher/Program.cs @@ -30,7 +30,7 @@ namespace LibationLauncher migrate_to_v4_0_0(); migrate_to_v5_0_0(); - + ensureLoggingConfig(); ensureSerilogConfig(); configureLogging(); @@ -213,9 +213,10 @@ namespace LibationLauncher { var persistentDictionary = new PersistentDictionary(Configuration.Instance.SettingsFilePath); - if (persistentDictionary.GetString("AllowLibationFixup") is null) + var config = Configuration.Instance; + if (persistentDictionary.GetString(nameof(config.AllowLibationFixup)) is null) { - persistentDictionary.Set("AllowLibationFixup", true); + persistentDictionary.Set(nameof(config.AllowLibationFixup), true); } if (!File.Exists(AudibleApiStorage.AccountsSettingsFile)) From 729212a5d59db3cdb0bae8901852fef4e569b79e Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Thu, 1 Jul 2021 13:16:09 -0600 Subject: [PATCH 2/5] Simplified ffmpeg chapter parser by using json insterad of xml. --- AaxDecrypter/Chapters.cs | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/AaxDecrypter/Chapters.cs b/AaxDecrypter/Chapters.cs index 8a05e7e2..fedc3b40 100644 --- a/AaxDecrypter/Chapters.cs +++ b/AaxDecrypter/Chapters.cs @@ -1,9 +1,9 @@ using Dinah.Core; using Dinah.Core.Diagnostics; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Diagnostics; -using System.Globalization; using System.Linq; using System.Text; @@ -14,36 +14,25 @@ namespace AaxDecrypter private List _chapterList = new List(); public IEnumerable 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 + "\"" + Arguments = "-loglevel panic -show_chapters -print_format json \"" + audiobookFile + "\"" }; + var xml = info.RunHidden().Output; + var chapterJObject = JObject.Parse(xml); + var chapters = chapterJObject["chapters"] + .Select(c => new Chapter( + c["tags"]?["title"]?.Value(), + c["start_time"].Value(), + c["end_time"].Value() + )); - var xmlDocument = new System.Xml.XmlDocument(); - xmlDocument.LoadXml(xml); - var chaptersXml = xmlDocument.SelectNodes("/ffprobe/chapters/chapter") - .Cast() - .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() - .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))); - } + _chapterList.AddRange(chapters); } public void AddChapter(Chapter chapter) { @@ -79,6 +68,10 @@ namespace AaxDecrypter StartOffset = TimeSpan.FromMilliseconds(startOffsetMs); EndOffset = StartOffset + TimeSpan.FromMilliseconds(lengthMs); } + public Chapter(string title, double startTimeSec, double endTimeSec) + :this(title, (long)(startTimeSec * 1000), (long)((endTimeSec - startTimeSec) * 1000)) + { + } public string ToFFMeta() { From 66bd18fdc5ae5fe95080c1e0d44e1a2cc8c05516 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Thu, 1 Jul 2021 17:58:02 -0600 Subject: [PATCH 3/5] Fixed typo. --- AaxDecrypter/Chapters.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AaxDecrypter/Chapters.cs b/AaxDecrypter/Chapters.cs index fedc3b40..bb8275da 100644 --- a/AaxDecrypter/Chapters.cs +++ b/AaxDecrypter/Chapters.cs @@ -23,8 +23,8 @@ namespace AaxDecrypter Arguments = "-loglevel panic -show_chapters -print_format json \"" + audiobookFile + "\"" }; - var xml = info.RunHidden().Output; - var chapterJObject = JObject.Parse(xml); + var jString = info.RunHidden().Output; + var chapterJObject = JObject.Parse(jString); var chapters = chapterJObject["chapters"] .Select(c => new Chapter( c["tags"]?["title"]?.Value(), From 0d89c3410774d1900b1a901484d7b5f690998b77 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Thu, 1 Jul 2021 18:01:03 -0600 Subject: [PATCH 4/5] Added try blocks. TODO: Add error logging. --- AaxDecrypter/AaxcDownloadConverter.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index 11038eb1..23e3b882 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -211,13 +211,27 @@ namespace AaxDecrypter public bool Step5_CreateCue() { - File.WriteAllText(PathLib.ReplaceExtension(outputFileName, ".cue"), Cue.CreateContents(Path.GetFileName(outputFileName), downloadLicense.ChapterInfo)); + try + { + File.WriteAllText(PathLib.ReplaceExtension(outputFileName, ".cue"), Cue.CreateContents(Path.GetFileName(outputFileName), downloadLicense.ChapterInfo)); + } + catch (Exception ex) + { + //TODO Add log entry + } return !isCanceled; } public bool Step6_CreateNfo() { - File.WriteAllText(PathLib.ReplaceExtension(outputFileName, ".nfo"), NFO.CreateContents(AppName, aaxcTagLib, downloadLicense.ChapterInfo)); + try + { + File.WriteAllText(PathLib.ReplaceExtension(outputFileName, ".nfo"), NFO.CreateContents(AppName, aaxcTagLib, downloadLicense.ChapterInfo)); + } + catch (Exception ex) + { + //TODO Add log entry + } return !isCanceled; } From d41fe0d3e6fd00cf40dd2b9d41ce0f1f3932cdab Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Thu, 1 Jul 2021 21:42:44 -0600 Subject: [PATCH 5/5] Added log --- AaxDecrypter/AaxcDownloadConverter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index 23e3b882..7438ec61 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -217,7 +217,7 @@ namespace AaxDecrypter } catch (Exception ex) { - //TODO Add log entry + Serilog.Log.Logger.Error(ex, $"{nameof(Step5_CreateCue)}. FAILED"); } return !isCanceled; } @@ -230,7 +230,7 @@ namespace AaxDecrypter } catch (Exception ex) { - //TODO Add log entry + Serilog.Log.Logger.Error(ex, $"{nameof(Step5_CreateCue)}. FAILED"); } return !isCanceled; }