fix: improve subtitle handling and tool names
- Rename list_video_subtitles to list_subtitle_languages for clarity - Update tool descriptions to better reflect functionality - Improve subtitle listing output format - Simplify subtitle download parameters - Add verbose logging for better debugging - Bump version to 0.6.21
This commit is contained in:
parent
5523b1dedd
commit
58384bb1a2
@ -48,13 +48,13 @@ pip install yt-dlp
|
|||||||
|
|
||||||
## Tool Documentation
|
## Tool Documentation
|
||||||
|
|
||||||
* **list_video_subtitles**
|
* **list_subtitle_languages**
|
||||||
* List all available subtitles for a video
|
* List all available subtitle languages and their formats for a video (including auto-generated captions)
|
||||||
* Inputs:
|
* Inputs:
|
||||||
* `url` (string, required): URL of the video
|
* `url` (string, required): URL of the video
|
||||||
|
|
||||||
* **download_video_srt**
|
* **download_video_subtitles**
|
||||||
* Download subtitles in SRT format
|
* Download video subtitles in any available format. Supports both regular and auto-generated subtitles
|
||||||
* Inputs:
|
* Inputs:
|
||||||
* `url` (string, required): URL of the video
|
* `url` (string, required): URL of the video
|
||||||
* `language` (string, optional): Language code (e.g., 'en', 'zh-Hant', 'ja'). Defaults to 'en'
|
* `language` (string, optional): Language code (e.g., 'en', 'zh-Hant', 'ja'). Defaults to 'en'
|
||||||
@ -96,3 +96,4 @@ MIT
|
|||||||
|
|
||||||
Dewei Yen
|
Dewei Yen
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevinwatt/yt-dlp-mcp",
|
"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",
|
"description": "yt-dlp MCP Server - Download video content via Model Context Protocol",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"mcp",
|
"mcp",
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import * as path from "path";
|
|||||||
import { spawnPromise } from "spawn-rx";
|
import { spawnPromise } from "spawn-rx";
|
||||||
import { rimraf } from "rimraf";
|
import { rimraf } from "rimraf";
|
||||||
|
|
||||||
const VERSION = '0.6.20';
|
const VERSION = '0.6.21';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System Configuration
|
* System Configuration
|
||||||
@ -100,8 +100,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|||||||
return {
|
return {
|
||||||
tools: [
|
tools: [
|
||||||
{
|
{
|
||||||
name: "list_video_subtitles",
|
name: "list_subtitle_languages",
|
||||||
description: "List all available subtitles for a video, including auto-generated captions",
|
description: "List all available subtitle languages and their formats for a video (including auto-generated captions)",
|
||||||
inputSchema: {
|
inputSchema: {
|
||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
@ -242,13 +242,18 @@ async function listSubtitles(url: string): Promise<string> {
|
|||||||
"--list-subs", // 列出一般字幕
|
"--list-subs", // 列出一般字幕
|
||||||
"--write-auto-sub", // 包含自動生成的字幕
|
"--write-auto-sub", // 包含自動生成的字幕
|
||||||
"--skip-download",
|
"--skip-download",
|
||||||
|
"--verbose", // 添加詳細輸出
|
||||||
url
|
url
|
||||||
],
|
],
|
||||||
{ cwd: tempDirectory }
|
{ cwd: tempDirectory }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 如果沒有一般字幕,添加說明
|
||||||
|
if (result.includes("has no subtitles")) {
|
||||||
|
return "Regular subtitles: None\n\nAuto-generated subtitles: Available in multiple languages";
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 直接傳遞 yt-dlp 的錯誤訊息
|
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
await safeCleanup(tempDirectory);
|
await safeCleanup(tempDirectory);
|
||||||
@ -268,7 +273,6 @@ async function downloadSubtitles(url: string, language: string = "en"): Promise<
|
|||||||
throw new Error('Invalid language code');
|
throw new Error('Invalid language code');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下載字幕,同時支援一般字幕和自動生成的字幕
|
|
||||||
try {
|
try {
|
||||||
const result = await spawnPromise(
|
const result = await spawnPromise(
|
||||||
"yt-dlp",
|
"yt-dlp",
|
||||||
@ -278,6 +282,7 @@ async function downloadSubtitles(url: string, language: string = "en"): Promise<
|
|||||||
"--sub-lang", language,
|
"--sub-lang", language,
|
||||||
"--convert-subs", "srt",
|
"--convert-subs", "srt",
|
||||||
"--skip-download",
|
"--skip-download",
|
||||||
|
"--verbose", // 添加詳細輸出
|
||||||
url
|
url
|
||||||
],
|
],
|
||||||
{ cwd: tempDirectory }
|
{ cwd: tempDirectory }
|
||||||
@ -293,7 +298,7 @@ async function downloadSubtitles(url: string, language: string = "en"): Promise<
|
|||||||
|
|
||||||
// 過濾出字幕文件
|
// 過濾出字幕文件
|
||||||
const subtitleFiles = files.filter(file =>
|
const subtitleFiles = files.filter(file =>
|
||||||
file.endsWith('.srt')
|
file.endsWith('.srt') || file.endsWith('.vtt')
|
||||||
);
|
);
|
||||||
|
|
||||||
if (subtitleFiles.length === 0) {
|
if (subtitleFiles.length === 0) {
|
||||||
@ -494,10 +499,10 @@ server.setRequestHandler(
|
|||||||
resolution?: string;
|
resolution?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (toolName === "list_video_subtitles") {
|
if (toolName === "list_subtitle_languages") {
|
||||||
return handleToolExecution(
|
return handleToolExecution(
|
||||||
() => listSubtitles(args.url),
|
() => listSubtitles(args.url),
|
||||||
"Error listing subtitles"
|
"Error listing subtitle languages"
|
||||||
);
|
);
|
||||||
} else if (toolName === "download_video_subtitles") {
|
} else if (toolName === "download_video_subtitles") {
|
||||||
return handleToolExecution(
|
return handleToolExecution(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user