Skip to content

Commit

Permalink
Fix not all failed video parts being redownloaded (#1180)
Browse files Browse the repository at this point in the history
* Improve video download error reporting

* Rename ExecuteDownloadThread to Execute

* Fix not all video parts being redownloaded
  • Loading branch information
ScrubN authored Aug 5, 2024
1 parent 8d7ca52 commit a11b237
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions TwitchDownloaderCore/Tools/VideoDownloadThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 10 additions & 7 deletions TwitchDownloaderCore/VideoDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private void LogDownloadThreadExceptions(IReadOnlyCollection<Exception> download
if (downloadExceptions.Count == 0)
return;

var culpritList = new List<string>();
var culprits = new HashSet<string>();
var sb = new StringBuilder();
foreach (var downloadException in downloadExceptions)
{
Expand All @@ -259,24 +259,27 @@ private void LogDownloadThreadExceptions(IReadOnlyCollection<Exception> 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)
{
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());
}

Expand Down Expand Up @@ -312,7 +315,7 @@ private async Task VerifyDownloadedParts(ICollection<M3U8.Stream> 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);
}
}

Expand Down

0 comments on commit a11b237

Please sign in to comment.