From 2e879df47d8c08e263cd1c43efb76c3d666855e7 Mon Sep 17 00:00:00 2001 From: kevinwatt Date: Tue, 11 Feb 2025 02:58:07 +0800 Subject: [PATCH] add .npmignore and update package.json downloadVideo shows progress and downloads to Downloads folder --- .npmignore | 6 ++++++ package.json | 15 ++++++++++++++- src/index.mts | 35 +++++++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..d3eddc2 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +src/ +.git/ +.gitignore +.prettierrc +eslint.config.mjs +tsconfig.json \ No newline at end of file diff --git a/package.json b/package.json index 746cdf3..27602f1 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,23 @@ { "name": "@kevinwatt/yt-dlp-mcp", "version": "0.5.1", + "description": "YouTube yt-dlp MCP Server - Download YouTube content via Model Context Protocol", + "keywords": ["mcp", "youtube", "yt-dlp", "dive", "llm"], + "homepage": "https://github.com/kevinwatt/yt-dlp-mcp#readme", + "bugs": { + "url": "https://github.com/kevinwatt/yt-dlp-mcp/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/kevinwatt/yt-dlp-mcp.git" + }, "bin": { "yt-dlp-mcp": "lib/index.mjs" }, - "description": "YouTube video download for MCP", + "files": [ + "lib", + "README.md" + ], "main": "./lib/index.mjs", "scripts": { "prepare": "tsc && shx chmod +x ./lib/index.mjs" diff --git a/src/index.mts b/src/index.mts index d3e9635..ec7217f 100644 --- a/src/index.mts +++ b/src/index.mts @@ -103,20 +103,35 @@ async function downloadSubtitles(url: string): Promise { /** * Downloads a YouTube video to the user's default Downloads folder. * @param url The URL of the YouTube video. - * @returns A success message. + * @returns A detailed success message including the filename. */ async function downloadVideo(url: string): Promise { - // Determine the user's Downloads directory (works for Windows, macOS, and Linux by default) + // Determine the user's Downloads directory const userDownloadsDir = path.join(os.homedir(), "Downloads"); + + try { + // First get video info to know the filename + const infoResult = await spawnPromise("yt-dlp", [ + "--print", "filename", + "--output", path.join(userDownloadsDir, "%(title)s.%(ext)s"), + "--no-download", + url + ]); + + const expectedFilename = infoResult.trim(); + + // Download with progress info + await spawnPromise("yt-dlp", [ + "--progress", + "--newline", + "--output", path.join(userDownloadsDir, "%(title)s.%(ext)s"), + url + ]); - // Use yt-dlp to download the video into the Downloads folder using a default filename template - await spawnPromise("yt-dlp", [ - url, - "-o", - path.join(userDownloadsDir, "%(title)s.%(ext)s"), - ]); - - return `Video successfully downloaded to ${userDownloadsDir}`; + return `Video successfully downloaded as "${path.basename(expectedFilename)}" to ${userDownloadsDir}`; + } catch (error) { + throw new Error(`Failed to download video: ${error}`); + } } /**