From 2627848820e2fa53acf40263b06696d46dc1ca91 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:14:16 -0500 Subject: [PATCH 1/5] Move FilenameService to TwitchDownloaderCore.Services namespace --- TwitchDownloaderCLI/Modes/DownloadVideo.cs | 1 + TwitchDownloaderCLI/Tools/FileCollisionHandler.cs | 2 +- .../{ToolTests => ServiceTests}/FilenameServiceTests.cs | 4 ++-- TwitchDownloaderCore/{Tools => Services}/FilenameService.cs | 3 ++- TwitchDownloaderWPF/PageChatDownload.xaml.cs | 1 + TwitchDownloaderWPF/PageChatUpdate.xaml.cs | 1 + TwitchDownloaderWPF/PageClipDownload.xaml.cs | 1 + TwitchDownloaderWPF/PageVodDownload.xaml.cs | 1 + TwitchDownloaderWPF/Services/FileCollisionService.cs | 2 +- TwitchDownloaderWPF/WindowQueueOptions.xaml.cs | 1 + 10 files changed, 12 insertions(+), 5 deletions(-) rename TwitchDownloaderCore.Tests/{ToolTests => ServiceTests}/FilenameServiceTests.cs (99%) rename TwitchDownloaderCore/{Tools => Services}/FilenameService.cs (99%) diff --git a/TwitchDownloaderCLI/Modes/DownloadVideo.cs b/TwitchDownloaderCLI/Modes/DownloadVideo.cs index df291fad..ad367404 100644 --- a/TwitchDownloaderCLI/Modes/DownloadVideo.cs +++ b/TwitchDownloaderCLI/Modes/DownloadVideo.cs @@ -7,6 +7,7 @@ using TwitchDownloaderCore; using TwitchDownloaderCore.Interfaces; using TwitchDownloaderCore.Options; +using TwitchDownloaderCore.Services; using TwitchDownloaderCore.Tools; namespace TwitchDownloaderCLI.Modes diff --git a/TwitchDownloaderCLI/Tools/FileCollisionHandler.cs b/TwitchDownloaderCLI/Tools/FileCollisionHandler.cs index 0d6ab36a..e73e6e60 100644 --- a/TwitchDownloaderCLI/Tools/FileCollisionHandler.cs +++ b/TwitchDownloaderCLI/Tools/FileCollisionHandler.cs @@ -3,7 +3,7 @@ using TwitchDownloaderCLI.Models; using TwitchDownloaderCLI.Modes.Arguments; using TwitchDownloaderCore.Interfaces; -using TwitchDownloaderCore.Tools; +using TwitchDownloaderCore.Services; namespace TwitchDownloaderCLI.Tools { diff --git a/TwitchDownloaderCore.Tests/ToolTests/FilenameServiceTests.cs b/TwitchDownloaderCore.Tests/ServiceTests/FilenameServiceTests.cs similarity index 99% rename from TwitchDownloaderCore.Tests/ToolTests/FilenameServiceTests.cs rename to TwitchDownloaderCore.Tests/ServiceTests/FilenameServiceTests.cs index 8765975b..7a346abf 100644 --- a/TwitchDownloaderCore.Tests/ToolTests/FilenameServiceTests.cs +++ b/TwitchDownloaderCore.Tests/ServiceTests/FilenameServiceTests.cs @@ -1,6 +1,6 @@ -using TwitchDownloaderCore.Tools; +using TwitchDownloaderCore.Services; -namespace TwitchDownloaderCore.Tests.ToolTests +namespace TwitchDownloaderCore.Tests.ServiceTests { public class FilenameServiceTests { diff --git a/TwitchDownloaderCore/Tools/FilenameService.cs b/TwitchDownloaderCore/Services/FilenameService.cs similarity index 99% rename from TwitchDownloaderCore/Tools/FilenameService.cs rename to TwitchDownloaderCore/Services/FilenameService.cs index 4ba70011..477c3e75 100644 --- a/TwitchDownloaderCore/Tools/FilenameService.cs +++ b/TwitchDownloaderCore/Services/FilenameService.cs @@ -5,8 +5,9 @@ using System.Text; using System.Text.RegularExpressions; using TwitchDownloaderCore.Extensions; +using TwitchDownloaderCore.Tools; -namespace TwitchDownloaderCore.Tools +namespace TwitchDownloaderCore.Services { public static class FilenameService { diff --git a/TwitchDownloaderWPF/PageChatDownload.xaml.cs b/TwitchDownloaderWPF/PageChatDownload.xaml.cs index a3333536..80592ee8 100644 --- a/TwitchDownloaderWPF/PageChatDownload.xaml.cs +++ b/TwitchDownloaderWPF/PageChatDownload.xaml.cs @@ -11,6 +11,7 @@ using System.Windows.Media.Imaging; using TwitchDownloaderCore; using TwitchDownloaderCore.Options; +using TwitchDownloaderCore.Services; using TwitchDownloaderCore.Tools; using TwitchDownloaderCore.TwitchObjects.Gql; using TwitchDownloaderWPF.Models; diff --git a/TwitchDownloaderWPF/PageChatUpdate.xaml.cs b/TwitchDownloaderWPF/PageChatUpdate.xaml.cs index dc682d61..09edf21c 100644 --- a/TwitchDownloaderWPF/PageChatUpdate.xaml.cs +++ b/TwitchDownloaderWPF/PageChatUpdate.xaml.cs @@ -12,6 +12,7 @@ using TwitchDownloaderCore; using TwitchDownloaderCore.Chat; using TwitchDownloaderCore.Options; +using TwitchDownloaderCore.Services; using TwitchDownloaderCore.Tools; using TwitchDownloaderCore.TwitchObjects; using TwitchDownloaderCore.TwitchObjects.Gql; diff --git a/TwitchDownloaderWPF/PageClipDownload.xaml.cs b/TwitchDownloaderWPF/PageClipDownload.xaml.cs index 3a98693b..a34ca344 100644 --- a/TwitchDownloaderWPF/PageClipDownload.xaml.cs +++ b/TwitchDownloaderWPF/PageClipDownload.xaml.cs @@ -10,6 +10,7 @@ using System.Windows.Media.Imaging; using TwitchDownloaderCore; using TwitchDownloaderCore.Options; +using TwitchDownloaderCore.Services; using TwitchDownloaderCore.Tools; using TwitchDownloaderCore.TwitchObjects.Gql; using TwitchDownloaderWPF.Models; diff --git a/TwitchDownloaderWPF/PageVodDownload.xaml.cs b/TwitchDownloaderWPF/PageVodDownload.xaml.cs index 713d7cc6..7d98e169 100644 --- a/TwitchDownloaderWPF/PageVodDownload.xaml.cs +++ b/TwitchDownloaderWPF/PageVodDownload.xaml.cs @@ -16,6 +16,7 @@ using TwitchDownloaderCore; using TwitchDownloaderCore.Extensions; using TwitchDownloaderCore.Options; +using TwitchDownloaderCore.Services; using TwitchDownloaderCore.Tools; using TwitchDownloaderCore.TwitchObjects.Gql; using TwitchDownloaderWPF.Models; diff --git a/TwitchDownloaderWPF/Services/FileCollisionService.cs b/TwitchDownloaderWPF/Services/FileCollisionService.cs index 520d9e26..528e8640 100644 --- a/TwitchDownloaderWPF/Services/FileCollisionService.cs +++ b/TwitchDownloaderWPF/Services/FileCollisionService.cs @@ -3,7 +3,7 @@ using System.IO; using System.Windows; using Ookii.Dialogs.Wpf; -using TwitchDownloaderCore.Tools; +using TwitchDownloaderCore.Services; using TwitchDownloaderWPF.Models; using TwitchDownloaderWPF.Properties; diff --git a/TwitchDownloaderWPF/WindowQueueOptions.xaml.cs b/TwitchDownloaderWPF/WindowQueueOptions.xaml.cs index 51724eae..ef116239 100644 --- a/TwitchDownloaderWPF/WindowQueueOptions.xaml.cs +++ b/TwitchDownloaderWPF/WindowQueueOptions.xaml.cs @@ -7,6 +7,7 @@ using System.Windows.Media; using TwitchDownloaderCore; using TwitchDownloaderCore.Options; +using TwitchDownloaderCore.Services; using TwitchDownloaderCore.Tools; using TwitchDownloaderWPF.Properties; using TwitchDownloaderWPF.Services; From 7f249ddb33c5bd31c8cdc45493c8ae815432f233 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:16:41 -0500 Subject: [PATCH 2/5] Cleanup InfoHandler --- TwitchDownloaderCLI/Modes/InfoHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TwitchDownloaderCLI/Modes/InfoHandler.cs b/TwitchDownloaderCLI/Modes/InfoHandler.cs index 7d4ed846..fe373964 100644 --- a/TwitchDownloaderCLI/Modes/InfoHandler.cs +++ b/TwitchDownloaderCLI/Modes/InfoHandler.cs @@ -113,7 +113,6 @@ private static void HandleVodTable(GqlVideoResponse videoInfo, GqlVideoChapterRe const string DEFAULT_STRING = "-"; var infoVideo = videoInfo.data.video; - var hasBitrate = m3u8.Streams.Any(x => x.StreamInfo.Bandwidth != default); var infoTableTitle = new TableTitle("Video Info"); var infoTable = new Table() @@ -138,6 +137,7 @@ private static void HandleVodTable(GqlVideoResponse videoInfo, GqlVideoChapterRe .AddColumn(new TableColumn("FPS").RightAligned()) .AddColumn(new TableColumn("Codecs").RightAligned()); + var hasBitrate = m3u8.Streams.Any(x => x.StreamInfo.Bandwidth != default); if (hasBitrate) { streamTable @@ -154,7 +154,7 @@ private static void HandleVodTable(GqlVideoResponse videoInfo, GqlVideoChapterRe if (hasBitrate) { - var videoLength = TimeSpan.FromSeconds(videoInfo.data.video.lengthSeconds); + var videoLength = TimeSpan.FromSeconds(infoVideo.lengthSeconds); var bitrate = stream.StreamInfo.Bandwidth.StringifyOrDefault(x => $"{x / 1000}kbps", DEFAULT_STRING); var fileSize = stream.StreamInfo.Bandwidth.StringifyOrDefault(x => $"~{VideoSizeEstimator.StringifyByteCount(VideoSizeEstimator.EstimateVideoSize(x, TimeSpan.Zero, videoLength))}", DEFAULT_STRING); streamTable.AddRow(name, resolution, fps, codecs, bitrate, fileSize); From c54322b742815ab57c54ee4e3b01c9d971404cba Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:18:41 -0500 Subject: [PATCH 3/5] Use HashCode.Combine --- TwitchDownloaderCore/TwitchObjects/ChatRootInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TwitchDownloaderCore/TwitchObjects/ChatRootInfo.cs b/TwitchDownloaderCore/TwitchObjects/ChatRootInfo.cs index 6eb27389..1cd81bd0 100644 --- a/TwitchDownloaderCore/TwitchObjects/ChatRootInfo.cs +++ b/TwitchDownloaderCore/TwitchObjects/ChatRootInfo.cs @@ -41,7 +41,7 @@ public override string ToString() => $"{Major}.{Minor}.{Patch}"; public override int GetHashCode() - => ToString().GetHashCode(); + => HashCode.Combine(Major, Minor, Patch); public static bool operator >(ChatRootVersion left, ChatRootVersion right) { From 325ce21fe86539966fa423210ce797e0db91e6ca Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:21:40 -0500 Subject: [PATCH 4/5] Bump SkiaSharp and HarfBuzzSharp to latest minor version --- TwitchDownloaderCore/TwitchDownloaderCore.csproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/TwitchDownloaderCore/TwitchDownloaderCore.csproj b/TwitchDownloaderCore/TwitchDownloaderCore.csproj index 776c3337..f777aeae 100644 --- a/TwitchDownloaderCore/TwitchDownloaderCore.csproj +++ b/TwitchDownloaderCore/TwitchDownloaderCore.csproj @@ -23,13 +23,13 @@ - - + + - - - - + + + + From 765531c1f4e6896cd1b0bfa33b4b01ff4fd7f7cf Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Fri, 27 Dec 2024 21:08:50 -0500 Subject: [PATCH 5/5] Use HashSet<> instead of List<> --- TwitchDownloaderCore/TwitchHelper.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index 2ecc18bf..36c02415 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -355,7 +355,7 @@ private static async Task> GetStvEmotesMetadata(int stre public static async Task> GetThirdPartyEmotes(List comments, int streamerId, string cacheFolder, ITaskLogger logger, EmbeddedData embeddedData = null, bool bttv = true, bool ffz = true, bool stv = true, bool allowUnlistedEmotes = true, bool offline = false, CancellationToken cancellationToken = default) { List returnList = new List(); - List alreadyAdded = new List(); + HashSet alreadyAdded = new HashSet(); // No 3rd party emotes are wanted if (!bttv && !ffz && !stv) @@ -459,7 +459,7 @@ public static async Task> GetThirdPartyEmotes(List co return returnList; static async Task FetchEmoteImages(IReadOnlyCollection comments, IEnumerable emoteResponse, ICollection returnList, - ICollection alreadyAdded, DirectoryInfo cacheFolder, ITaskLogger logger, CancellationToken cancellationToken) + ISet alreadyAdded, DirectoryInfo cacheFolder, ITaskLogger logger, CancellationToken cancellationToken) { if (!cacheFolder.Exists) cacheFolder = CreateDirectory(cacheFolder.FullName); @@ -500,8 +500,8 @@ where comments.Any(comment => Regex.IsMatch(comment.message.body, pattern)) public static async Task> GetEmotes(List comments, string cacheFolder, ITaskLogger logger, EmbeddedData embeddedData = null, bool offline = false, CancellationToken cancellationToken = default) { List returnList = new List(); - List alreadyAdded = new List(); - List failedEmotes = new List(); + HashSet alreadyAdded = new HashSet(); + HashSet failedEmotes = new HashSet(); DirectoryInfo emoteFolder = new DirectoryInfo(Path.Combine(cacheFolder, "emotes")); if (!emoteFolder.Exists) @@ -633,7 +633,7 @@ public static async Task> GetEmotes(List comments, st public static async Task> GetChatBadges(List comments, int streamerId, string cacheFolder, ITaskLogger logger, EmbeddedData embeddedData = null, bool offline = false, CancellationToken cancellationToken = default) { List returnList = new List(); - List alreadyAdded = new List(); + HashSet alreadyAdded = new HashSet(); // Load our embedded data from file if (embeddedData?.twitchBadges != null) @@ -781,7 +781,7 @@ public static async Task> GetEmojis(string cacheFol public static async Task> GetBits(List comments, string cacheFolder, string channelId, ITaskLogger logger, EmbeddedData embeddedData = null, bool offline = false, CancellationToken cancellationToken = default) { List returnList = new List(); - List alreadyAdded = new List(); + HashSet alreadyAdded = new HashSet(); // Load our embedded data from file if (embeddedData?.twitchBits != null)