From b3c8fc8b8f8031515c1d5d32aa434d945edb926f Mon Sep 17 00:00:00 2001 From: kevinwatt Date: Tue, 11 Feb 2025 03:07:00 +0800 Subject: [PATCH] set file timestamps to now --- src/index.mts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/index.mts b/src/index.mts index ec7217f..5d552fa 100644 --- a/src/index.mts +++ b/src/index.mts @@ -106,25 +106,36 @@ async function downloadSubtitles(url: string): Promise { * @returns A detailed success message including the filename. */ async function downloadVideo(url: string): Promise { - // Determine the user's Downloads directory const userDownloadsDir = path.join(os.homedir(), "Downloads"); try { + // Get current timestamp for filename + const timestamp = new Date().toISOString() + .replace(/[:.]/g, '-') + .replace('T', '_') + .split('.')[0]; + + const outputTemplate = path.join( + userDownloadsDir, + `%(title)s_${timestamp}.%(ext)s` + ); + // First get video info to know the filename const infoResult = await spawnPromise("yt-dlp", [ "--print", "filename", - "--output", path.join(userDownloadsDir, "%(title)s.%(ext)s"), + "--output", outputTemplate, "--no-download", url ]); const expectedFilename = infoResult.trim(); - // Download with progress info + // Download with progress info and set modification time to now await spawnPromise("yt-dlp", [ "--progress", "--newline", - "--output", path.join(userDownloadsDir, "%(title)s.%(ext)s"), + "--mtime", + "--output", outputTemplate, url ]);