Skip to content

Commit

Permalink
fix: catch yt-dlp err
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamesb committed Mar 1, 2024
1 parent 4f694a9 commit 91e3f73
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions packages/cli/src/youtube/transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,32 @@ const tryReadFileSync = (file: string) => {
export async function downloadTranscript(
videoId: string
): Promise<string | undefined> {
const fallbackAutoSubsCmd = [
"yt-dlp",
"--write-auto-sub",
"--skip-download",
"-o",
`"${dataFolder}/${videoId}.%(ext)s"`,
`https://www.youtube.com/watch?v=${videoId}`,
].join(" ");
try {
const fallbackAutoSubsCmd = [
"yt-dlp",
"--write-auto-sub",
"--skip-download",
"-o",
`"${dataFolder}/${videoId}.%(ext)s"`,
`https://www.youtube.com/watch?v=${videoId}`,
].join(" ");

if (!existsSync(dataFolder)) {
execSync(`mkdir -p ${dataFolder}`);
}
const filepath = path.join(dataFolder, `${videoId}.en.vtt`);
if (!existsSync(filepath)) {
await execAsync(fallbackAutoSubsCmd);
if (existsSync(filepath)) {
return filepath;
} else {
return undefined;
if (!existsSync(dataFolder)) {
execSync(`mkdir -p ${dataFolder}`);
}
const filepath = path.join(dataFolder, `${videoId}.en.vtt`);
if (!existsSync(filepath)) {
await execAsync(fallbackAutoSubsCmd);
if (existsSync(filepath)) {
return filepath;
} else {
return undefined;
}
}
return filepath;
} catch (e) {
return undefined;
}
return filepath;
}

export async function fetchTranscript(
Expand Down

0 comments on commit 91e3f73

Please sign in to comment.