mirror of
https://github.com/kevinwatt/yt-dlp-mcp.git
synced 2025-08-10 16:09:14 +03:00
fix: add ignore-config flag
This commit is contained in:
@@ -30,20 +30,22 @@ import { _spawnPromise, validateUrl, getFormattedTimestamp, isYouTubeUrl } from
|
||||
*/
|
||||
export async function downloadAudio(url: string, config: Config): Promise<string> {
|
||||
const timestamp = getFormattedTimestamp();
|
||||
|
||||
|
||||
try {
|
||||
validateUrl(url);
|
||||
|
||||
|
||||
const outputTemplate = path.join(
|
||||
config.file.downloadsDir,
|
||||
sanitizeFilename(`%(title)s [%(id)s] ${timestamp}`, config.file) + '.%(ext)s'
|
||||
);
|
||||
|
||||
const format = isYouTubeUrl(url)
|
||||
const format = isYouTubeUrl(url)
|
||||
? "140/bestaudio[ext=m4a]/bestaudio"
|
||||
: "bestaudio[ext=m4a]/bestaudio[ext=mp3]/bestaudio";
|
||||
|
||||
await _spawnPromise("yt-dlp", [
|
||||
"--ignore-config",
|
||||
"--no-check-certificate",
|
||||
"--verbose",
|
||||
"--progress",
|
||||
"--newline",
|
||||
@@ -62,4 +64,4 @@ export async function downloadAudio(url: string, config: Config): Promise<string
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ export async function listSubtitles(url: string): Promise<string> {
|
||||
|
||||
try {
|
||||
const output = await _spawnPromise('yt-dlp', [
|
||||
'--ignore-config',
|
||||
'--list-subs',
|
||||
'--write-auto-sub',
|
||||
'--skip-download',
|
||||
@@ -81,6 +82,7 @@ export async function downloadSubtitles(
|
||||
|
||||
try {
|
||||
await _spawnPromise('yt-dlp', [
|
||||
'--ignore-config',
|
||||
'--write-sub',
|
||||
'--write-auto-sub',
|
||||
'--sub-lang', language,
|
||||
@@ -139,6 +141,7 @@ export async function downloadTranscript(
|
||||
|
||||
try {
|
||||
await _spawnPromise('yt-dlp', [
|
||||
'--ignore-config',
|
||||
'--skip-download',
|
||||
'--write-subs',
|
||||
'--write-auto-subs',
|
||||
@@ -166,4 +169,4 @@ export async function downloadTranscript(
|
||||
} finally {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as path from "path";
|
||||
import type { Config } from "../config.js";
|
||||
import { sanitizeFilename } from "../config.js";
|
||||
import {
|
||||
_spawnPromise,
|
||||
validateUrl,
|
||||
getFormattedTimestamp,
|
||||
import {
|
||||
_spawnPromise,
|
||||
validateUrl,
|
||||
getFormattedTimestamp,
|
||||
isYouTubeUrl,
|
||||
generateRandomFilename
|
||||
generateRandomFilename
|
||||
} from "./utils.js";
|
||||
|
||||
/**
|
||||
@@ -39,11 +39,11 @@ export async function downloadVideo(
|
||||
resolution: "480p" | "720p" | "1080p" | "best" = "720p"
|
||||
): Promise<string> {
|
||||
const userDownloadsDir = config.file.downloadsDir;
|
||||
|
||||
|
||||
try {
|
||||
validateUrl(url);
|
||||
const timestamp = getFormattedTimestamp();
|
||||
|
||||
|
||||
let format: string;
|
||||
if (isYouTubeUrl(url)) {
|
||||
// YouTube-specific format selection
|
||||
@@ -80,15 +80,16 @@ export async function downloadVideo(
|
||||
|
||||
let outputTemplate: string;
|
||||
let expectedFilename: string;
|
||||
|
||||
|
||||
try {
|
||||
// 嘗試獲取檔案名稱
|
||||
outputTemplate = path.join(
|
||||
userDownloadsDir,
|
||||
sanitizeFilename(`%(title)s [%(id)s] ${timestamp}`, config.file) + '.%(ext)s'
|
||||
);
|
||||
|
||||
|
||||
expectedFilename = await _spawnPromise("yt-dlp", [
|
||||
"--ignore-config",
|
||||
"--get-filename",
|
||||
"-f", format,
|
||||
"--output", outputTemplate,
|
||||
@@ -101,10 +102,11 @@ export async function downloadVideo(
|
||||
outputTemplate = path.join(userDownloadsDir, randomFilename);
|
||||
expectedFilename = randomFilename;
|
||||
}
|
||||
|
||||
|
||||
// Download with progress info
|
||||
try {
|
||||
await _spawnPromise("yt-dlp", [
|
||||
"--ignore-config",
|
||||
"--progress",
|
||||
"--newline",
|
||||
"--no-mtime",
|
||||
@@ -120,4 +122,4 @@ export async function downloadVideo(
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user