diff --git a/Common/AppManager.cs b/Common/AppManager.cs index 68a9943..a7ddf5d 100644 --- a/Common/AppManager.cs +++ b/Common/AppManager.cs @@ -59,7 +59,7 @@ public static class AppManager static AppManager() { - CurrentVersion = new Version("2.2.1.0"); + CurrentVersion = new Version("2.3.0.0"); ProgramFolderPath = Path.Combine( Environment.GetFolderPath( diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 0d47e63..a239896 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -486,7 +486,7 @@ private async void DownloadBtn_Click(object sender, RoutedEventArgs e) TaskbarInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Indeterminate; DownloadProgressBar.IsIndeterminate = true; - var wasDownloadedSuccessfully = await _client.DownloadVideoAsync( + var wasDownloadedSuccessfully = await _client.DownloadFileAsync( new Metadata( CurrentVideo!.Url, Path.Combine(DownloadPathTextBox.Text, TitleTextBox.Text), diff --git a/Services/YouTubeClient.cs b/Services/YouTubeClient.cs index 5e4ce02..fbfca84 100644 --- a/Services/YouTubeClient.cs +++ b/Services/YouTubeClient.cs @@ -2,6 +2,7 @@ using FFMpegCore; using Newtonsoft.Json.Linq; +using Syncfusion.Windows.Controls.Input; using System; using System.Collections.Generic; using System.Drawing; @@ -36,7 +37,7 @@ public interface IYouTubeClient public ValueTask TryDownloadThumbnailAsync(VideoId videoId, string fullPath); - public ValueTask DownloadVideoAsync(Metadata metadata, DownloadStartedCallback started, DownloadProgressCallback progress, DownloadCancelledCallback cancelled); + public ValueTask DownloadFileAsync(Metadata metadata, DownloadStartedCallback started, DownloadProgressCallback progress, DownloadCancelledCallback cancelled); public Task CancelDownloadIfRunning(); } @@ -143,7 +144,7 @@ public async ValueTask TryDownloadThumbnailAsync(VideoId videoId, string f return false; } - public async ValueTask DownloadVideoAsync(Metadata metadata, DownloadStartedCallback started, DownloadProgressCallback progress, DownloadCancelledCallback cancelled) + public async ValueTask DownloadFileAsync(Metadata metadata, DownloadStartedCallback started, DownloadProgressCallback progress, DownloadCancelledCallback cancelled) { IsDownloading = true; @@ -154,7 +155,7 @@ public async ValueTask DownloadVideoAsync(Metadata metadata, DownloadStart CreateCts(); var fullStreams = await GetStreamsAsync(metadata); - + started(); if (fullStreams.IsVideoStreamEmpty) @@ -169,8 +170,8 @@ public async ValueTask DownloadVideoAsync(Metadata metadata, DownloadStart { string temppath = Path.GetTempPath(); - string videotemp = Path.Combine(temppath, $"video-stream_{Guid.NewGuid()}.tmp"); string audiotemp = Path.Combine(temppath, $"audio-stream_{Guid.NewGuid()}.tmp"); + string videotemp = Path.Combine(temppath, $"video-stream_{Guid.NewGuid()}.tmp"); deletionFiles.Add($"{videotemp}.mp4"); deletionFiles.Add($"{audiotemp}.{fullStreams.AudioStream.Container.Name}"); @@ -215,11 +216,14 @@ private async ValueTask GetStreamsAsync(Metadata metadata) private async Task DownloadVideoTempFile(VideoOnlyStreamInfo videoStream, Metadata metadata, string temppath, DownloadProgressCallback progress) { await FFMpegArguments - .FromUrlInput(new Uri(videoStream.Url)) + .FromUrlInput(new Uri(videoStream.Url), x => + { + x.Seek(metadata.StartTime); + x.WithDuration(metadata.GetDuration()); + }) .OutputToFile($"{temppath}.mp4", true, x => { - x.WithCustomArgument($"-ss {metadata.StartTime} -t {metadata.GetDuration()}"); - x.WithVideoBitrate((int)videoStream.Bitrate.KiloBitsPerSecond); + x.WithVideoBitrate((int)Math.Round(videoStream.Bitrate.KiloBitsPerSecond, 0)); x.WithFastStart(); x.UsingShortest(true); x.UsingMultithreading(true); @@ -235,11 +239,14 @@ await FFMpegArguments private async Task DownloadAudioTempFile(AudioOnlyStreamInfo audioStream, Metadata metadata, string temppath, DownloadProgressCallback progress) { await FFMpegArguments - .FromUrlInput(new Uri(audioStream.Url)) + .FromUrlInput(new Uri(audioStream.Url), x => + { + x.Seek(metadata.StartTime); + x.WithDuration(metadata.GetDuration()); + }) .OutputToFile($"{temppath}.{audioStream.Container.Name}", true, x => { - x.WithCustomArgument($"-ss {metadata.StartTime} -t {metadata.GetDuration()}"); - x.WithAudioBitrate((int)audioStream.Bitrate.KiloBitsPerSecond); + x.WithAudioBitrate((int)Math.Round(audioStream.Bitrate.KiloBitsPerSecond, 0)); x.WithFastStart(); x.UsingShortest(true); x.UsingMultithreading(true); @@ -255,11 +262,13 @@ await FFMpegArguments private async Task DownloadAudioFile(AudioOnlyStreamInfo audioStream, Metadata metadata, DownloadProgressCallback progress) { await FFMpegArguments - .FromUrlInput(new Uri(audioStream.Url)) - .OutputToFile($"{metadata.FullPath}.mp3", true, x => + .FromUrlInput(new Uri(audioStream.Url), x => + { + x.Seek(metadata.StartTime); + x.WithDuration(metadata.GetDuration()); + }) + .OutputToFile(metadata.FullPath + ".mp3", true, x => { - x.WithCustomArgument($"-ss {metadata.StartTime} -t {metadata.GetDuration()}"); - x.WithAudioBitrate((int)audioStream.Bitrate.KiloBitsPerSecond); x.WithAudioCodec(FFMpegCore.Enums.AudioCodec.LibMp3Lame); x.WithFastStart(); x.UsingShortest(true); diff --git a/Version.xml b/Version.xml index e02244b..bf17dc7 100644 --- a/Version.xml +++ b/Version.xml @@ -1,6 +1,6 @@ - 2.2.1.0 + 2.3.0.0 https://github.com/BlyZeYT/YouTube-Downloader/releases/download/2.2.1.0/YouTube-Downloader-v2.2.1.0.zip false \ No newline at end of file diff --git a/YouTubeDownloaderV2.csproj b/YouTubeDownloaderV2.csproj index 8d06533..dc4ddec 100644 --- a/YouTubeDownloaderV2.csproj +++ b/YouTubeDownloaderV2.csproj @@ -30,17 +30,17 @@ - + - + - - - + + + - - + +