diff --git a/README.md b/README.md index c1dafbd..82c0435 100644 --- a/README.md +++ b/README.md @@ -48,13 +48,13 @@ pip install yt-dlp ## Tool Documentation -* **list_video_subtitles** - * List all available subtitles for a video +* **list_subtitle_languages** + * List all available subtitle languages and their formats for a video (including auto-generated captions) * Inputs: * `url` (string, required): URL of the video -* **download_video_srt** - * Download subtitles in SRT format +* **download_video_subtitles** + * Download video subtitles in any available format. Supports both regular and auto-generated subtitles * Inputs: * `url` (string, required): URL of the video * `language` (string, optional): Language code (e.g., 'en', 'zh-Hant', 'ja'). Defaults to 'en' @@ -96,3 +96,4 @@ MIT Dewei Yen + diff --git a/package.json b/package.json index 49edd72..76da70e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevinwatt/yt-dlp-mcp", - "version": "0.6.20", + "version": "0.6.21", "description": "yt-dlp MCP Server - Download video content via Model Context Protocol", "keywords": [ "mcp", diff --git a/src/index.mts b/src/index.mts index b6c4576..b2158cf 100644 --- a/src/index.mts +++ b/src/index.mts @@ -14,7 +14,7 @@ import * as path from "path"; import { spawnPromise } from "spawn-rx"; import { rimraf } from "rimraf"; -const VERSION = '0.6.20'; +const VERSION = '0.6.21'; /** * System Configuration @@ -100,8 +100,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { - name: "list_video_subtitles", - description: "List all available subtitles for a video, including auto-generated captions", + name: "list_subtitle_languages", + description: "List all available subtitle languages and their formats for a video (including auto-generated captions)", inputSchema: { type: "object", properties: { @@ -242,13 +242,18 @@ async function listSubtitles(url: string): Promise { "--list-subs", // 列出一般字幕 "--write-auto-sub", // 包含自動生成的字幕 "--skip-download", + "--verbose", // 添加詳細輸出 url ], { cwd: tempDirectory } ); + + // 如果沒有一般字幕,添加說明 + if (result.includes("has no subtitles")) { + return "Regular subtitles: None\n\nAuto-generated subtitles: Available in multiple languages"; + } return result; } catch (error) { - // 直接傳遞 yt-dlp 的錯誤訊息 throw error; } finally { await safeCleanup(tempDirectory); @@ -268,7 +273,6 @@ async function downloadSubtitles(url: string, language: string = "en"): Promise< throw new Error('Invalid language code'); } - // 下載字幕,同時支援一般字幕和自動生成的字幕 try { const result = await spawnPromise( "yt-dlp", @@ -278,6 +282,7 @@ async function downloadSubtitles(url: string, language: string = "en"): Promise< "--sub-lang", language, "--convert-subs", "srt", "--skip-download", + "--verbose", // 添加詳細輸出 url ], { cwd: tempDirectory } @@ -293,7 +298,7 @@ async function downloadSubtitles(url: string, language: string = "en"): Promise< // 過濾出字幕文件 const subtitleFiles = files.filter(file => - file.endsWith('.srt') + file.endsWith('.srt') || file.endsWith('.vtt') ); if (subtitleFiles.length === 0) { @@ -494,10 +499,10 @@ server.setRequestHandler( resolution?: string; }; - if (toolName === "list_video_subtitles") { + if (toolName === "list_subtitle_languages") { return handleToolExecution( () => listSubtitles(args.url), - "Error listing subtitles" + "Error listing subtitle languages" ); } else if (toolName === "download_video_subtitles") { return handleToolExecution(