From 004437e808c81d26db310fb9d3da52dc7be6ddfc Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:33:56 -0400 Subject: [PATCH 01/14] Fully qualify Translations namespace --- TwitchDownloaderWPF/PageChatRender.xaml.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/TwitchDownloaderWPF/PageChatRender.xaml.cs b/TwitchDownloaderWPF/PageChatRender.xaml.cs index 21d5d19b..3ccccff0 100644 --- a/TwitchDownloaderWPF/PageChatRender.xaml.cs +++ b/TwitchDownloaderWPF/PageChatRender.xaml.cs @@ -20,7 +20,6 @@ using TwitchDownloaderCore.TwitchObjects; using TwitchDownloaderWPF.Models; using TwitchDownloaderWPF.Properties; -using TwitchDownloaderWPF.Translations; using TwitchDownloaderWPF.Utils; using WpfAnimatedGif; using MessageBox = System.Windows.MessageBox; @@ -197,14 +196,14 @@ private void LoadSettings() RadioEmojiNone.IsChecked = (EmojiVendor)Settings.Default.RenderEmojiVendor == EmojiVendor.None; comboBadges.Items.Clear(); - comboBadges.Items.Add(new CheckComboBoxItem { Content = Strings.BadgeMaskBroadcaster, Tag = ChatBadgeType.Broadcaster }); - comboBadges.Items.Add(new CheckComboBoxItem { Content = Strings.BadgeMaskModerator, Tag = ChatBadgeType.Moderator }); - comboBadges.Items.Add(new CheckComboBoxItem { Content = Strings.BadgeMaskVIP, Tag = ChatBadgeType.VIP }); - comboBadges.Items.Add(new CheckComboBoxItem { Content = Strings.BadgeMaskSubscriber, Tag = ChatBadgeType.Subscriber }); - comboBadges.Items.Add(new CheckComboBoxItem { Content = Strings.BadgeMaskPredictions, Tag = ChatBadgeType.Predictions }); - comboBadges.Items.Add(new CheckComboBoxItem { Content = Strings.BadgeMaskNoAudioNoVideo, Tag = ChatBadgeType.NoAudioVisual }); - comboBadges.Items.Add(new CheckComboBoxItem { Content = Strings.BadgeMaskTwitchPrime, Tag = ChatBadgeType.PrimeGaming }); - comboBadges.Items.Add(new CheckComboBoxItem { Content = Strings.BadgeMaskOthers, Tag = ChatBadgeType.Other }); + comboBadges.Items.Add(new CheckComboBoxItem { Content = Translations.Strings.BadgeMaskBroadcaster, Tag = ChatBadgeType.Broadcaster }); + comboBadges.Items.Add(new CheckComboBoxItem { Content = Translations.Strings.BadgeMaskModerator, Tag = ChatBadgeType.Moderator }); + comboBadges.Items.Add(new CheckComboBoxItem { Content = Translations.Strings.BadgeMaskVIP, Tag = ChatBadgeType.VIP }); + comboBadges.Items.Add(new CheckComboBoxItem { Content = Translations.Strings.BadgeMaskSubscriber, Tag = ChatBadgeType.Subscriber }); + comboBadges.Items.Add(new CheckComboBoxItem { Content = Translations.Strings.BadgeMaskPredictions, Tag = ChatBadgeType.Predictions }); + comboBadges.Items.Add(new CheckComboBoxItem { Content = Translations.Strings.BadgeMaskNoAudioNoVideo, Tag = ChatBadgeType.NoAudioVisual }); + comboBadges.Items.Add(new CheckComboBoxItem { Content = Translations.Strings.BadgeMaskTwitchPrime, Tag = ChatBadgeType.PrimeGaming }); + comboBadges.Items.Add(new CheckComboBoxItem { Content = Translations.Strings.BadgeMaskOthers, Tag = ChatBadgeType.Other }); var badgeMask = (ChatBadgeType)Settings.Default.ChatBadgeMask; foreach (CheckComboBoxItem item in comboBadges.Items) From 2a391a939dc009d8d1efa6e5fc6cb3b43f05c0a1 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:15:43 -0400 Subject: [PATCH 02/14] Remove unused methods --- TwitchDownloaderCore/TwitchHelper.cs | 9 --------- TwitchDownloaderWPF/PageQueue.xaml.cs | 7 ------- 2 files changed, 16 deletions(-) diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index cd16d92d..ecedcc90 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -1011,15 +1011,6 @@ where DateTime.UtcNow.Ticks - directoryInfo.LastWriteTimeUtc.Ticks > TimeSpan.Ti : $"{wasDeleted} old video caches were deleted, {toDelete.Length - wasDeleted} could not be deleted."); } - public static int TimestampToSeconds(string input) - { - // Gets total seconds from timestamp in the format of 0h0m0s - input = input.Replace('h', ':').Replace('m', ':').Replace("s", ""); - TimeSpan returnSpan = TimeSpan.Parse(input); - - return (int)returnSpan.TotalSeconds; - } - public static async Task GetStreamerName(int id) { try diff --git a/TwitchDownloaderWPF/PageQueue.xaml.cs b/TwitchDownloaderWPF/PageQueue.xaml.cs index 5f1baf84..d64a5fb8 100644 --- a/TwitchDownloaderWPF/PageQueue.xaml.cs +++ b/TwitchDownloaderWPF/PageQueue.xaml.cs @@ -33,13 +33,6 @@ public PageQueue() taskManager.DoWork += TaskManager_DoWork; taskManager.RunWorkerAsync(); - - taskList.CollectionChanged += TaskList_CollectionChanged; - } - - private void TaskList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) - { - } private void TaskManager_DoWork(object sender, DoWorkEventArgs e) From 71d0cf19f36cb3eb78175e1fad4aa2f338ddb285 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:17:38 -0400 Subject: [PATCH 03/14] Add missing access modifiers --- TwitchDownloaderCore/TwitchHelper.cs | 2 +- TwitchDownloaderWPF/PageQueue.xaml.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index ecedcc90..fefeeabe 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -105,7 +105,7 @@ public static async Task GetVideoPlaylist(long videoId, string token, st return await response.Content.ReadAsStringAsync(); } - static bool IsAuthException(Exception ex) + private static bool IsAuthException(Exception ex) { while (ex != null) { diff --git a/TwitchDownloaderWPF/PageQueue.xaml.cs b/TwitchDownloaderWPF/PageQueue.xaml.cs index d64a5fb8..cf99bb67 100644 --- a/TwitchDownloaderWPF/PageQueue.xaml.cs +++ b/TwitchDownloaderWPF/PageQueue.xaml.cs @@ -17,7 +17,7 @@ namespace TwitchDownloaderWPF /// public partial class PageQueue : Page { - public static object taskLock = new object(); + public static readonly object taskLock = new object(); public static ObservableCollection taskList { get; set; } = new ObservableCollection(); BackgroundWorker taskManager = new BackgroundWorker(); From 642ffade12ac3bf91497566261e84765b9b60361 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:18:54 -0400 Subject: [PATCH 04/14] Suppress naming issues --- TwitchDownloaderWPF/Services/AvailableCultures.cs | 2 +- TwitchDownloaderWPF/Services/NativeFunctions.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/TwitchDownloaderWPF/Services/AvailableCultures.cs b/TwitchDownloaderWPF/Services/AvailableCultures.cs index 9b257903..c7056860 100644 --- a/TwitchDownloaderWPF/Services/AvailableCultures.cs +++ b/TwitchDownloaderWPF/Services/AvailableCultures.cs @@ -49,6 +49,6 @@ static AvailableCultures() SimplifiedChinese = new Culture("zh-CN", "简体中文"), }; } - // ReSharper enable StringLiteralTypo + // ReSharper restore StringLiteralTypo } } diff --git a/TwitchDownloaderWPF/Services/NativeFunctions.cs b/TwitchDownloaderWPF/Services/NativeFunctions.cs index 5be4c370..aa788fc4 100644 --- a/TwitchDownloaderWPF/Services/NativeFunctions.cs +++ b/TwitchDownloaderWPF/Services/NativeFunctions.cs @@ -27,12 +27,14 @@ public record struct FlashWInfo public uint FlashCount; public uint Timeout; + // ReSharper disable InconsistentNaming public const uint FLASHW_STOP = 0; public const uint FLASHW_CAPTION = 1; public const uint FLASHW_TRAY = 2; public const uint FLASHW_ALL = 3; public const uint FLASHW_TIMER = 4; public const uint FLASHW_TIMERNOFG = 12; + // ReSharper restore InconsistentNaming } } } \ No newline at end of file From ba059f061162fcff082f02ba29eb991a7b918bc2 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:19:13 -0400 Subject: [PATCH 05/14] Fix bad string key names in japanese --- TwitchDownloaderWPF/Translations/Strings.ja.resx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TwitchDownloaderWPF/Translations/Strings.ja.resx b/TwitchDownloaderWPF/Translations/Strings.ja.resx index 8ee84dcb..015c1b67 100644 --- a/TwitchDownloaderWPF/Translations/Strings.ja.resx +++ b/TwitchDownloaderWPF/Translations/Strings.ja.resx @@ -239,7 +239,7 @@ ダウンロード - + コネクション: @@ -248,7 +248,7 @@ ダウンロードフォーマット: - + ダウンロードスレッド: From 8c292fb532040310b1401c52fa72bc977e37665b Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:22:58 -0400 Subject: [PATCH 06/14] Fix ArgumentException args --- TwitchDownloaderCore/Extensions/M3U8Extensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TwitchDownloaderCore/Extensions/M3U8Extensions.cs b/TwitchDownloaderCore/Extensions/M3U8Extensions.cs index 3ef590fb..b27526d5 100644 --- a/TwitchDownloaderCore/Extensions/M3U8Extensions.cs +++ b/TwitchDownloaderCore/Extensions/M3U8Extensions.cs @@ -28,7 +28,7 @@ public static M3U8.Stream GetStreamOfQuality(this M3U8 m3u8, string qualityStrin { if (m3u8.Streams.Length == 0) { - throw new ArgumentException(nameof(m3u8), "M3U8 does not contain any streams."); + throw new ArgumentException("M3U8 does not contain any streams.", nameof(m3u8)); } if (TryGetKeywordStream(m3u8, qualityString, out var keywordStream)) From f990ffbd9a0777ca8863604d230b40a1598d75cf Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:24:03 -0400 Subject: [PATCH 07/14] Use type keyword --- TwitchDownloaderCore/TwitchHelper.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index fefeeabe..5307dc77 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -566,7 +566,7 @@ public static async Task> GetEmotes(List comments, st var nameList = comments.Where(comment => comment.message.user_badges != null) .SelectMany(comment => comment.message.user_badges) - .Where(badge => !String.IsNullOrWhiteSpace(badge._id)) + .Where(badge => !string.IsNullOrWhiteSpace(badge._id)) .Where(badge => globalBadges.ContainsKey(badge._id) || subBadges.ContainsKey(badge._id)) .Select(badge => badge._id).Distinct(); @@ -1027,7 +1027,7 @@ public static async Task GetUserInfo(IEnumerable id { RequestUri = new Uri("https://gql.twitch.tv/gql"), Method = HttpMethod.Post, - Content = new StringContent("{\"query\":\"query{users(ids:[" + String.Join(",", idList.Select(x => "\\\"" + x + "\\\"").ToArray()) + "]){id,login,createdAt,updatedAt,description,profileImageURL(width:300)}}\",\"variables\":{}}", Encoding.UTF8, "application/json") + Content = new StringContent("{\"query\":\"query{users(ids:[" + string.Join(",", idList.Select(x => "\\\"" + x + "\\\"").ToArray()) + "]){id,login,createdAt,updatedAt,description,profileImageURL(width:300)}}\",\"variables\":{}}", Encoding.UTF8, "application/json") }; request.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko"); using var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); @@ -1077,7 +1077,7 @@ public static async Task GetImage(DirectoryInfo cacheDir, string imageUr } catch (Exception e) when (e is IOException or SecurityException) { - // File being written to by parallel process? Maybe. Can just fallback to HTTP request. + // File being written to by parallel process? Maybe. Can just fall back to HTTP request. logger.LogVerbose($"Failed to read from or delete {file.Name}: {e.Message}"); } } From 7dcad4f2197f48c32f43c072dc608bfbf1670025 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:25:06 -0400 Subject: [PATCH 08/14] Remove unused imports --- TwitchDownloaderCore/TsMerger.cs | 3 +-- .../TwitchObjects/Api/BTTVChannelEmoteResponse.cs | 6 +----- .../TwitchObjects/Api/STVChannelEmoteResponse.cs | 6 +----- .../TwitchObjects/Api/STVGlobalEmoteResponse.cs | 6 +----- TwitchDownloaderCore/TwitchObjects/GifEmote.cs | 3 --- .../TwitchObjects/Gql/GqlBadgeResponse.cs | 6 +----- .../TwitchObjects/Gql/GqlCheerResponse.cs | 4 +--- .../TwitchObjects/Gql/GqlCommentResponse.cs | 3 --- .../TwitchObjects/Gql/GqlUserInfoResponse.cs | 3 --- .../TwitchObjects/Gql/GqlVideoTokenResponse.cs | 8 +------- TwitchDownloaderCore/TwitchObjects/TwitchComment.cs | 2 -- TwitchDownloaderCore/TwitchObjects/UpdateFrame.cs | 4 ---- TwitchDownloaderCore/VideoDownloader.cs | 1 - TwitchDownloaderWPF/PageClipDownload.xaml.cs | 1 - TwitchDownloaderWPF/PageQueue.xaml.cs | 3 +-- 15 files changed, 8 insertions(+), 51 deletions(-) diff --git a/TwitchDownloaderCore/TsMerger.cs b/TwitchDownloaderCore/TsMerger.cs index c10030c2..dcc4c374 100644 --- a/TwitchDownloaderCore/TsMerger.cs +++ b/TwitchDownloaderCore/TsMerger.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; diff --git a/TwitchDownloaderCore/TwitchObjects/Api/BTTVChannelEmoteResponse.cs b/TwitchDownloaderCore/TwitchObjects/Api/BTTVChannelEmoteResponse.cs index 2c91158f..75a0cb04 100644 --- a/TwitchDownloaderCore/TwitchObjects/Api/BTTVChannelEmoteResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Api/BTTVChannelEmoteResponse.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace TwitchDownloaderCore.TwitchObjects.Api { diff --git a/TwitchDownloaderCore/TwitchObjects/Api/STVChannelEmoteResponse.cs b/TwitchDownloaderCore/TwitchObjects/Api/STVChannelEmoteResponse.cs index 2ff6ad14..85b11300 100644 --- a/TwitchDownloaderCore/TwitchObjects/Api/STVChannelEmoteResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Api/STVChannelEmoteResponse.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace TwitchDownloaderCore.TwitchObjects.Api { diff --git a/TwitchDownloaderCore/TwitchObjects/Api/STVGlobalEmoteResponse.cs b/TwitchDownloaderCore/TwitchObjects/Api/STVGlobalEmoteResponse.cs index dbe6b7b7..f8af0f92 100644 --- a/TwitchDownloaderCore/TwitchObjects/Api/STVGlobalEmoteResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Api/STVGlobalEmoteResponse.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace TwitchDownloaderCore.TwitchObjects.Api { diff --git a/TwitchDownloaderCore/TwitchObjects/GifEmote.cs b/TwitchDownloaderCore/TwitchObjects/GifEmote.cs index 595e6110..4b74705f 100644 --- a/TwitchDownloaderCore/TwitchObjects/GifEmote.cs +++ b/TwitchDownloaderCore/TwitchObjects/GifEmote.cs @@ -1,9 +1,6 @@ using SkiaSharp; -using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; -using System.Text; namespace TwitchDownloaderCore.TwitchObjects { diff --git a/TwitchDownloaderCore/TwitchObjects/Gql/GqlBadgeResponse.cs b/TwitchDownloaderCore/TwitchObjects/Gql/GqlBadgeResponse.cs index f64e2a61..366e8de1 100644 --- a/TwitchDownloaderCore/TwitchObjects/Gql/GqlBadgeResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Gql/GqlBadgeResponse.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; using System.Text.Json.Serialization; -using System.Threading.Tasks; namespace TwitchDownloaderCore.TwitchObjects.Gql { diff --git a/TwitchDownloaderCore/TwitchObjects/Gql/GqlCheerResponse.cs b/TwitchDownloaderCore/TwitchObjects/Gql/GqlCheerResponse.cs index 21feda0c..410692df 100644 --- a/TwitchDownloaderCore/TwitchObjects/Gql/GqlCheerResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Gql/GqlCheerResponse.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace TwitchDownloaderCore.TwitchObjects.Gql { diff --git a/TwitchDownloaderCore/TwitchObjects/Gql/GqlCommentResponse.cs b/TwitchDownloaderCore/TwitchObjects/Gql/GqlCommentResponse.cs index 165a4348..5cff89fc 100644 --- a/TwitchDownloaderCore/TwitchObjects/Gql/GqlCommentResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Gql/GqlCommentResponse.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace TwitchDownloaderCore.TwitchObjects.Gql { diff --git a/TwitchDownloaderCore/TwitchObjects/Gql/GqlUserInfoResponse.cs b/TwitchDownloaderCore/TwitchObjects/Gql/GqlUserInfoResponse.cs index bff2cbaf..2f228c90 100644 --- a/TwitchDownloaderCore/TwitchObjects/Gql/GqlUserInfoResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Gql/GqlUserInfoResponse.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace TwitchDownloaderCore.TwitchObjects.Gql { diff --git a/TwitchDownloaderCore/TwitchObjects/Gql/GqlVideoTokenResponse.cs b/TwitchDownloaderCore/TwitchObjects/Gql/GqlVideoTokenResponse.cs index d223a73d..05083e94 100644 --- a/TwitchDownloaderCore/TwitchObjects/Gql/GqlVideoTokenResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Gql/GqlVideoTokenResponse.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TwitchDownloaderCore.TwitchObjects.Gql +namespace TwitchDownloaderCore.TwitchObjects.Gql { public class GqlVideoData { diff --git a/TwitchDownloaderCore/TwitchObjects/TwitchComment.cs b/TwitchDownloaderCore/TwitchObjects/TwitchComment.cs index 2a13c886..101dac9d 100644 --- a/TwitchDownloaderCore/TwitchObjects/TwitchComment.cs +++ b/TwitchDownloaderCore/TwitchObjects/TwitchComment.cs @@ -1,7 +1,5 @@ using SkiaSharp; -using System; using System.Collections.Generic; -using System.Text; namespace TwitchDownloaderCore.TwitchObjects { diff --git a/TwitchDownloaderCore/TwitchObjects/UpdateFrame.cs b/TwitchDownloaderCore/TwitchObjects/UpdateFrame.cs index 2f91e0b5..ffbe47d1 100644 --- a/TwitchDownloaderCore/TwitchObjects/UpdateFrame.cs +++ b/TwitchDownloaderCore/TwitchObjects/UpdateFrame.cs @@ -1,9 +1,5 @@ using SkiaSharp; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace TwitchDownloaderCore.TwitchObjects { diff --git a/TwitchDownloaderCore/VideoDownloader.cs b/TwitchDownloaderCore/VideoDownloader.cs index 3069c08b..aab696de 100644 --- a/TwitchDownloaderCore/VideoDownloader.cs +++ b/TwitchDownloaderCore/VideoDownloader.cs @@ -5,7 +5,6 @@ using System.Globalization; using System.IO; using System.Linq; -using System.Net; using System.Net.Http; using System.Text; using System.Text.RegularExpressions; diff --git a/TwitchDownloaderWPF/PageClipDownload.xaml.cs b/TwitchDownloaderWPF/PageClipDownload.xaml.cs index 42fd3f3a..06b7770d 100644 --- a/TwitchDownloaderWPF/PageClipDownload.xaml.cs +++ b/TwitchDownloaderWPF/PageClipDownload.xaml.cs @@ -1,6 +1,5 @@ using Microsoft.Win32; using System; -using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Threading; diff --git a/TwitchDownloaderWPF/PageQueue.xaml.cs b/TwitchDownloaderWPF/PageQueue.xaml.cs index cf99bb67..4ab7508d 100644 --- a/TwitchDownloaderWPF/PageQueue.xaml.cs +++ b/TwitchDownloaderWPF/PageQueue.xaml.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.ObjectModel; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Threading; using System.Windows; From 01bfd515f14a8e92ffdb018ca8bfcb7924d45560 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:26:22 -0400 Subject: [PATCH 09/14] Lower finalization retry timeout to 5 seconds --- TwitchDownloaderCore/VideoDownloader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TwitchDownloaderCore/VideoDownloader.cs b/TwitchDownloaderCore/VideoDownloader.cs index aab696de..eecb1d74 100644 --- a/TwitchDownloaderCore/VideoDownloader.cs +++ b/TwitchDownloaderCore/VideoDownloader.cs @@ -121,8 +121,8 @@ await FfmpegMetadata.SerializeAsync(metadataPath, videoInfo.owner.displayName, d ffmpegExitCode = await RunFfmpegVideoCopy(downloadFolder, outputFileInfo, concatListPath, metadataPath, startOffset, endDuration, videoLength, ffmpegRetries > 0, cancellationToken); if (ffmpegExitCode != 0) { - _progress.LogError($"Failed to finalize video (code {ffmpegExitCode}), retrying in 10 seconds..."); - await Task.Delay(10_000, cancellationToken); + _progress.LogError($"Failed to finalize video (code {ffmpegExitCode}), retrying in 5 seconds..."); + await Task.Delay(5_000, cancellationToken); } } while (ffmpegExitCode != 0 && ffmpegRetries++ < 1); From 8cd4a82adf2e15d2f5e0ff433131d0f7037ce5f9 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:32:45 -0400 Subject: [PATCH 10/14] Delete `__typename`s --- .../TwitchObjects/Gql/GqlClipTokenResponse.cs | 3 --- .../TwitchObjects/Gql/GqlCommentResponse.cs | 12 ------------ .../TwitchObjects/Gql/GqlVideoTokenResponse.cs | 1 - 3 files changed, 16 deletions(-) diff --git a/TwitchDownloaderCore/TwitchObjects/Gql/GqlClipTokenResponse.cs b/TwitchDownloaderCore/TwitchObjects/Gql/GqlClipTokenResponse.cs index 1e909c1e..97fbce66 100644 --- a/TwitchDownloaderCore/TwitchObjects/Gql/GqlClipTokenResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Gql/GqlClipTokenResponse.cs @@ -5,7 +5,6 @@ public class ClipToken public string id { get; set; } public PlaybackAccessToken playbackAccessToken { get; set; } public VideoQuality[] videoQualities { get; set; } - public string __typename { get; set; } } public class ClipTokenData @@ -17,7 +16,6 @@ public class PlaybackAccessToken { public string signature { get; set; } public string value { get; set; } - public string __typename { get; set; } } public class GqlClipTokenResponse @@ -31,6 +29,5 @@ public class VideoQuality public double frameRate { get; set; } public string quality { get; set; } public string sourceURL { get; set; } - public string __typename { get; set; } } } diff --git a/TwitchDownloaderCore/TwitchObjects/Gql/GqlCommentResponse.cs b/TwitchDownloaderCore/TwitchObjects/Gql/GqlCommentResponse.cs index 5cff89fc..6c6a04f5 100644 --- a/TwitchDownloaderCore/TwitchObjects/Gql/GqlCommentResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Gql/GqlCommentResponse.cs @@ -6,7 +6,6 @@ namespace TwitchDownloaderCore.TwitchObjects.Gql public class CommentChannel { public string id { get; set; } - public string __typename { get; set; } } public class CommentCommenter @@ -14,21 +13,18 @@ public class CommentCommenter public string id { get; set; } public string login { get; set; } public string displayName { get; set; } - public string __typename { get; set; } } public class CommentComments { public List edges { get; set; } public CommentPageInfo pageInfo { get; set; } - public string __typename { get; set; } } public class Creator { public string id { get; set; } public CommentChannel channel { get; set; } - public string __typename { get; set; } } public class CommentData @@ -40,14 +36,12 @@ public class CommentEdge { public string cursor { get; set; } public CommentNode node { get; set; } - public string __typename { get; set; } } public class CommentFragment { public CommentEmote emote { get; set; } public string text { get; set; } - public string __typename { get; set; } } public class CommentEmote @@ -55,7 +49,6 @@ public class CommentEmote public string id { get; set; } public string emoteID { get; set; } public int from { get; set; } - public string __typename { get; set; } } public class CommentMessage @@ -63,7 +56,6 @@ public class CommentMessage public List fragments { get; set; } public List userBadges { get; set; } public string userColor { get; set; } - public string __typename { get; set; } } public class CommentNode @@ -73,14 +65,12 @@ public class CommentNode public int contentOffsetSeconds { get; set; } public DateTime createdAt { get; set; } public CommentMessage message { get; set; } - public string __typename { get; set; } } public class CommentPageInfo { public bool hasNextPage { get; set; } public bool hasPreviousPage { get; set; } - public string __typename { get; set; } } public class GqlCommentResponse @@ -94,7 +84,6 @@ public class CommentUserBadge public string id { get; set; } public string setID { get; set; } public string version { get; set; } - public string __typename { get; set; } } public class CommentVideo @@ -102,6 +91,5 @@ public class CommentVideo public string id { get; set; } public Creator creator { get; set; } public CommentComments comments { get; set; } - public string __typename { get; set; } } } diff --git a/TwitchDownloaderCore/TwitchObjects/Gql/GqlVideoTokenResponse.cs b/TwitchDownloaderCore/TwitchObjects/Gql/GqlVideoTokenResponse.cs index 05083e94..fd2f4690 100644 --- a/TwitchDownloaderCore/TwitchObjects/Gql/GqlVideoTokenResponse.cs +++ b/TwitchDownloaderCore/TwitchObjects/Gql/GqlVideoTokenResponse.cs @@ -15,6 +15,5 @@ public class VideoPlaybackAccessToken { public string value { get; set; } public string signature { get; set; } - public string __typename { get; set; } } } From 950c97cfec1f8338d49dd68eddcce445f33fbcdc Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:44:10 -0400 Subject: [PATCH 11/14] Delete unused classes --- .../TwitchObjects/GifEmote.cs | 63 ------------------- .../TwitchObjects/TwitchComment.cs | 14 ----- 2 files changed, 77 deletions(-) delete mode 100644 TwitchDownloaderCore/TwitchObjects/GifEmote.cs delete mode 100644 TwitchDownloaderCore/TwitchObjects/TwitchComment.cs diff --git a/TwitchDownloaderCore/TwitchObjects/GifEmote.cs b/TwitchDownloaderCore/TwitchObjects/GifEmote.cs deleted file mode 100644 index 4b74705f..00000000 --- a/TwitchDownloaderCore/TwitchObjects/GifEmote.cs +++ /dev/null @@ -1,63 +0,0 @@ -using SkiaSharp; -using System.Collections.Generic; -using System.Linq; - -namespace TwitchDownloaderCore.TwitchObjects -{ - public class GifEmote - { - public Point Offset { get; set; } - public string Name { get; set; } - public SKCodec Codec { get; set; } - public int FrameCount { get; set; } - public List DurationList { get; set; } - public int TotalDuration { get; set; } - public int ImageScale { get; set; } - public int Width { get; set; } - public int Height { get; set; } - public List ImageFrames { get; set; } - public SKBitmap BackgroundImage { get; set; } - - public GifEmote(Point offset, string name, SKCodec codec, int imageScale, List imageFrames) - { - Offset = offset; - Name = name; - Codec = codec; - ImageScale = imageScale; - ImageFrames = imageFrames; - FrameCount = codec.FrameCount; - - DurationList = new List(); - for (int i = 0; i < FrameCount; i++) - { - var duration = Codec.FrameInfo[i].Duration / 10; - DurationList.Add(duration); - TotalDuration += duration; - } - - if (TotalDuration == 0 || TotalDuration == FrameCount) - { - for (int i = 0; i < DurationList.Count; i++) - { - DurationList.RemoveAt(i); - DurationList.Insert(i, 10); - } - TotalDuration = DurationList.Count * 10; - } - - for (int i = 0; i < DurationList.Count; i++) - { - if (DurationList[i] == 0) - { - TotalDuration += 10; - DurationList[i] = 10; - } - } - - Width = ImageFrames.First().Width; - Height = ImageFrames.First().Height; - - imageScale = ImageScale; - } - } -} diff --git a/TwitchDownloaderCore/TwitchObjects/TwitchComment.cs b/TwitchDownloaderCore/TwitchObjects/TwitchComment.cs deleted file mode 100644 index 101dac9d..00000000 --- a/TwitchDownloaderCore/TwitchObjects/TwitchComment.cs +++ /dev/null @@ -1,14 +0,0 @@ -using SkiaSharp; -using System.Collections.Generic; - -namespace TwitchDownloaderCore.TwitchObjects -{ - public class TwitchComment - { - public string Section { get; set; } - public double SecondsOffset { get; set; } - public List GifEmotes { get; set; } - public List NormalEmotes { get; set; } - public List NormalEmotesPositions { get; set; } - } -} From ebce32ee9347352970c1462f4ac0ee9ac62b31f4 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:44:21 -0400 Subject: [PATCH 12/14] Remove redundant qualifiers --- TwitchDownloaderCore/Tools/M3U8Parse.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TwitchDownloaderCore/Tools/M3U8Parse.cs b/TwitchDownloaderCore/Tools/M3U8Parse.cs index dfa45e0a..1d5186f9 100644 --- a/TwitchDownloaderCore/Tools/M3U8Parse.cs +++ b/TwitchDownloaderCore/Tools/M3U8Parse.cs @@ -283,9 +283,9 @@ public static ExtByteRange Parse(ReadOnlySpan text) public partial record ExtMediaInfo { - public static Stream.ExtMediaInfo Parse(ReadOnlySpan text) + public static ExtMediaInfo Parse(ReadOnlySpan text) { - var mediaInfo = new Stream.ExtMediaInfo(); + var mediaInfo = new ExtMediaInfo(); if (text.StartsWith(MEDIA_INFO_KEY)) text = text[13..]; From 4cb10f19a6fb16a6c803256f4467a6336dd16643 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:44:30 -0400 Subject: [PATCH 13/14] Remove redundant variable --- TwitchDownloaderCore/TsMerger.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/TwitchDownloaderCore/TsMerger.cs b/TwitchDownloaderCore/TsMerger.cs index dcc4c374..59c86252 100644 --- a/TwitchDownloaderCore/TsMerger.cs +++ b/TwitchDownloaderCore/TsMerger.cs @@ -134,7 +134,6 @@ private static async Task VerifyVideoPart(string filePath) private async Task CombineVideoParts(IReadOnlyCollection fileList, FileStream outputStream, CancellationToken cancellationToken) { DriveInfo outputDrive = DriveHelper.GetOutputDrive(mergeOptions.OutputFile); - string outputFile = mergeOptions.OutputFile; int partCount = fileList.Count; int doneCount = 0; From bb7058545541e9b1f20fa9c5bef1ead6f48285da Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:44:51 -0400 Subject: [PATCH 14/14] Rename test constants --- .../ToolTests/M3U8Tests.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/TwitchDownloaderCore.Tests/ToolTests/M3U8Tests.cs b/TwitchDownloaderCore.Tests/ToolTests/M3U8Tests.cs index e9a14cde..2855a5d2 100644 --- a/TwitchDownloaderCore.Tests/ToolTests/M3U8Tests.cs +++ b/TwitchDownloaderCore.Tests/ToolTests/M3U8Tests.cs @@ -14,7 +14,7 @@ public class M3U8Tests [InlineData(true, "ru-RU")] public void CorrectlyParsesTwitchM3U8OfTransportStreams(bool useStream, string culture) { - const string ExampleM3U8Twitch = + const string EXAMPLE_M3U8_TWITCH = "#EXTM3U" + "\n#EXT-X-VERSION:3" + "\n#EXT-X-TARGETDURATION:10" + @@ -37,13 +37,13 @@ public void CorrectlyParsesTwitchM3U8OfTransportStreams(bool useStream, string c M3U8 m3u8; if (useStream) { - var bytes = Encoding.Unicode.GetBytes(ExampleM3U8Twitch); + var bytes = Encoding.Unicode.GetBytes(EXAMPLE_M3U8_TWITCH); using var ms = new MemoryStream(bytes); m3u8 = M3U8.Parse(ms, Encoding.Unicode); } else { - m3u8 = M3U8.Parse(ExampleM3U8Twitch); + m3u8 = M3U8.Parse(EXAMPLE_M3U8_TWITCH); } CultureInfo.CurrentCulture = oldCulture; @@ -73,7 +73,7 @@ public void CorrectlyParsesTwitchM3U8OfTransportStreams(bool useStream, string c [InlineData(true, "ru-RU")] public void CorrectlyParsesTwitchM3U8OfLiveStreams(bool useStream, string culture) { - const string ExampleM3U8Twitch = + const string EXAMPLE_M3U8_TWITCH = "#EXTM3U" + "\n#EXT-X-VERSION:3" + "\n#EXT-X-TARGETDURATION:5" + @@ -129,13 +129,13 @@ public void CorrectlyParsesTwitchM3U8OfLiveStreams(bool useStream, string cultur M3U8 m3u8; if (useStream) { - var bytes = Encoding.Unicode.GetBytes(ExampleM3U8Twitch); + var bytes = Encoding.Unicode.GetBytes(EXAMPLE_M3U8_TWITCH); using var ms = new MemoryStream(bytes); m3u8 = M3U8.Parse(ms, Encoding.Unicode); } else { - m3u8 = M3U8.Parse(ExampleM3U8Twitch); + m3u8 = M3U8.Parse(EXAMPLE_M3U8_TWITCH); } CultureInfo.CurrentCulture = oldCulture; @@ -167,7 +167,7 @@ public void CorrectlyParsesTwitchM3U8OfLiveStreams(bool useStream, string cultur [InlineData(true, "ru-RU")] public void CorrectlyParsesTwitchM3U8OfPlaylists(bool useStream, string culture) { - const string ExampleM3U8Twitch = + const string EXAMPLE_M3U8_TWITCH = "#EXTM3U" + "\n#EXT-X-TWITCH-INFO:ORIGIN=\"s3\",B=\"false\",REGION=\"NA\",USER-IP=\"255.255.255.255\",SERVING-ID=\"123abc456def789ghi012jkl345mno67\",CLUSTER=\"cloudfront_vod\",USER-COUNTRY=\"US\",MANIFEST-CLUSTER=\"cloudfront_vod\"" + "\n#EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID=\"chunked\",NAME=\"1080p60\",AUTOSELECT=NO,DEFAULT=NO" + @@ -217,13 +217,13 @@ public void CorrectlyParsesTwitchM3U8OfPlaylists(bool useStream, string culture) M3U8 m3u8; if (useStream) { - var bytes = Encoding.Unicode.GetBytes(ExampleM3U8Twitch); + var bytes = Encoding.Unicode.GetBytes(EXAMPLE_M3U8_TWITCH); using var ms = new MemoryStream(bytes); m3u8 = M3U8.Parse(ms, Encoding.Unicode); } else { - m3u8 = M3U8.Parse(ExampleM3U8Twitch); + m3u8 = M3U8.Parse(EXAMPLE_M3U8_TWITCH); } CultureInfo.CurrentCulture = oldCulture; @@ -280,7 +280,7 @@ public void CorrectlyParsesTwitchM3U8StreamInfo(string streamInfoString, int ban [InlineData(true, "ru-RU")] public void CorrectlyParsesKickM3U8OfTransportStreams(bool useStream, string culture) { - const string ExampleM3U8Kick = + const string EXAMPLE_M3U8_KICK = "#EXTM3U" + "\n#EXT-X-VERSION:4" + "\n#EXT-X-MEDIA-SEQUENCE:0" + @@ -343,13 +343,13 @@ public void CorrectlyParsesKickM3U8OfTransportStreams(bool useStream, string cul M3U8 m3u8; if (useStream) { - var bytes = Encoding.Unicode.GetBytes(ExampleM3U8Kick); + var bytes = Encoding.Unicode.GetBytes(EXAMPLE_M3U8_KICK); using var ms = new MemoryStream(bytes); m3u8 = M3U8.Parse(ms, Encoding.Unicode); } else { - m3u8 = M3U8.Parse(ExampleM3U8Kick); + m3u8 = M3U8.Parse(EXAMPLE_M3U8_KICK); } CultureInfo.CurrentCulture = oldCulture; @@ -378,7 +378,7 @@ public void CorrectlyParsesKickM3U8OfTransportStreams(bool useStream, string cul [InlineData(true, "ru-RU")] public void CorrectlyParsesKickM3U8OfPlaylists(bool useStream, string culture) { - const string ExampleM3U8Kick = + const string EXAMPLE_M3U8_KICK = "#EXTM3U" + "\n#EXT-X-SESSION-DATA:DATA-ID=\"net.live-video.content.id\",VALUE=\"AbC123dEf456\"" + "\n#EXT-X-SESSION-DATA:DATA-ID=\"net.live-video.customer.id\",VALUE=\"123456789012\"" + @@ -423,13 +423,13 @@ public void CorrectlyParsesKickM3U8OfPlaylists(bool useStream, string culture) M3U8 m3u8; if (useStream) { - var bytes = Encoding.Unicode.GetBytes(ExampleM3U8Kick); + var bytes = Encoding.Unicode.GetBytes(EXAMPLE_M3U8_KICK); using var ms = new MemoryStream(bytes); m3u8 = M3U8.Parse(ms, Encoding.Unicode); } else { - m3u8 = M3U8.Parse(ExampleM3U8Kick); + m3u8 = M3U8.Parse(EXAMPLE_M3U8_KICK); } CultureInfo.CurrentCulture = oldCulture;