diff --git a/TwitchDownloaderCore/Tools/VideoDownloadThread.cs b/TwitchDownloaderCore/Tools/VideoDownloadThread.cs index 527d5708..1546aa42 100644 --- a/TwitchDownloaderCore/Tools/VideoDownloadThread.cs +++ b/TwitchDownloaderCore/Tools/VideoDownloadThread.cs @@ -43,13 +43,13 @@ public void StartDownload() } ThreadTask = Task.Factory.StartNew( - ExecuteDownloadThread, + Execute, _cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); } - private void ExecuteDownloadThread() + private void Execute() { using var cts = new CancellationTokenSource(); _cancellationToken.Register(PropagateCancel, cts); diff --git a/TwitchDownloaderCore/VideoDownloader.cs b/TwitchDownloaderCore/VideoDownloader.cs index a81190f8..fe2ac551 100644 --- a/TwitchDownloaderCore/VideoDownloader.cs +++ b/TwitchDownloaderCore/VideoDownloader.cs @@ -248,7 +248,7 @@ private void LogDownloadThreadExceptions(IReadOnlyCollection download if (downloadExceptions.Count == 0) return; - var culpritList = new List(); + var culprits = new HashSet(); var sb = new StringBuilder(); foreach (var downloadException in downloadExceptions) { @@ -259,16 +259,17 @@ private void LogDownloadThreadExceptions(IReadOnlyCollection download }; // Try to only log exceptions from different sources - var culprit = ex.TargetSite?.Name; - if (string.IsNullOrEmpty(culprit) || culpritList.Contains(culprit)) + var targetSiteName = ex.TargetSite?.Name ?? "PrivateMethod"; + var targetSiteTypeName = ex.TargetSite?.DeclaringType?.Name ?? "PrivateType"; + + var culprit = $"{targetSiteTypeName}.{targetSiteName}"; + if (!culprits.Add(culprit)) continue; - sb.EnsureCapacity(sb.Capacity + ex.Message.Length + culprit.Length + 6); sb.Append(", "); sb.Append(ex.Message); sb.Append(" at "); sb.Append(culprit); - culpritList.Add(culprit); } if (sb.Length == 0) @@ -276,7 +277,9 @@ private void LogDownloadThreadExceptions(IReadOnlyCollection download return; } - sb.Replace(",", $"{downloadExceptions.Count} errors were encountered while downloading:", 0, 1); + _ = downloadExceptions.Count == 1 + ? sb.Replace(",", "1 error was encountered while downloading:", 0, 1) + : sb.Replace(",", $"{downloadExceptions.Count} errors were encountered while downloading:", 0, 1); _progress.LogInfo(sb.ToString()); } @@ -312,7 +315,7 @@ private async Task VerifyDownloadedParts(ICollection playlist, Rang } _progress.LogInfo($"The following parts will be redownloaded: {string.Join(", ", failedParts)}"); - await DownloadVideoPartsAsync(failedParts, videoListCrop, baseUrl, downloadFolder, vodAirDate, cancellationToken); + await DownloadVideoPartsAsync(failedParts, Range.All, baseUrl, downloadFolder, vodAirDate, cancellationToken); } }