Skip to content

Commit

Permalink
Catch HttpRequestExceptions when fetching image data from third party…
Browse files Browse the repository at this point in the history
… emote providers
  • Loading branch information
ScrubN committed Mar 27, 2024
1 parent 7b11b74 commit eb83b74
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/ChatDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public async Task DownloadAsync(IProgress<ProgressReport> progress, Cancellation

// 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, bttv: downloadOptions.BttvEmotes, ffz: downloadOptions.FfzEmotes, stv: downloadOptions.StvEmotes, cancellationToken: cancellationToken);
List<TwitchEmote> thirdPartyEmotes = await TwitchHelper.GetThirdPartyEmotes(chatRoot.comments, chatRoot.streamer.id, downloadOptions.TempFolder, bttv: downloadOptions.BttvEmotes, ffz: downloadOptions.FfzEmotes, stv: downloadOptions.StvEmotes, progress: progress, cancellationToken: cancellationToken);
List<TwitchEmote> firstPartyEmotes = await TwitchHelper.GetEmotes(chatRoot.comments, downloadOptions.TempFolder, cancellationToken: cancellationToken);
List<ChatBadge> twitchBadges = await TwitchHelper.GetChatBadges(chatRoot.comments, chatRoot.streamer.id, downloadOptions.TempFolder, cancellationToken: cancellationToken);
List<CheerEmote> twitchBits = await TwitchHelper.GetBits(chatRoot.comments, downloadOptions.TempFolder, chatRoot.streamer.id.ToString(), cancellationToken: cancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ private async Task<List<TwitchEmote>> GetScaledEmotes(CancellationToken cancella
private async Task<List<TwitchEmote>> GetScaledThirdEmotes(CancellationToken cancellationToken)
{
var emoteThirdTask = await TwitchHelper.GetThirdPartyEmotes(chatRoot.comments, chatRoot.streamer.id, renderOptions.TempFolder, chatRoot.embeddedData, renderOptions.BttvEmotes, renderOptions.FfzEmotes,
renderOptions.StvEmotes, renderOptions.AllowUnlistedEmotes, renderOptions.Offline, cancellationToken);
renderOptions.StvEmotes, renderOptions.AllowUnlistedEmotes, renderOptions.Offline, _progress, cancellationToken);

foreach (var emote in emoteThirdTask)
{
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/ChatUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private async Task FirstPartyEmoteTask(IProgress<ProgressReport> progress = null

private async Task ThirdPartyEmoteTask(IProgress<ProgressReport> progress = null, CancellationToken cancellationToken = default)
{
List<TwitchEmote> thirdPartyEmoteList = await TwitchHelper.GetThirdPartyEmotes(chatRoot.comments, chatRoot.streamer.id, _updateOptions.TempFolder, _updateOptions.ReplaceEmbeds ? null : chatRoot.embeddedData, _updateOptions.BttvEmotes, _updateOptions.FfzEmotes, _updateOptions.StvEmotes, cancellationToken: cancellationToken);
List<TwitchEmote> thirdPartyEmoteList = await TwitchHelper.GetThirdPartyEmotes(chatRoot.comments, chatRoot.streamer.id, _updateOptions.TempFolder, _updateOptions.ReplaceEmbeds ? null : chatRoot.embeddedData, _updateOptions.BttvEmotes, _updateOptions.FfzEmotes, _updateOptions.StvEmotes, progress: progress, cancellationToken: cancellationToken);

int inputCount = chatRoot.embeddedData.thirdParty.Count;
chatRoot.embeddedData.thirdParty = new List<EmbedEmoteData>();
Expand Down
29 changes: 25 additions & 4 deletions TwitchDownloaderCore/TwitchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private static async Task<List<EmoteResponseItem>> GetStvEmotesMetadata(int stre
return returnList;
}

public static async Task<List<TwitchEmote>> GetThirdPartyEmotes(List<Comment> comments, int streamerId, string cacheFolder, EmbeddedData embeddedData = null, bool bttv = true, bool ffz = true, bool stv = true, bool allowUnlistedEmotes = true, bool offline = false, CancellationToken cancellationToken = new())
public static async Task<List<TwitchEmote>> GetThirdPartyEmotes(List<Comment> comments, int streamerId, string cacheFolder, EmbeddedData embeddedData = null, bool bttv = true, bool ffz = true, bool stv = true, bool allowUnlistedEmotes = true, bool offline = false, IProgress<ProgressReport> progress = null, CancellationToken cancellationToken = default)
{
List<TwitchEmote> returnList = new List<TwitchEmote>();
List<string> alreadyAdded = new List<string>();
Expand Down Expand Up @@ -384,21 +384,42 @@ private static async Task<List<EmoteResponseItem>> GetStvEmotesMetadata(int stre

if (bttv)
{
await FetchEmoteImages(comments, emoteDataResponse.BTTV, returnList, alreadyAdded, bttvFolder, cancellationToken);
try
{
await FetchEmoteImages(comments, emoteDataResponse.BTTV, returnList, alreadyAdded, bttvFolder, cancellationToken);
}
catch (HttpRequestException e) when (progress != null)
{
progress.Report(new ProgressReport(ReportType.Log, $"BTTV returned HTTP {e.StatusCode}. BTTV emotes may be disabled for this session."));
}
}

cancellationToken.ThrowIfCancellationRequested();

if (ffz)
{
await FetchEmoteImages(comments, emoteDataResponse.FFZ, returnList, alreadyAdded, ffzFolder, cancellationToken);
try
{
await FetchEmoteImages(comments, emoteDataResponse.FFZ, returnList, alreadyAdded, ffzFolder, cancellationToken);
}
catch (HttpRequestException e) when (progress != null)
{
progress.Report(new ProgressReport(ReportType.Log, $"FFZ returned HTTP {e.StatusCode}. FFZ emotes may be disabled for this session."));
}
}

cancellationToken.ThrowIfCancellationRequested();

if (stv)
{
await FetchEmoteImages(comments, emoteDataResponse.STV, returnList, alreadyAdded, stvFolder, cancellationToken);
try
{
await FetchEmoteImages(comments, emoteDataResponse.STV, returnList, alreadyAdded, stvFolder, cancellationToken);
}
catch (HttpRequestException e) when (progress != null)
{
progress.Report(new ProgressReport(ReportType.Log, $"7TV returned HTTP {e.StatusCode}. 7TV emotes may be disabled for this session."));
}
}

return returnList;
Expand Down

0 comments on commit eb83b74

Please sign in to comment.