add .npmignore and update package.json

downloadVideo shows progress and downloads to Downloads folder
This commit is contained in:
kevinwatt 2025-02-11 02:58:07 +08:00
parent 81099a39a7
commit 2e879df47d
3 changed files with 45 additions and 11 deletions

6
.npmignore Normal file
View File

@ -0,0 +1,6 @@
src/
.git/
.gitignore
.prettierrc
eslint.config.mjs
tsconfig.json

View File

@ -1,10 +1,23 @@
{ {
"name": "@kevinwatt/yt-dlp-mcp", "name": "@kevinwatt/yt-dlp-mcp",
"version": "0.5.1", "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": { "bin": {
"yt-dlp-mcp": "lib/index.mjs" "yt-dlp-mcp": "lib/index.mjs"
}, },
"description": "YouTube video download for MCP", "files": [
"lib",
"README.md"
],
"main": "./lib/index.mjs", "main": "./lib/index.mjs",
"scripts": { "scripts": {
"prepare": "tsc && shx chmod +x ./lib/index.mjs" "prepare": "tsc && shx chmod +x ./lib/index.mjs"

View File

@ -103,20 +103,35 @@ async function downloadSubtitles(url: string): Promise<string> {
/** /**
* Downloads a YouTube video to the user's default Downloads folder. * Downloads a YouTube video to the user's default Downloads folder.
* @param url The URL of the YouTube video. * @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<string> { async function downloadVideo(url: string): Promise<string> {
// 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"); 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 return `Video successfully downloaded as "${path.basename(expectedFilename)}" to ${userDownloadsDir}`;
await spawnPromise("yt-dlp", [ } catch (error) {
url, throw new Error(`Failed to download video: ${error}`);
"-o", }
path.join(userDownloadsDir, "%(title)s.%(ext)s"),
]);
return `Video successfully downloaded to ${userDownloadsDir}`;
} }
/** /**