Skip to content

Commit

Permalink
null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McRackan committed Dec 31, 2019
1 parent f93498b commit 9abb9e3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 52 deletions.
6 changes: 3 additions & 3 deletions AaxDecrypter/UNTESTED/AaxToM4bConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ private int ngDecrypt()

public bool Step3_Chapterize()
{
string str1 = "";
var str1 = "";
if (chapters.FirstChapterStart != 0.0)
{
str1 = " -ss " + chapters.FirstChapterStart.ToString("0.000", CultureInfo.InvariantCulture) + " -t " + (chapters.LastChapterStart - 1.0).ToString("0.000", CultureInfo.InvariantCulture) + " ";
}

string ffmpegTags = tags.GenerateFfmpegTags();
string ffmpegChapters = chapters.GenerateFfmpegChapters();
var ffmpegTags = tags.GenerateFfmpegTags();
var ffmpegChapters = chapters.GenerateFfmpegChapters();
File.WriteAllText(ff_txt_file, ffmpegTags + ffmpegChapters);

var tagAndChapterInfo = new ProcessStartInfo
Expand Down
12 changes: 6 additions & 6 deletions AaxDecrypter/UNTESTED/Chapters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class Chapters

public Chapters(string file, double totalTime)
{
this.markers = getAAXChapters(file);
markers = getAAXChapters(file);

// add end time
this.markers.Add(totalTime);
markers.Add(totalTime);
}

private static List<double> getAAXChapters(string file)
Expand All @@ -42,7 +42,7 @@ private static List<double> getAAXChapters(string file)
}

// subtract 1 b/c end time marker is a real entry but isn't a real chapter
public int Count() => this.markers.Count - 1;
public int Count() => markers.Count - 1;

public string GetCuefromChapters(string fileName)
{
Expand All @@ -56,7 +56,7 @@ public string GetCuefromChapters(string fileName)
{
var chapter = i + 1;

var timeSpan = TimeSpan.FromSeconds(this.markers[i]);
var timeSpan = TimeSpan.FromSeconds(markers[i]);
var minutes = Math.Floor(timeSpan.TotalMinutes).ToString();
var seconds = timeSpan.Seconds.ToString("D2");
var milliseconds = (timeSpan.Milliseconds / 10).ToString("D2");
Expand All @@ -78,8 +78,8 @@ public string GenerateFfmpegChapters()
{
var chapter = i + 1;

var start = this.markers[i] * 1000.0;
var end = this.markers[i + 1] * 1000.0;
var start = markers[i] * 1000.0;
var end = markers[i + 1] * 1000.0;
var chapterName = chapter.ToString("D3");

stringBuilder.Append("[CHAPTER]\n");
Expand Down
77 changes: 35 additions & 42 deletions AaxDecrypter/UNTESTED/Tags.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using TagLib;
using TagLib.Mpeg4;
using Dinah.Core;
Expand All @@ -23,52 +18,50 @@ public class Tags
public string genre { get; }
public TimeSpan duration { get; }

// input file
public Tags(string file)
{
using TagLib.File tagLibFile = TagLib.File.Create(file, "audio/mp4", ReadStyle.Average);
this.title = tagLibFile.Tag.Title.Replace(" (Unabridged)", "");
this.album = tagLibFile.Tag.Album.Replace(" (Unabridged)", "");
this.author = tagLibFile.Tag.FirstPerformer ?? "[unknown]";
this.year = tagLibFile.Tag.Year.ToString();
this.comments = tagLibFile.Tag.Comment;
this.duration = tagLibFile.Properties.Duration;
this.genre = tagLibFile.Tag.FirstGenre;
using var tagLibFile = TagLib.File.Create(file, "audio/mp4", ReadStyle.Average);
title = tagLibFile.Tag.Title.Replace(" (Unabridged)", "");
album = tagLibFile.Tag.Album.Replace(" (Unabridged)", "");
author = tagLibFile.Tag.FirstPerformer ?? "[unknown]";
year = tagLibFile.Tag.Year.ToString();
comments = tagLibFile.Tag.Comment ?? "";
duration = tagLibFile.Properties.Duration;
genre = tagLibFile.Tag.FirstGenre ?? "";

var tag = tagLibFile.GetTag(TagTypes.Apple, true);
this.publisher = tag.Publisher;
this.narrator = string.IsNullOrWhiteSpace(tagLibFile.Tag.FirstComposer) ? tag.Narrator : tagLibFile.Tag.FirstComposer;
this.comments = !string.IsNullOrWhiteSpace(tag.LongDescription) ? tag.LongDescription : tag.Description;
this.id = tag.AudibleCDEK;
var tag = tagLibFile.GetTag(TagTypes.Apple, true);
publisher = tag.Publisher ?? "";
narrator = string.IsNullOrWhiteSpace(tagLibFile.Tag.FirstComposer) ? tag.Narrator : tagLibFile.Tag.FirstComposer;
comments = !string.IsNullOrWhiteSpace(tag.LongDescription) ? tag.LongDescription : tag.Description;
id = tag.AudibleCDEK;
}

// my best guess of what this step is doing:
// re-publish the data we read from the input file => output file
public void AddAppleTags(string file)
{
using var file1 = TagLib.File.Create(file, "audio/mp4", ReadStyle.Average);
var tag = (AppleTag)file1.GetTag(TagTypes.Apple, true);
tag.Publisher = this.publisher;
tag.LongDescription = this.comments;
tag.Description = this.comments;
file1.Save();
using var tagLibFile = TagLib.File.Create(file, "audio/mp4", ReadStyle.Average);
var tag = (AppleTag)tagLibFile.GetTag(TagTypes.Apple, true);
tag.Publisher = publisher;
tag.LongDescription = comments;
tag.Description = comments;
tagLibFile.Save();
}

public string GenerateFfmpegTags()
{
StringBuilder stringBuilder = new StringBuilder();

stringBuilder.Append(";FFMETADATA1\n");
stringBuilder.Append("major_brand=aax\n");
stringBuilder.Append("minor_version=1\n");
stringBuilder.Append("compatible_brands=aax M4B mp42isom\n");
stringBuilder.Append("date=" + this.year + "\n");
stringBuilder.Append("genre=" + this.genre + "\n");
stringBuilder.Append("title=" + this.title + "\n");
stringBuilder.Append("artist=" + this.author + "\n");
stringBuilder.Append("album=" + this.album + "\n");
stringBuilder.Append("composer=" + this.narrator + "\n");
stringBuilder.Append("comment=" + this.comments.Truncate(254) + "\n");
stringBuilder.Append("description=" + this.comments + "\n");

return stringBuilder.ToString();
}
=> $";FFMETADATA1"
+ $"\nmajor_brand=aax"
+ $"\nminor_version=1"
+ $"\ncompatible_brands=aax M4B mp42isom"
+ $"\ndate={year}"
+ $"\ngenre={genre}"
+ $"\ntitle={title}"
+ $"\nartist={author}"
+ $"\nalbum={album}"
+ $"\ncomposer={narrator}"
+ $"\ncomment={comments.Truncate(254)}"
+ $"\ndescription={comments}"
+ $"\n";
}
}
2 changes: 1 addition & 1 deletion LibationLauncher/LibationLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>

<Version>3.1.1.0</Version>
<Version>3.1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions REFERENCE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- begin VERSIONING ---------------------------------------------------------------------------------------------------------------------
https://github.com/rmcrackan/Libation/releases

v3.1.2 : null checks
v3.1.1 : Check if upgrade available on github
v3.1.0 : FIRST PUBLIC RELEASE
v3.1-beta.11 : Improved configuration and settings file management. Configurable logging
Expand Down

0 comments on commit 9abb9e3

Please sign in to comment.