From 184259f985d62a314276e550194a767510a35151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B3=E9=88=9E?= Date: Sun, 3 Dec 2023 11:27:45 +0800 Subject: [PATCH] feat: improve handling of cookies in yt-dlp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added a check for the existence of a "cookies.txt" file - Logging the detected cookies file and using it for yt-dlp - Creating backup copies of the cookies file with different names Signed-off-by: 陳鈞 --- Services/LiveChatDownloadService.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Services/LiveChatDownloadService.cs b/Services/LiveChatDownloadService.cs index b04fb34..85d7f98 100644 --- a/Services/LiveChatDownloadService.cs +++ b/Services/LiveChatDownloadService.cs @@ -47,10 +47,14 @@ private Task ExecuteAsyncInternal(CancellationToken stoppingToken) IgnoreNoFormatsError = true }; - if (File.Exists("cookies.txt")) + FileInfo cookies = new("cookies.txt"); + if (cookies.Exists) { - live_chatOptionSet.Cookies = "cookies.txt"; - info_jsonOptionSet.Cookies = "cookies.txt"; + _logger.LogInformation("Detected {cookies}, use it for yt-dlp", cookies.FullName); + var bak = cookies.CopyTo("cookies.bak.txt", true); + var bak2 = cookies.CopyTo("cookies.bak2.txt", true); + live_chatOptionSet.Cookies = bak.FullName; + info_jsonOptionSet.Cookies = bak2.FullName; } YoutubeDLProcess ytdlProc = new(Helper.WhereIsYt_dlp());