Skip to content

Commit

Permalink
Fix chatdownload embed progress & bad videodownload error message (#1108
Browse files Browse the repository at this point in the history
)

* Fix chatdownload embed progress

* Fix bad exception message
  • Loading branch information
ScrubN authored Jun 23, 2024
1 parent ed5afde commit 7c0dd55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions TwitchDownloaderCore/ChatDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,19 +450,21 @@ private async Task DownloadAsyncImpl(FileInfo outputFileInfo, FileStream outputF

private async Task EmbedImages(ChatRoot chatRoot, CancellationToken cancellationToken)
{
_progress.SetTemplateStatus("Downloading + Embedding Images {0}%", 0);
_progress.SetTemplateStatus("Downloading Embed Images {0}%", 0);
chatRoot.embeddedData = new EmbeddedData();

// This is the exact same process as in ChatUpdater.cs but not in a task oriented manner
// TODO: Combine this with ChatUpdater in a different file
List<TwitchEmote> thirdPartyEmotes = await TwitchHelper.GetThirdPartyEmotes(chatRoot.comments, chatRoot.streamer.id, downloadOptions.TempFolder, _progress, bttv: downloadOptions.BttvEmotes, ffz: downloadOptions.FfzEmotes, stv: downloadOptions.StvEmotes, cancellationToken: cancellationToken);
_progress.ReportProgress(50 / 4);
_progress.ReportProgress(25);
List<TwitchEmote> firstPartyEmotes = await TwitchHelper.GetEmotes(chatRoot.comments, downloadOptions.TempFolder, _progress, cancellationToken: cancellationToken);
_progress.ReportProgress(50 / 4 * 2);
_progress.ReportProgress(50);
List<ChatBadge> twitchBadges = await TwitchHelper.GetChatBadges(chatRoot.comments, chatRoot.streamer.id, downloadOptions.TempFolder, _progress, cancellationToken: cancellationToken);
_progress.ReportProgress(50 / 4 * 3);
_progress.ReportProgress(75);
List<CheerEmote> twitchBits = await TwitchHelper.GetBits(chatRoot.comments, downloadOptions.TempFolder, chatRoot.streamer.id.ToString(), _progress, cancellationToken: cancellationToken);
_progress.ReportProgress(50);
_progress.ReportProgress(100);

_progress.SetTemplateStatus("Embedding Images {0}%", 0);

var totalImageCount = thirdPartyEmotes.Count + firstPartyEmotes.Count + twitchBadges.Count + twitchBits.Count;
var imagesProcessed = 0;
Expand All @@ -480,7 +482,7 @@ private async Task EmbedImages(ChatRoot chatRoot, CancellationToken cancellation
};

chatRoot.embeddedData.thirdParty.Add(newEmote);
_progress.ReportProgress(++imagesProcessed * 100 / totalImageCount + 50);
_progress.ReportProgress(++imagesProcessed * 100 / totalImageCount);
}

cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -498,7 +500,7 @@ private async Task EmbedImages(ChatRoot chatRoot, CancellationToken cancellation
};

chatRoot.embeddedData.firstParty.Add(newEmote);
_progress.ReportProgress(++imagesProcessed * 100 / totalImageCount + 50);
_progress.ReportProgress(++imagesProcessed * 100 / totalImageCount);
}

cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -512,7 +514,7 @@ private async Task EmbedImages(ChatRoot chatRoot, CancellationToken cancellation
};

chatRoot.embeddedData.twitchBadges.Add(newBadge);
_progress.ReportProgress(++imagesProcessed * 100 / totalImageCount + 50);
_progress.ReportProgress(++imagesProcessed * 100 / totalImageCount);
}

cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -540,14 +542,14 @@ private async Task EmbedImages(ChatRoot chatRoot, CancellationToken cancellation
}

chatRoot.embeddedData.twitchBits.Add(newBit);
_progress.ReportProgress(++imagesProcessed * 100 / totalImageCount + 50);
_progress.ReportProgress(++imagesProcessed * 100 / totalImageCount);
}
}

private async Task BackfillUserInfo(ChatRoot chatRoot)
{
// Best effort, but if we fail oh well
_progress.SetTemplateStatus("Backfilling Commenter Info {0}", 0);
_progress.SetTemplateStatus("Backfilling Commenter Info {0}%", 0);

var userIds = chatRoot.comments.Select(x => x.commenter._id).Distinct().ToArray();
var userInfo = new Dictionary<string, User>(userIds.Length);
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/VideoDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private async Task VerifyDownloadedParts(ICollection<M3U8.Stream> playlist, Rang
{
// 19/20 parts failed to verify. Either the VOD is heavily corrupted or something went horribly wrong.
// TODO: Somehow let the user bypass this. Maybe with callbacks?
throw new Exception($"Too many parts are corrupted or missing ({failedParts}/{partCount}), aborting.");
throw new Exception($"Too many parts are corrupted or missing ({failedParts.Count}/{partCount}), aborting.");
}

_progress.LogInfo($"The following parts will be redownloaded: {string.Join(", ", failedParts)}");
Expand Down

0 comments on commit 7c0dd55

Please sign in to comment.