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",
"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"

View File

@@ -103,20 +103,35 @@ async function downloadSubtitles(url: string): Promise<string> {
/**
* 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<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");
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}`);
}
}
/**