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

Cleanup #1168

Merged
merged 2 commits into from
Aug 1, 2024
Merged

Cleanup #1168

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
16 changes: 8 additions & 8 deletions TwitchDownloaderCore/ChatDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static async Task<List<Comment>> DownloadSection(Range downloadRange, st
{
cancellationToken.ThrowIfCancellationRequested();

GqlCommentResponse[] commentResponse;
GqlCommentResponse commentResponse;
try
{
var request = new HttpRequestMessage()
Expand All @@ -68,20 +68,20 @@ private static async Task<List<Comment>> DownloadSection(Range downloadRange, st
if (isFirst)
{
request.Content = new StringContent(
"[{\"operationName\":\"VideoCommentsByOffsetOrCursor\",\"variables\":{\"videoID\":\"" + videoId + "\",\"contentOffsetSeconds\":" + videoStart + "},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"b70a3591ff0f4e0313d126c6a1502d79a1c02baebb288227c582044aa76adf6a\"}}}]",
"{\"operationName\":\"VideoCommentsByOffsetOrCursor\",\"variables\":{\"videoID\":\"" + videoId + "\",\"contentOffsetSeconds\":" + videoStart + "},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"b70a3591ff0f4e0313d126c6a1502d79a1c02baebb288227c582044aa76adf6a\"}}}",
Encoding.UTF8, "application/json");
}
else
{
request.Content = new StringContent(
"[{\"operationName\":\"VideoCommentsByOffsetOrCursor\",\"variables\":{\"videoID\":\"" + videoId + "\",\"cursor\":\"" + cursor + "\"},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"b70a3591ff0f4e0313d126c6a1502d79a1c02baebb288227c582044aa76adf6a\"}}}]",
"{\"operationName\":\"VideoCommentsByOffsetOrCursor\",\"variables\":{\"videoID\":\"" + videoId + "\",\"cursor\":\"" + cursor + "\"},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"b70a3591ff0f4e0313d126c6a1502d79a1c02baebb288227c582044aa76adf6a\"}}}",
Encoding.UTF8, "application/json");
}

using (var httpResponse = await HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false))
{
httpResponse.EnsureSuccessStatusCode();
commentResponse = await httpResponse.Content.ReadFromJsonAsync<GqlCommentResponse[]>(options: null, cancellationToken);
commentResponse = await httpResponse.Content.ReadFromJsonAsync<GqlCommentResponse>(options: null, cancellationToken);
}

errorCount = 0;
Expand All @@ -97,13 +97,13 @@ private static async Task<List<Comment>> DownloadSection(Range downloadRange, st
continue;
}

if (commentResponse[0].data.video.comments?.edges is null)
if (commentResponse.data.video.comments?.edges is null)
{
// video.comments can be null for some dumb reason, skip
continue;
}

var convertedComments = ConvertComments(commentResponse[0].data.video, format);
var convertedComments = ConvertComments(commentResponse.data.video, format);
foreach (var comment in convertedComments)
{
if (comment.content_offset_seconds >= videoStart && comment.content_offset_seconds < videoEnd)
Expand All @@ -117,10 +117,10 @@ private static async Task<List<Comment>> DownloadSection(Range downloadRange, st
}
}

if (!commentResponse[0].data.video.comments.pageInfo.hasNextPage)
if (!commentResponse.data.video.comments.pageInfo.hasNextPage)
break;

cursor = commentResponse[0].data.video.comments.edges.Last().cursor;
cursor = commentResponse.data.video.comments.edges.Last().cursor;

var percent = (int)Math.Floor((latestMessage - videoStart) / videoDuration * 100);
progress.Report(percent);
Expand Down
9 changes: 3 additions & 6 deletions TwitchDownloaderCore/TwitchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,11 @@ public static async Task<Dictionary<string, SKBitmap>> GetEmojis(string cacheFol
return returnCache;

var emojiFolder = Path.Combine(cacheFolder, "emojis", emojiVendor.EmojiFolder());
var emojiExtensions = new Regex(@"\.(?:png|PNG)$", RegexOptions.RightToLeft); // Extensions are case sensitive on Linux and Mac

if (!Directory.Exists(emojiFolder))
CreateDirectory(emojiFolder);

var emojiFiles = Directory.GetFiles(emojiFolder)
.Where(i => emojiExtensions.IsMatch(i)).ToArray();
var enumerationOptions = new EnumerationOptions { MatchType = MatchType.Simple, MatchCasing = MatchCasing.CaseInsensitive };
var emojiFiles = Directory.GetFiles(emojiFolder, "*.png", enumerationOptions);

if (emojiFiles.Length < emojiVendor.EmojiCount())
{
Expand Down Expand Up @@ -719,8 +717,7 @@ public static async Task<Dictionary<string, SKBitmap>> GetEmojis(string cacheFol
}
}

emojiFiles = Directory.GetFiles(emojiFolder)
.Where(i => emojiExtensions.IsMatch(i)).ToArray();
emojiFiles = Directory.GetFiles(emojiFolder, "*.png", enumerationOptions);
}
finally
{
Expand Down
Loading