Skip to content

Commit

Permalink
Clean up with latest C# features
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Jan 11, 2024
1 parent eea2be3 commit 9a92a76
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 28 deletions.
2 changes: 1 addition & 1 deletion YoutubeDownloader.Core/Downloading/FileNameTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace YoutubeDownloader.Core.Downloading;

public class FileNameTemplate
public static class FileNameTemplate
{
public static string Apply(
string template,
Expand Down
22 changes: 5 additions & 17 deletions YoutubeDownloader.Core/Downloading/VideoDownloadOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ IEnumerable<VideoDownloadOption> GetVideoAndAudioOptions()
yield return new VideoDownloadOption(
videoStreamInfo.Container,
false,
new[] { videoStreamInfo }
[videoStreamInfo]
);
}
// Separate audio + video stream
Expand Down Expand Up @@ -75,22 +75,14 @@ IEnumerable<VideoDownloadOption> 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]
);
}
}
Expand All @@ -106,11 +98,7 @@ IEnumerable<VideoDownloadOption> GetAudioOnlyOptions()

if (audioStreamInfo is not null)
{
yield return new VideoDownloadOption(
Container.Mp4,
true,
new[] { audioStreamInfo }
);
yield return new VideoDownloadOption(Container.Mp4, true, [audioStreamInfo]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader.Core/Resolving/QueryResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<QueryResult> 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
Expand Down
6 changes: 3 additions & 3 deletions YoutubeDownloader.Core/Tagging/MediaFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions YoutubeDownloader.Core/Utils/PathEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ namespace YoutubeDownloader.Core.Utils;

public static class PathEx
{
private static readonly HashSet<char> InvalidFileNameChars =
new(Path.GetInvalidFileNameChars());
private static readonly HashSet<char> InvalidFileNameChars = [..Path.GetInvalidFileNameChars()];

public static string EscapeFileName(string path)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace YoutubeDownloader.Behaviors;

public class VideoMultiSelectionListBoxBehavior : MultiSelectionListBoxBehavior<IVideo> { }
public class VideoMultiSelectionListBoxBehavior : MultiSelectionListBoxBehavior<IVideo>;
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DashboardViewModel : PropertyChangedBase, IDisposable

public string? Query { get; set; }

public BindableCollection<DownloadViewModel> Downloads { get; } = new();
public BindableCollection<DownloadViewModel> Downloads { get; } = [];

public bool IsDownloadsAvailable => Downloads.Any();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader/ViewModels/Framework/DialogScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public void Close(T? dialogResult = default)
}
}

public abstract class DialogScreen : DialogScreen<bool?> { }
public abstract class DialogScreen : DialogScreen<bool?>;

0 comments on commit 9a92a76

Please sign in to comment.