From 9a92a7662139ea12a43a50703a02f082f09ef1dd Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 11 Jan 2024 22:45:37 +0200 Subject: [PATCH] Clean up with latest C# features --- .../Downloading/FileNameTemplate.cs | 2 +- .../Downloading/VideoDownloadOption.cs | 22 +++++-------------- .../Resolving/QueryResolver.cs | 2 +- YoutubeDownloader.Core/Tagging/MediaFile.cs | 6 ++--- YoutubeDownloader.Core/Utils/PathEx.cs | 3 +-- .../VideoMultiSelectionListBoxBehavior.cs | 2 +- .../Components/DashboardViewModel.cs | 2 +- .../Components/DownloadViewModel.cs | 2 +- .../ViewModels/Framework/DialogScreen.cs | 2 +- 9 files changed, 15 insertions(+), 28 deletions(-) diff --git a/YoutubeDownloader.Core/Downloading/FileNameTemplate.cs b/YoutubeDownloader.Core/Downloading/FileNameTemplate.cs index e005868b0..758ecf8af 100644 --- a/YoutubeDownloader.Core/Downloading/FileNameTemplate.cs +++ b/YoutubeDownloader.Core/Downloading/FileNameTemplate.cs @@ -5,7 +5,7 @@ namespace YoutubeDownloader.Core.Downloading; -public class FileNameTemplate +public static class FileNameTemplate { public static string Apply( string template, diff --git a/YoutubeDownloader.Core/Downloading/VideoDownloadOption.cs b/YoutubeDownloader.Core/Downloading/VideoDownloadOption.cs index ece9f42f2..05d373652 100644 --- a/YoutubeDownloader.Core/Downloading/VideoDownloadOption.cs +++ b/YoutubeDownloader.Core/Downloading/VideoDownloadOption.cs @@ -36,7 +36,7 @@ IEnumerable GetVideoAndAudioOptions() yield return new VideoDownloadOption( videoStreamInfo.Container, false, - new[] { videoStreamInfo } + [videoStreamInfo] ); } // Separate audio + video stream @@ -75,22 +75,14 @@ IEnumerable GetAudioOnlyOptions() if (audioStreamInfo is not null) { - yield return new VideoDownloadOption( - Container.WebM, - true, - new[] { audioStreamInfo } - ); + yield return new VideoDownloadOption(Container.WebM, true, [audioStreamInfo]); - yield return new VideoDownloadOption( - Container.Mp3, - true, - new[] { audioStreamInfo } - ); + yield return new VideoDownloadOption(Container.Mp3, true, [audioStreamInfo]); yield return new VideoDownloadOption( new Container("ogg"), true, - new[] { audioStreamInfo } + [audioStreamInfo] ); } } @@ -106,11 +98,7 @@ IEnumerable GetAudioOnlyOptions() if (audioStreamInfo is not null) { - yield return new VideoDownloadOption( - Container.Mp4, - true, - new[] { audioStreamInfo } - ); + yield return new VideoDownloadOption(Container.Mp4, true, [audioStreamInfo]); } } } diff --git a/YoutubeDownloader.Core/Resolving/QueryResolver.cs b/YoutubeDownloader.Core/Resolving/QueryResolver.cs index 0a194b025..ae29ad1bb 100644 --- a/YoutubeDownloader.Core/Resolving/QueryResolver.cs +++ b/YoutubeDownloader.Core/Resolving/QueryResolver.cs @@ -40,7 +40,7 @@ public async Task ResolveAsync( if (isUrl && VideoId.TryParse(query) is { } videoId) { var video = await _youtube.Videos.GetAsync(videoId, cancellationToken); - return new QueryResult(QueryResultKind.Video, video.Title, new[] { video }); + return new QueryResult(QueryResultKind.Video, video.Title, [video]); } // Channel diff --git a/YoutubeDownloader.Core/Tagging/MediaFile.cs b/YoutubeDownloader.Core/Tagging/MediaFile.cs index 38396bc5c..c65a79cee 100644 --- a/YoutubeDownloader.Core/Tagging/MediaFile.cs +++ b/YoutubeDownloader.Core/Tagging/MediaFile.cs @@ -7,11 +7,11 @@ namespace YoutubeDownloader.Core.Tagging; internal partial class MediaFile(TagFile file) : IDisposable { public void SetThumbnail(byte[] thumbnailData) => - file.Tag.Pictures = new IPicture[] { new Picture(thumbnailData) }; + file.Tag.Pictures = [new Picture(thumbnailData)]; - public void SetArtist(string artist) => file.Tag.Performers = new[] { artist }; + public void SetArtist(string artist) => file.Tag.Performers = [artist]; - public void SetArtistSort(string artistSort) => file.Tag.PerformersSort = new[] { artistSort }; + public void SetArtistSort(string artistSort) => file.Tag.PerformersSort = [artistSort]; public void SetTitle(string title) => file.Tag.Title = title; diff --git a/YoutubeDownloader.Core/Utils/PathEx.cs b/YoutubeDownloader.Core/Utils/PathEx.cs index a4d462ee2..c2a70f335 100644 --- a/YoutubeDownloader.Core/Utils/PathEx.cs +++ b/YoutubeDownloader.Core/Utils/PathEx.cs @@ -6,8 +6,7 @@ namespace YoutubeDownloader.Core.Utils; public static class PathEx { - private static readonly HashSet InvalidFileNameChars = - new(Path.GetInvalidFileNameChars()); + private static readonly HashSet InvalidFileNameChars = [..Path.GetInvalidFileNameChars()]; public static string EscapeFileName(string path) { diff --git a/YoutubeDownloader/Behaviors/VideoMultiSelectionListBoxBehavior.cs b/YoutubeDownloader/Behaviors/VideoMultiSelectionListBoxBehavior.cs index 76ffe2927..e098fdbbb 100644 --- a/YoutubeDownloader/Behaviors/VideoMultiSelectionListBoxBehavior.cs +++ b/YoutubeDownloader/Behaviors/VideoMultiSelectionListBoxBehavior.cs @@ -2,4 +2,4 @@ namespace YoutubeDownloader.Behaviors; -public class VideoMultiSelectionListBoxBehavior : MultiSelectionListBoxBehavior { } +public class VideoMultiSelectionListBoxBehavior : MultiSelectionListBoxBehavior; diff --git a/YoutubeDownloader/ViewModels/Components/DashboardViewModel.cs b/YoutubeDownloader/ViewModels/Components/DashboardViewModel.cs index 0bff0c6b3..e8495e5ab 100644 --- a/YoutubeDownloader/ViewModels/Components/DashboardViewModel.cs +++ b/YoutubeDownloader/ViewModels/Components/DashboardViewModel.cs @@ -33,7 +33,7 @@ public class DashboardViewModel : PropertyChangedBase, IDisposable public string? Query { get; set; } - public BindableCollection Downloads { get; } = new(); + public BindableCollection Downloads { get; } = []; public bool IsDownloadsAvailable => Downloads.Any(); diff --git a/YoutubeDownloader/ViewModels/Components/DownloadViewModel.cs b/YoutubeDownloader/ViewModels/Components/DownloadViewModel.cs index a65d0284e..b70ff7279 100644 --- a/YoutubeDownloader/ViewModels/Components/DownloadViewModel.cs +++ b/YoutubeDownloader/ViewModels/Components/DownloadViewModel.cs @@ -72,7 +72,7 @@ public async void ShowFile() try { // Navigate to the file in Windows Explorer - ProcessEx.Start("explorer", new[] { "/select,", FilePath! }); + ProcessEx.Start("explorer", ["/select,", FilePath!]); } catch (Exception ex) { diff --git a/YoutubeDownloader/ViewModels/Framework/DialogScreen.cs b/YoutubeDownloader/ViewModels/Framework/DialogScreen.cs index 44254e57e..cbbfd4349 100644 --- a/YoutubeDownloader/ViewModels/Framework/DialogScreen.cs +++ b/YoutubeDownloader/ViewModels/Framework/DialogScreen.cs @@ -16,4 +16,4 @@ public void Close(T? dialogResult = default) } } -public abstract class DialogScreen : DialogScreen { } +public abstract class DialogScreen : DialogScreen;