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