Skip to content

Commit

Permalink
Cleanup (#1280)
Browse files Browse the repository at this point in the history
* Move FilenameService to TwitchDownloaderCore.Services namespace

* Cleanup InfoHandler

* Use HashCode.Combine

* Bump SkiaSharp and HarfBuzzSharp to latest minor version

* Use HashSet<> instead of List<>
  • Loading branch information
ScrubN authored Dec 28, 2024
1 parent 92efc27 commit 59e1eca
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 20 deletions.
1 change: 1 addition & 0 deletions TwitchDownloaderCLI/Modes/DownloadVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using TwitchDownloaderCore;
using TwitchDownloaderCore.Interfaces;
using TwitchDownloaderCore.Options;
using TwitchDownloaderCore.Services;
using TwitchDownloaderCore.Tools;

namespace TwitchDownloaderCLI.Modes
Expand Down
4 changes: 2 additions & 2 deletions TwitchDownloaderCLI/Modes/InfoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCLI/Tools/FileCollisionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using TwitchDownloaderCLI.Models;
using TwitchDownloaderCLI.Modes.Arguments;
using TwitchDownloaderCore.Interfaces;
using TwitchDownloaderCore.Tools;
using TwitchDownloaderCore.Services;

namespace TwitchDownloaderCLI.Tools
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TwitchDownloaderCore.Tools;
using TwitchDownloaderCore.Services;

namespace TwitchDownloaderCore.Tests.ToolTests
namespace TwitchDownloaderCore.Tests.ServiceTests
{
public class FilenameServiceTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 6 additions & 6 deletions TwitchDownloaderCore/TwitchDownloaderCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="HarfBuzzSharp" Version="7.3.0.2" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.2" />
<PackageReference Include="HarfBuzzSharp" Version="7.3.0.3" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.3" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="2.88.8" />
<PackageReference Include="SkiaSharp" Version="2.88.9" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.9" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.9" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="2.88.9" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="Unicode.net" Version="2.0.0" />
</ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions TwitchDownloaderCore/TwitchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private static async Task<List<EmoteResponseItem>> GetStvEmotesMetadata(int stre
public static async Task<List<TwitchEmote>> GetThirdPartyEmotes(List<Comment> 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<TwitchEmote> returnList = new List<TwitchEmote>();
List<string> alreadyAdded = new List<string>();
HashSet<string> alreadyAdded = new HashSet<string>();

// No 3rd party emotes are wanted
if (!bttv && !ffz && !stv)
Expand Down Expand Up @@ -459,7 +459,7 @@ public static async Task<List<TwitchEmote>> GetThirdPartyEmotes(List<Comment> co
return returnList;

static async Task FetchEmoteImages(IReadOnlyCollection<Comment> comments, IEnumerable<EmoteResponseItem> emoteResponse, ICollection<TwitchEmote> returnList,
ICollection<string> alreadyAdded, DirectoryInfo cacheFolder, ITaskLogger logger, CancellationToken cancellationToken)
ISet<string> alreadyAdded, DirectoryInfo cacheFolder, ITaskLogger logger, CancellationToken cancellationToken)
{
if (!cacheFolder.Exists)
cacheFolder = CreateDirectory(cacheFolder.FullName);
Expand Down Expand Up @@ -500,8 +500,8 @@ where comments.Any(comment => Regex.IsMatch(comment.message.body, pattern))
public static async Task<List<TwitchEmote>> GetEmotes(List<Comment> comments, string cacheFolder, ITaskLogger logger, EmbeddedData embeddedData = null, bool offline = false, CancellationToken cancellationToken = default)
{
List<TwitchEmote> returnList = new List<TwitchEmote>();
List<string> alreadyAdded = new List<string>();
List<string> failedEmotes = new List<string>();
HashSet<string> alreadyAdded = new HashSet<string>();
HashSet<string> failedEmotes = new HashSet<string>();

DirectoryInfo emoteFolder = new DirectoryInfo(Path.Combine(cacheFolder, "emotes"));
if (!emoteFolder.Exists)
Expand Down Expand Up @@ -633,7 +633,7 @@ public static async Task<List<TwitchEmote>> GetEmotes(List<Comment> comments, st
public static async Task<List<ChatBadge>> GetChatBadges(List<Comment> comments, int streamerId, string cacheFolder, ITaskLogger logger, EmbeddedData embeddedData = null, bool offline = false, CancellationToken cancellationToken = default)
{
List<ChatBadge> returnList = new List<ChatBadge>();
List<string> alreadyAdded = new List<string>();
HashSet<string> alreadyAdded = new HashSet<string>();

// Load our embedded data from file
if (embeddedData?.twitchBadges != null)
Expand Down Expand Up @@ -781,7 +781,7 @@ public static async Task<Dictionary<string, SKBitmap>> GetEmojis(string cacheFol
public static async Task<List<CheerEmote>> GetBits(List<Comment> comments, string cacheFolder, string channelId, ITaskLogger logger, EmbeddedData embeddedData = null, bool offline = false, CancellationToken cancellationToken = default)
{
List<CheerEmote> returnList = new List<CheerEmote>();
List<string> alreadyAdded = new List<string>();
HashSet<string> alreadyAdded = new HashSet<string>();

// Load our embedded data from file
if (embeddedData?.twitchBits != null)
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/TwitchObjects/ChatRootInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderWPF/PageChatDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderWPF/PageChatUpdate.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderWPF/PageClipDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderWPF/PageVodDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/Services/FileCollisionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderWPF/WindowQueueOptions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 59e1eca

Please sign in to comment.