From 4403b5d4402cdc7d8b083a43cb5e1c55a4cb16d2 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 28 Nov 2023 17:23:45 -0500 Subject: [PATCH 1/2] Change generated clip temp file name --- TwitchDownloaderCore/ClipDownloader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TwitchDownloaderCore/ClipDownloader.cs b/TwitchDownloaderCore/ClipDownloader.cs index c7e6fcf5..975e820e 100644 --- a/TwitchDownloaderCore/ClipDownloader.cs +++ b/TwitchDownloaderCore/ClipDownloader.cs @@ -63,7 +63,7 @@ void DownloadProgressHandler(StreamCopyProgress streamProgress) TwitchHelper.CreateDirectory(downloadOptions.TempFolder); } - var tempFile = Path.Combine(downloadOptions.TempFolder, $"clip_{DateTimeOffset.Now.ToUnixTimeMilliseconds()}_{Path.GetRandomFileName()}"); + var tempFile = Path.Combine(downloadOptions.TempFolder, $"{downloadOptions.Id}_{DateTimeOffset.UtcNow.Ticks}.mp4"); try { await DownloadFileTaskAsync(downloadUrl, tempFile, downloadOptions.ThrottleKib, new Progress(DownloadProgressHandler), cancellationToken); From 99d60a1b2ce724f6a5070dcd7b7bead5a6b16827 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 28 Nov 2023 18:15:54 -0500 Subject: [PATCH 2/2] Add process exit check to mitigate possible .NET bug --- TwitchDownloaderCore/ClipDownloader.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TwitchDownloaderCore/ClipDownloader.cs b/TwitchDownloaderCore/ClipDownloader.cs index 975e820e..3198af7b 100644 --- a/TwitchDownloaderCore/ClipDownloader.cs +++ b/TwitchDownloaderCore/ClipDownloader.cs @@ -74,6 +74,12 @@ void DownloadProgressHandler(StreamCopyProgress streamProgress) var clipChapter = TwitchHelper.GenerateClipChapter(clipInfo.data.clip); await EncodeClipWithMetadata(tempFile, downloadOptions.Filename, clipInfo.data.clip, clipChapter, cancellationToken); + if (!File.Exists(downloadOptions.Filename)) + { + File.Move(tempFile, downloadOptions.Filename); + throw new FileNotFoundException("Unable to serialize metadata (is FFmpeg missing?). The download has been completed without custom metadata."); + } + _progress.Report(new ProgressReport(ReportType.SameLineStatus, "Encoding Clip Metadata 100%")); _progress.Report(new ProgressReport(100)); } @@ -163,6 +169,12 @@ await FfmpegMetadata.SerializeAsync(metadataFile, clipMetadata.broadcaster.displ }; process.Start(); + + // If the process has exited before we call WaitForExitAsync, the thread locks up. + // This was probably not intended by the .NET team, but it's an issue regardless. + if (process.HasExited) + return; + await process.WaitForExitAsync(cancellationToken); } finally