Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not all failed video parts being redownloaded #1180

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading