diff --git a/Yosu.Core/Utils/DelegateEqualityComparer.cs b/Yosu.Core/Utils/DelegateEqualityComparer.cs index 38d527d..bdee72e 100644 --- a/Yosu.Core/Utils/DelegateEqualityComparer.cs +++ b/Yosu.Core/Utils/DelegateEqualityComparer.cs @@ -3,16 +3,10 @@ namespace Yosu.Core.Utils; -public class DelegateEqualityComparer : IEqualityComparer +public class DelegateEqualityComparer(Func equals, Func getHashCode) : IEqualityComparer { - private readonly Func _equals; - private readonly Func _getHashCode; - - public DelegateEqualityComparer(Func equals, Func getHashCode) - { - _equals = equals; - _getHashCode = getHashCode; - } + private readonly Func _equals = equals; + private readonly Func _getHashCode = getHashCode; public bool Equals(T? x, T? y) { diff --git a/Yosu.Core/Utils/ThrottleLock.cs b/Yosu.Core/Utils/ThrottleLock.cs index 45ecb01..e83f04c 100644 --- a/Yosu.Core/Utils/ThrottleLock.cs +++ b/Yosu.Core/Utils/ThrottleLock.cs @@ -4,14 +4,12 @@ namespace Yosu.Core.Utils; -public class ThrottleLock : IDisposable +public class ThrottleLock(TimeSpan interval) : IDisposable { private readonly SemaphoreSlim _semaphore = new(1, 1); - private readonly TimeSpan _interval; + private readonly TimeSpan _interval = interval; private DateTimeOffset _lastRequestInstant = DateTimeOffset.MinValue; - public ThrottleLock(TimeSpan interval) => _interval = interval; - public async Task WaitAsync(CancellationToken cancellationToken = default) { await _semaphore.WaitAsync(cancellationToken); diff --git a/Yosu.Soundcloud.Core/Tagging/MediaFile.cs b/Yosu.Soundcloud.Core/Tagging/MediaFile.cs index c9f9482..21428c7 100644 --- a/Yosu.Soundcloud.Core/Tagging/MediaFile.cs +++ b/Yosu.Soundcloud.Core/Tagging/MediaFile.cs @@ -4,11 +4,9 @@ namespace Yosu.Soundcloud.Core.Tagging; -internal partial class MediaFile : IDisposable +internal partial class MediaFile(TagFile file) : IDisposable { - private readonly TagFile _file; - - public MediaFile(TagFile file) => _file = file; + private readonly TagFile _file = file; public void SetThumbnail(byte[] thumbnailData) => _file.Tag.Pictures = [new Picture(thumbnailData)]; diff --git a/Yosu.Spotify.Core/Tagging/MediaFile.cs b/Yosu.Spotify.Core/Tagging/MediaFile.cs index 9f3d01f..a461890 100644 --- a/Yosu.Spotify.Core/Tagging/MediaFile.cs +++ b/Yosu.Spotify.Core/Tagging/MediaFile.cs @@ -12,11 +12,9 @@ namespace Yosu.Spotify.Core.Tagging; -internal partial class MediaFile : IDisposable +internal partial class MediaFile(TagFile file) : IDisposable { - private readonly TagFile _file; - - public MediaFile(TagFile file) => _file = file; + private readonly TagFile _file = file; /*public void SetThumbnail(byte[] thumbnailData) { diff --git a/Yosu.Youtube.Converter/ConversionFormat.cs b/Yosu.Youtube.Converter/ConversionFormat.cs index 1f2d2a0..64cccd1 100644 --- a/Yosu.Youtube.Converter/ConversionFormat.cs +++ b/Yosu.Youtube.Converter/ConversionFormat.cs @@ -7,24 +7,22 @@ namespace Yosu.Youtube.Converter; /// /// Encapsulates conversion media format. /// +/// +/// Initializes an instance of . +/// [Obsolete("Use YoutubeExplode.Videos.Streams.Container instead"), ExcludeFromCodeCoverage] -public readonly struct ConversionFormat +public readonly struct ConversionFormat(string name) { /// /// Format name. /// - public string Name { get; } + public string Name { get; } = name; /// /// Whether this format is a known audio-only format. /// public bool IsAudioOnly => new Container(Name).IsAudioOnly(); - /// - /// Initializes an instance of . - /// - public ConversionFormat(string name) => Name = name; - /// public override string ToString() => Name; } diff --git a/Yosu.Youtube.Converter/ConversionRequest.cs b/Yosu.Youtube.Converter/ConversionRequest.cs index c4760e1..ab1c9f3 100644 --- a/Yosu.Youtube.Converter/ConversionRequest.cs +++ b/Yosu.Youtube.Converter/ConversionRequest.cs @@ -7,22 +7,30 @@ namespace Yosu.Youtube.Converter; /// /// Conversion options. /// -public class ConversionRequest +/// +/// Initializes an instance of . +/// +public class ConversionRequest( + string ffmpegCliFilePath, + string outputFilePath, + Container container, + ConversionPreset preset + ) { /// /// Path to FFmpeg CLI. /// - public string FFmpegCliFilePath { get; } + public string FFmpegCliFilePath { get; } = ffmpegCliFilePath; /// /// Output file path. /// - public string OutputFilePath { get; } + public string OutputFilePath { get; } = outputFilePath; /// /// Output container. /// - public Container Container { get; } + public Container Container { get; } = container; /// /// Output format. @@ -33,23 +41,7 @@ public class ConversionRequest /// /// Encoder preset. /// - public ConversionPreset Preset { get; } - - /// - /// Initializes an instance of . - /// - public ConversionRequest( - string ffmpegCliFilePath, - string outputFilePath, - Container container, - ConversionPreset preset - ) - { - FFmpegCliFilePath = ffmpegCliFilePath; - OutputFilePath = outputFilePath; - Container = container; - Preset = preset; - } + public ConversionPreset Preset { get; } = preset; /// /// Initializes an instance of . diff --git a/Yosu.Youtube.Converter/ConversionRequestBuilder.cs b/Yosu.Youtube.Converter/ConversionRequestBuilder.cs index dadde6a..a2b38d6 100644 --- a/Yosu.Youtube.Converter/ConversionRequestBuilder.cs +++ b/Yosu.Youtube.Converter/ConversionRequestBuilder.cs @@ -10,19 +10,17 @@ namespace Yosu.Youtube.Converter; /// /// Builder for . /// -public partial class ConversionRequestBuilder +/// +/// Initializes an instance of . +/// +public partial class ConversionRequestBuilder(string outputFilePath) { - private readonly string _outputFilePath; + private readonly string _outputFilePath = outputFilePath; private string? _ffmpegCliFilePath; private Container? _container; private ConversionPreset _preset; - /// - /// Initializes an instance of . - /// - public ConversionRequestBuilder(string outputFilePath) => _outputFilePath = outputFilePath; - private Container GetDefaultContainer() => new(Path.GetExtension(_outputFilePath).TrimStart('.').NullIfWhiteSpace() ?? "mp4"); diff --git a/Yosu.Youtube.Converter/Converter.cs b/Yosu.Youtube.Converter/Converter.cs index 63109ba..769daf8 100644 --- a/Yosu.Youtube.Converter/Converter.cs +++ b/Yosu.Youtube.Converter/Converter.cs @@ -13,18 +13,11 @@ namespace Yosu.Youtube.Converter; -internal partial class Converter +internal partial class Converter(VideoClient videoClient, FFmpeg ffmpeg, ConversionPreset preset) { - private readonly VideoClient _videoClient; - private readonly FFmpeg _ffmpeg; - private readonly ConversionPreset _preset; - - public Converter(VideoClient videoClient, FFmpeg ffmpeg, ConversionPreset preset) - { - _videoClient = videoClient; - _ffmpeg = ffmpeg; - _preset = preset; - } + private readonly VideoClient _videoClient = videoClient; + private readonly FFmpeg _ffmpeg = ffmpeg; + private readonly ConversionPreset _preset = preset; private async ValueTask ProcessAsync( string filePath, @@ -233,17 +226,11 @@ await ProcessAsync( internal partial class Converter { - private class StreamInput : IDisposable + private class StreamInput(IStreamInfo info, string filePath) : IDisposable { - public IStreamInfo Info { get; } - - public string FilePath { get; } + public IStreamInfo Info { get; } = info; - public StreamInput(IStreamInfo info, string filePath) - { - Info = info; - FilePath = filePath; - } + public string FilePath { get; } = filePath; public void Dispose() { @@ -258,17 +245,11 @@ public void Dispose() } } - private class SubtitleInput : IDisposable + private class SubtitleInput(ClosedCaptionTrackInfo info, string filePath) : IDisposable { - public ClosedCaptionTrackInfo Info { get; } - - public string FilePath { get; } + public ClosedCaptionTrackInfo Info { get; } = info; - public SubtitleInput(ClosedCaptionTrackInfo info, string filePath) - { - Info = info; - FilePath = filePath; - } + public string FilePath { get; } = filePath; public void Dispose() { diff --git a/Yosu.Youtube.Converter/FFmpeg/FFmpeg.android.cs b/Yosu.Youtube.Converter/FFmpeg/FFmpeg.android.cs index a1fe2b5..1ac4295 100644 --- a/Yosu.Youtube.Converter/FFmpeg/FFmpeg.android.cs +++ b/Yosu.Youtube.Converter/FFmpeg/FFmpeg.android.cs @@ -5,11 +5,9 @@ namespace Yosu.Youtube.Converter; -internal class FFmpeg +internal class FFmpeg(string filePath) { - private readonly string _filePath; - - public FFmpeg(string filePath) => _filePath = filePath; + private readonly string _filePath = filePath; public void Execute( string arguments, diff --git a/Yosu.Youtube.Converter/FFmpeg/FFmpeg.macios.cs b/Yosu.Youtube.Converter/FFmpeg/FFmpeg.macios.cs index 308f2b7..5db1f13 100644 --- a/Yosu.Youtube.Converter/FFmpeg/FFmpeg.macios.cs +++ b/Yosu.Youtube.Converter/FFmpeg/FFmpeg.macios.cs @@ -5,11 +5,9 @@ namespace Yosu.Youtube.Converter; -internal class FFmpeg +internal class FFmpeg(string filePath) { - private readonly string _filePath; - - public FFmpeg(string filePath) => _filePath = filePath; + private readonly string _filePath = filePath; public void Execute( string arguments, diff --git a/Yosu.Youtube.Converter/FFmpeg/FFmpeg.net.cs b/Yosu.Youtube.Converter/FFmpeg/FFmpeg.net.cs index b59cdff..cc80bb6 100644 --- a/Yosu.Youtube.Converter/FFmpeg/FFmpeg.net.cs +++ b/Yosu.Youtube.Converter/FFmpeg/FFmpeg.net.cs @@ -14,11 +14,9 @@ namespace Yosu.Youtube.Converter; // Ideally this should use named pipes and stream through stdout. // However, named pipes aren't well supported on non-Windows OS and // stdout streaming only works with some specific formats. -internal partial class FFmpeg +internal partial class FFmpeg(string filePath) { - private readonly string _filePath; - - public FFmpeg(string filePath) => _filePath = filePath; + private readonly string _filePath = filePath; public async ValueTask ExecuteAsync( string arguments, @@ -58,16 +56,14 @@ public async ValueTask ExecuteAsync( internal partial class FFmpeg { - private class FFmpegProgressRouter : PipeTarget + private class FFmpegProgressRouter(IProgress output) : PipeTarget { private readonly StringBuilder _buffer = new(); - private readonly IProgress _output; + private readonly IProgress _output = output; private TimeSpan? _totalDuration; private TimeSpan? _lastOffset; - public FFmpegProgressRouter(IProgress output) => _output = output; - private TimeSpan? TryParseTotalDuration(string data) => data.Pipe(s => Regex.Match(s, @"Duration:\s(\d\d:\d\d:\d\d.\d\d)").Groups[1].Value) .NullIfWhiteSpace() diff --git a/Yosu.Youtube.Converter/FFmpeg/FFmpeg.windows.cs b/Yosu.Youtube.Converter/FFmpeg/FFmpeg.windows.cs index 6089f01..c6bd1aa 100644 --- a/Yosu.Youtube.Converter/FFmpeg/FFmpeg.windows.cs +++ b/Yosu.Youtube.Converter/FFmpeg/FFmpeg.windows.cs @@ -5,11 +5,9 @@ namespace Yosu.Youtube.Converter; -internal class FFmpeg +internal class FFmpeg(string filePath) { - private readonly string _filePath; - - public FFmpeg(string filePath) => _filePath = filePath; + private readonly string _filePath = filePath; public async ValueTask ExecuteAsync( string arguments, diff --git a/Yosu.Youtube.Converter/Utils/ProgressMuxer.cs b/Yosu.Youtube.Converter/Utils/ProgressMuxer.cs index 2d40d9c..f999699 100644 --- a/Yosu.Youtube.Converter/Utils/ProgressMuxer.cs +++ b/Yosu.Youtube.Converter/Utils/ProgressMuxer.cs @@ -3,16 +3,14 @@ namespace Yosu.Youtube.Converter.Utils; -internal class ProgressMuxer +internal class ProgressMuxer(IProgress target) { - private readonly IProgress _target; + private readonly IProgress _target = target; private readonly object _lock = new(); private readonly Dictionary _splitWeights = []; private readonly Dictionary _splitValues = []; - public ProgressMuxer(IProgress target) => _target = target; - public IProgress CreateInput(double weight = 1) { lock (_lock) diff --git a/Yosu.Youtube.Core/Tagging/MediaFile.cs b/Yosu.Youtube.Core/Tagging/MediaFile.cs index b4fa04d..866fa83 100644 --- a/Yosu.Youtube.Core/Tagging/MediaFile.cs +++ b/Yosu.Youtube.Core/Tagging/MediaFile.cs @@ -12,11 +12,9 @@ namespace Yosu.Youtube.Core.Tagging; -internal partial class MediaFile : IDisposable +internal partial class MediaFile(TagFile file) : IDisposable { - private readonly TagFile _file; - - public MediaFile(TagFile file) => _file = file; + private readonly TagFile _file = file; /*public void SetThumbnail(byte[] thumbnailData) { diff --git a/Yosu/Platforms/Android/MainApplication.cs b/Yosu/Platforms/Android/MainApplication.cs index c193161..43760ca 100644 --- a/Yosu/Platforms/Android/MainApplication.cs +++ b/Yosu/Platforms/Android/MainApplication.cs @@ -7,10 +7,7 @@ namespace Yosu; [Application(UsesCleartextTraffic = true)] -public class MainApplication : MauiApplication +public class MainApplication(IntPtr handle, JniHandleOwnership ownership) : MauiApplication(handle, ownership) { - public MainApplication(IntPtr handle, JniHandleOwnership ownership) - : base(handle, ownership) { } - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); } diff --git a/Yosu/Utils/ResizableSemaphore.cs b/Yosu/Utils/ResizableSemaphore.cs index 10948b5..c19b20f 100644 --- a/Yosu/Utils/ResizableSemaphore.cs +++ b/Yosu/Utils/ResizableSemaphore.cs @@ -88,11 +88,9 @@ public void Dispose() internal partial class ResizableSemaphore { - private class AcquiredAccess : IDisposable + private class AcquiredAccess(ResizableSemaphore semaphore) : IDisposable { - private readonly ResizableSemaphore _semaphore; - - public AcquiredAccess(ResizableSemaphore semaphore) => _semaphore = semaphore; + private readonly ResizableSemaphore _semaphore = semaphore; public void Dispose() => _semaphore.Release(); } diff --git a/Yosu/ViewModels/Framework/ListGroup.cs b/Yosu/ViewModels/Framework/ListGroup.cs index 6a133da..91a2541 100644 --- a/Yosu/ViewModels/Framework/ListGroup.cs +++ b/Yosu/ViewModels/Framework/ListGroup.cs @@ -2,13 +2,7 @@ namespace Yosu.ViewModels.Framework; -public class ListGroup : List +public class ListGroup(string name, List items) : List(items) { - public string Name { get; } - - public ListGroup(string name, List items) - : base(items) - { - Name = name; - } + public string Name { get; } = name; }