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 ]);