JimLiu/baoyu-skills / skills/baoyu-youtube-transcript
baoyu-youtube-transcript
VerifiedDownloads YouTube video transcripts/subtitles and cover images by URL or video ID. Supports multiple languages, translation, chapters, and speaker identification. Caches raw data for fast re-formatting. Use when user asks to "get YouTube transcript", "download subtitles", "get captions", "YouTube字幕", "YouTube封面", "视频封面", "video thumbnail", "video cover image", or provides a YouTube URL and wants the transcript/subtitle text or cover image extracted.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 6.5 KB |
| prompts/speaker-transcript.md | markdown | 4.6 KB |
| scripts/main.test.ts | script | 8.5 KB |
| scripts/main.ts | script | 8.4 KB |
| scripts/shared.ts | script | 3.4 KB |
| scripts/storage.ts | script | 1.9 KB |
| scripts/transcript.ts | script | 13.5 KB |
| scripts/types.ts | script | 2.4 KB |
| scripts/youtube.ts | script | 22.4 KB |
scripts/shared.ts
View on GitHubimport type { TranscriptError } from "./types.ts";
export function extractVideoId(input: string): string {
input = input.replace(/\\/g, "").trim();
const patterns = [
/(?:youtube\.com\/watch\?.*v=|youtu\.be\/|youtube\.com\/embed\/|youtube\.com\/v\/|youtube\.com\/shorts\/)([a-zA-Z0-9_-]{11})/,
/^([a-zA-Z0-9_-]{11})$/,
];
for (const pattern of patterns) {
const match = input.match(pattern);
if (match) return match[1];
}
return input;
}
export function slugify(value: string): string {
return value
.toLowerCase()
.replace(/[^\w\s-]/g, "")
.replace(/\s+/g, "-")
.replace(/-+/g, "-")
.replace(/^-|-$/g, "") || "untitled";
}
export function htmlUnescape(value: string): string {
return value
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/'/g, "'")
.replace(///g, "/")
.replace(/'/g, "'")
.replace(/&#(\d+);/g, (_, n) => String.fromCharCode(parseInt(n)))
.replace(/&#x([0-9a-fA-F]+);/g, (_, n) => String.fromCharCode(parseInt(n, 16)));
}
export function stripTags(value: string): string {
return value.replace(/<[^>]*>/g, "");
}
export function makeError(message: string, code?: string): Error {
const error = new Error(message) as TranscriptError;
if (code) error.code = code;
return error;
}
export function normalizeError(error: unknown): TranscriptError {
if (error instanceof Error) {
const known = error as TranscriptError;
if (known.code) return known;
const message = known.message || String(error);
const lower = message.toLowerCase();
if (lower.includes("bot detected")) known.code = "BOT_DETECTED";
else if (lower.includes("age restricted")) known.code = "AGE_RESTRICTED";
else if (lower.includes("video unavailable")) known.code = "VIDEO_UNAVAILABLE";
else if (lower.includes("transcripts disabled")) known.code = "TRANSCRIPTS_DISABLED";
else if (lower.includes("no transcript found")) known.code = "NO_TRANSCRIPT";
else if (lower.includes("invalid video id")) known.code = "INVALID_VIDEO_ID";
else if (lower.includes("ip blocked") || lower.includes("recaptcha") || lower.includes("http 429")) known.code = "IP_BLOCKED";
else if (lower.includes("cannot extract api key")) known.code = "PAGE_FETCH_FAILED";
else if (lower.includes("innertube api") || lower.includes("http 403")) known.code = "INNERTUBE_REJECTED";
else if (lower.includes("yt-dlp fallback failed")) known.code = "YT_DLP_FAILED";
return known;
}
return makeError(String(error), "UNKNOWN") as TranscriptError;
}
export function shouldTryAlternateClient(error: unknown): boolean {
const code = normalizeError(error).code;
return code === "BOT_DETECTED" || code === "IP_BLOCKED" || code === "INNERTUBE_REJECTED" || code === "AGE_RESTRICTED" || code === "VIDEO_UNAVAILABLE";
}
export function shouldTryYtDlpFallback(error: unknown): boolean {
const code = normalizeError(error).code;
return code === "BOT_DETECTED" || code === "IP_BLOCKED" || code === "INNERTUBE_REJECTED" || code === "PAGE_FETCH_FAILED" || code === "AGE_RESTRICTED" || code === "VIDEO_UNAVAILABLE";
}
export function normalizePublishDate(uploadDate?: string): string {
if (!uploadDate || !/^\d{8}$/.test(uploadDate)) return uploadDate || "";
return `${uploadDate.slice(0, 4)}-${uploadDate.slice(4, 6)}-${uploadDate.slice(6, 8)}`;
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |