diff --git a/AaxDecrypter/AaxcDownloadConvertBase.cs b/AaxDecrypter/AaxcDownloadConvertBase.cs
index b4959c3f..20fd0850 100644
--- a/AaxDecrypter/AaxcDownloadConvertBase.cs
+++ b/AaxDecrypter/AaxcDownloadConvertBase.cs
@@ -20,8 +20,8 @@ namespace AaxDecrypter
public override void SetCoverArt(byte[] coverArt)
{
base.SetCoverArt(coverArt);
- if (coverArt is not null)
- AaxFile?.AppleTags.SetCoverArt(coverArt);
+ if (coverArt is not null && AaxFile?.AppleTags is not null)
+ AaxFile.AppleTags.Cover = coverArt;
}
/// Optional step to run after Metadata is retrieved
diff --git a/AaxDecrypter/AudiobookDownloadBase.cs b/AaxDecrypter/AudiobookDownloadBase.cs
index 8a20b5c5..fc8f8ef7 100644
--- a/AaxDecrypter/AudiobookDownloadBase.cs
+++ b/AaxDecrypter/AudiobookDownloadBase.cs
@@ -67,16 +67,17 @@ namespace AaxDecrypter
Serilog.Log.Logger.Error("Conversion failed");
return IsSuccess;
- }
+ }
- protected void OnRetrievedTitle(string title)
+ protected void OnRetrievedTitle(string title)
=> RetrievedTitle?.Invoke(this, title);
- protected void OnRetrievedAuthors(string authors)
+ protected void OnRetrievedAuthors(string authors)
=> RetrievedAuthors?.Invoke(this, authors);
- protected void OnRetrievedNarrators(string narrators)
+ protected void OnRetrievedNarrators(string narrators)
=> RetrievedNarrators?.Invoke(this, narrators);
- protected void OnRetrievedCoverArt(byte[] coverArt)
+ protected void OnRetrievedCoverArt(byte[] coverArt)
=> RetrievedCoverArt?.Invoke(this, coverArt);
+
protected void OnDecryptProgressUpdate(DownloadProgress downloadProgress)
=> DecryptProgressUpdate?.Invoke(this, downloadProgress);
protected void OnDecryptTimeRemaining(TimeSpan timeRemaining)
diff --git a/FileLiberator/AudioDecodable.cs b/FileLiberator/AudioDecodable.cs
index 24478024..1b527472 100644
--- a/FileLiberator/AudioDecodable.cs
+++ b/FileLiberator/AudioDecodable.cs
@@ -17,19 +17,22 @@ namespace FileLiberator
RequestCoverArt?.Invoke(this, setCoverArtDel);
}
- protected void OnTitleDiscovered(string title)
+ protected void OnTitleDiscovered(string title) => OnTitleDiscovered(null, title);
+ protected void OnTitleDiscovered(object _, string title)
{
Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(TitleDiscovered), Title = title });
TitleDiscovered?.Invoke(this, title);
}
- protected void OnAuthorsDiscovered(string authors)
+ protected void OnAuthorsDiscovered(string authors) => OnAuthorsDiscovered(null, authors);
+ protected void OnAuthorsDiscovered(object _, string authors)
{
Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(AuthorsDiscovered), Authors = authors });
AuthorsDiscovered?.Invoke(this, authors);
}
- protected void OnNarratorsDiscovered(string narrators)
+ protected void OnNarratorsDiscovered(string narrators) => OnNarratorsDiscovered(null, narrators);
+ protected void OnNarratorsDiscovered(object _, string narrators)
{
Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(NarratorsDiscovered), Narrators = narrators });
NarratorsDiscovered?.Invoke(this, narrators);
diff --git a/FileLiberator/ConvertToMp3.cs b/FileLiberator/ConvertToMp3.cs
index 12b51745..12d758c1 100644
--- a/FileLiberator/ConvertToMp3.cs
+++ b/FileLiberator/ConvertToMp3.cs
@@ -73,8 +73,8 @@ namespace FileLiberator
private void M4bBook_ConversionProgressUpdate(object sender, ConversionProgressEventArgs e)
{
var duration = m4bBook.Duration;
- double remainingSecsToProcess = (duration - e.ProcessPosition).TotalSeconds;
- double estTimeRemaining = remainingSecsToProcess / e.ProcessSpeed;
+ var remainingSecsToProcess = (duration - e.ProcessPosition).TotalSeconds;
+ var estTimeRemaining = remainingSecsToProcess / e.ProcessSpeed;
if (double.IsNormal(estTimeRemaining))
OnStreamingTimeRemaining(TimeSpan.FromSeconds(estTimeRemaining));
diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs
index ef4b932b..efe74d6c 100644
--- a/FileLiberator/DownloadDecryptBook.cs
+++ b/FileLiberator/DownloadDecryptBook.cs
@@ -132,11 +132,12 @@ namespace FileLiberator
abDownloader = converter;
}
- abDownloader.DecryptProgressUpdate += (_, progress) => OnStreamingProgressChanged(progress);
- abDownloader.DecryptTimeRemaining += (_, remaining) => OnStreamingTimeRemaining(remaining);
- abDownloader.RetrievedTitle += (_, title) => OnTitleDiscovered(title);
- abDownloader.RetrievedAuthors += (_, authors) => OnAuthorsDiscovered(authors);
- abDownloader.RetrievedNarrators += (_, narrators) => OnNarratorsDiscovered(narrators);
+ abDownloader.DecryptProgressUpdate += OnStreamingProgressChanged;
+ abDownloader.DecryptTimeRemaining += OnStreamingTimeRemaining;
+
+ abDownloader.RetrievedTitle += OnTitleDiscovered;
+ abDownloader.RetrievedAuthors += OnAuthorsDiscovered;
+ abDownloader.RetrievedNarrators += OnNarratorsDiscovered;
abDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt;
abDownloader.FileCreated += (_, path) => OnFileCreated(libraryBook, path);
@@ -172,7 +173,7 @@ namespace FileLiberator
throw new Exception(errorString("Locale"));
}
- private void AaxcDownloader_RetrievedCoverArt(object sender, byte[] e)
+ private void AaxcDownloader_RetrievedCoverArt(object _, byte[] e)
{
if (e is not null)
OnCoverImageDiscovered(e);
diff --git a/FileLiberator/DownloadFile.cs b/FileLiberator/DownloadFile.cs
index 0ed0492b..b5939280 100644
--- a/FileLiberator/DownloadFile.cs
+++ b/FileLiberator/DownloadFile.cs
@@ -12,8 +12,7 @@ namespace FileLiberator
{
var client = new HttpClient();
- var progress = new Progress();
- progress.ProgressChanged += (_, e) => OnStreamingProgressChanged(e);
+ var progress = new Progress(OnStreamingProgressChanged);
OnStreamingBegin(proposedDownloadFilePath);
diff --git a/FileLiberator/DownloadPdf.cs b/FileLiberator/DownloadPdf.cs
index 88f8587e..a2378e31 100644
--- a/FileLiberator/DownloadPdf.cs
+++ b/FileLiberator/DownloadPdf.cs
@@ -62,8 +62,7 @@ namespace FileLiberator
var api = await libraryBook.GetApiAsync();
var downloadUrl = await api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId);
- var progress = new Progress();
- progress.ProgressChanged += (_, e) => OnStreamingProgressChanged(e);
+ var progress = new Progress(OnStreamingProgressChanged);
var client = new HttpClient();
diff --git a/FileLiberator/Streamable.cs b/FileLiberator/Streamable.cs
index 78f83d0a..9bc84d59 100644
--- a/FileLiberator/Streamable.cs
+++ b/FileLiberator/Streamable.cs
@@ -18,12 +18,14 @@ namespace FileLiberator
StreamingBegin?.Invoke(this, filePath);
}
- protected void OnStreamingProgressChanged(DownloadProgress progress)
+ protected void OnStreamingProgressChanged(DownloadProgress progress) => OnStreamingProgressChanged(null, progress);
+ protected void OnStreamingProgressChanged(object _, DownloadProgress progress)
{
StreamingProgressChanged?.Invoke(this, progress);
}
- protected void OnStreamingTimeRemaining(TimeSpan timeRemaining)
+ protected void OnStreamingTimeRemaining(TimeSpan timeRemaining) => OnStreamingTimeRemaining(null, timeRemaining);
+ protected void OnStreamingTimeRemaining(object _, TimeSpan timeRemaining)
{
StreamingTimeRemaining?.Invoke(this, timeRemaining);
}
diff --git a/LibationWinForms/BookLiberation/AudioDecodeForm.cs b/LibationWinForms/BookLiberation/AudioDecodeForm.cs
index 44b7e2d2..6520aa65 100644
--- a/LibationWinForms/BookLiberation/AudioDecodeForm.cs
+++ b/LibationWinForms/BookLiberation/AudioDecodeForm.cs
@@ -14,11 +14,6 @@ namespace LibationWinForms.BookLiberation
private Func GetCoverArtDelegate;
- // book info
- private string title;
- private string authorNames;
- private string narratorNames;
-
#region Processable event handler overrides
public override void Processable_Begin(object sender, LibraryBook libraryBook)
{
@@ -31,8 +26,8 @@ namespace LibationWinForms.BookLiberation
//Set default values from library
AudioDecodable_TitleDiscovered(sender, libraryBook.Book.Title);
- AudioDecodable_AuthorsDiscovered(sender, string.Join(", ", libraryBook.Book.Authors));
- AudioDecodable_NarratorsDiscovered(sender, string.Join(", ", libraryBook.Book.NarratorNames));
+ AudioDecodable_AuthorsDiscovered(sender, libraryBook.Book.AuthorNames);
+ AudioDecodable_NarratorsDiscovered(sender, libraryBook.Book.NarratorNames);
AudioDecodable_CoverImageDiscovered(sender,
PictureStorage.GetPicture(
new PictureDefinition(
@@ -60,9 +55,24 @@ namespace LibationWinForms.BookLiberation
updateRemainingTime((int)timeRemaining.TotalSeconds);
}
+ private void updateRemainingTime(int remaining)
+ => remainingTimeLbl.UIThreadAsync(() => remainingTimeLbl.Text = $"ETA:\r\n{formatTime(remaining)}");
+
+ private string formatTime(int seconds)
+ {
+ var timeSpan = new TimeSpan(0, 0, seconds);
+ return
+ timeSpan.TotalHours >= 1 ? $"{timeSpan:%h}h {timeSpan:mm}m {timeSpan:ss}s"
+ : timeSpan.TotalMinutes >= 1 ? $"{timeSpan:%m}m {timeSpan:ss}s"
+ : $"{seconds} sec";
+ }
#endregion
#region AudioDecodable event handlers
+ private string title;
+ private string authorNames;
+ private string narratorNames;
+
public override void AudioDecodable_RequestCoverArt(object sender, Action setCoverArtDelegate)
{
base.AudioDecodable_RequestCoverArt(sender, setCoverArtDelegate);
@@ -91,27 +101,14 @@ namespace LibationWinForms.BookLiberation
updateBookInfo();
}
+ private void updateBookInfo()
+ => bookInfoLbl.UIThreadAsync(() => bookInfoLbl.Text = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}");
+
public override void AudioDecodable_CoverImageDiscovered(object sender, byte[] coverArt)
{
base.AudioDecodable_CoverImageDiscovered(sender, coverArt);
pictureBox1.UIThreadAsync(() => pictureBox1.Image = Dinah.Core.Drawing.ImageReader.ToImage(coverArt));
}
#endregion
-
- // thread-safe UI updates
- private void updateBookInfo()
- => bookInfoLbl.UIThreadAsync(() => bookInfoLbl.Text = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}");
-
- private void updateRemainingTime(int remaining)
- => remainingTimeLbl.UIThreadAsync(() => remainingTimeLbl.Text = $"ETA:\r\n{formatTime(remaining)}");
-
- private string formatTime(int seconds)
- {
- var timeSpan = new TimeSpan(0, 0, seconds);
- return
- timeSpan.TotalHours >= 1 ? $"{timeSpan:%h}h {timeSpan:mm}m {timeSpan:ss}s"
- : timeSpan.TotalMinutes >= 1 ? $"{timeSpan:%m}m {timeSpan:ss}s"
- : $"{seconds} sec";
- }
}
}