transcriptyt 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TranscriptYT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,35 @@
1
- # Temporary Holding Version
1
+ # transcriptyt
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ JavaScript/TypeScript client for the [TranscriptYT YouTube Transcript API](https://transcript-yt.com). Zero dependencies; works in Node.js 18+, Bun, Deno, and edge runtimes.
4
+
5
+ ```bash
6
+ npm install transcriptyt
7
+ ```
8
+
9
+ ```js
10
+ import { TranscriptYT, TranscriptYTError } from "transcriptyt";
11
+
12
+ const client = new TranscriptYT({ apiKey: process.env.TRANSCRIPTYT_API_KEY });
13
+
14
+ // Timestamped JSON (default)
15
+ const t = await client.getTranscript("https://youtu.be/dQw4w9WgXcQ");
16
+ t.segments; // [{ start, duration, text }, ...]
17
+
18
+ // Files: "text" | "srt" | "vtt" | "csv" | "md" return a string
19
+ const srt = await client.getTranscript("dQw4w9WgXcQ", { format: "srt" });
20
+
21
+ // Translate (150+ languages), merge cues into paragraphs, add timestamps
22
+ const md = await client.getTranscript("dQw4w9WgXcQ", { translateTo: "es", format: "md", paragraphs: true, timestamps: true });
23
+
24
+ // Free calls
25
+ await client.listLanguages("dQw4w9WgXcQ");
26
+ await client.getUsage();
27
+
28
+ try {
29
+ await client.getTranscript("not-a-video");
30
+ } catch (e) {
31
+ if (e instanceof TranscriptYTError) console.log(e.status, e.code, e.message);
32
+ }
33
+ ```
34
+
35
+ Get a free API key (100 transcripts) at [transcript-yt.com](https://transcript-yt.com/login). Docs: [transcript-yt.com/docs](https://transcript-yt.com/docs).
package/index.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ export type Format = "json" | "text" | "srt" | "vtt" | "csv" | "md";
2
+
3
+ export interface Segment {
4
+ start: number;
5
+ duration: number;
6
+ text: string;
7
+ }
8
+
9
+ export interface Track {
10
+ languageCode: string;
11
+ languageName: string;
12
+ autoGenerated: boolean;
13
+ }
14
+
15
+ export interface Transcript {
16
+ videoId: string;
17
+ title: string | null;
18
+ author: string | null;
19
+ channelId: string | null;
20
+ durationSeconds: number;
21
+ language: string;
22
+ translated: boolean;
23
+ autoGenerated: boolean;
24
+ source: "captions" | "speech_to_text";
25
+ segments: Segment[];
26
+ text: string;
27
+ availableLanguages: Track[];
28
+ }
29
+
30
+ export interface TranscriptOptions {
31
+ /** BCP-47 code of the caption track to use. */
32
+ language?: string;
33
+ /** BCP-47 code to machine-translate into (150+ languages). */
34
+ translateTo?: string;
35
+ format?: Format;
36
+ /** JSON only: set false to return just the full text. */
37
+ includeSegments?: boolean;
38
+ /** Prefix lines with [HH:MM:SS] in text and md output. */
39
+ timestamps?: boolean;
40
+ /** Merge caption cues into paragraph-length segments. */
41
+ paragraphs?: boolean;
42
+ }
43
+
44
+ export interface Usage {
45
+ plan: string;
46
+ credits_remaining: number;
47
+ plan_credits: { total: number; used: number; remaining: number };
48
+ topup_credits: { remaining: number; grants: Array<{ remaining: number; expires_at: string }> };
49
+ period_resets_at: string | null;
50
+ rate_limit_per_minute: number;
51
+ }
52
+
53
+ export class TranscriptYTError extends Error {
54
+ status?: number;
55
+ /** e.g. INVALID_VIDEO, VIDEO_UNAVAILABLE, NO_CAPTIONS, LANGUAGE_NOT_AVAILABLE, RATE_LIMITED, BLOCKED, QUOTA_EXCEEDED */
56
+ code?: string;
57
+ body?: unknown;
58
+ }
59
+
60
+ export class TranscriptYT {
61
+ constructor(options?: { apiKey?: string; baseUrl?: string; fetch?: typeof fetch });
62
+ getTranscript(url: string, options?: TranscriptOptions & { format?: "json" }): Promise<Transcript>;
63
+ getTranscript(url: string, options: TranscriptOptions & { format: Exclude<Format, "json"> }): Promise<string>;
64
+ listLanguages(url: string): Promise<{ videoId: string; languages: Track[] }>;
65
+ getUsage(): Promise<Usage>;
66
+ }
67
+
68
+ export default TranscriptYT;
package/index.js ADDED
@@ -0,0 +1,69 @@
1
+ const DEFAULT_BASE_URL = "https://transcript-yt.com";
2
+
3
+ export class TranscriptYTError extends Error {
4
+ constructor(message, { status, code, body } = {}) {
5
+ super(message);
6
+ this.name = "TranscriptYTError";
7
+ this.status = status;
8
+ this.code = code;
9
+ this.body = body;
10
+ }
11
+ }
12
+
13
+ export class TranscriptYT {
14
+ constructor({ apiKey = globalThis.process?.env?.TRANSCRIPTYT_API_KEY, baseUrl = DEFAULT_BASE_URL, fetch: fetchImpl = globalThis.fetch } = {}) {
15
+ if (!apiKey) throw new TranscriptYTError("Missing API key. Pass { apiKey } or set TRANSCRIPTYT_API_KEY.");
16
+ this.apiKey = apiKey;
17
+ this.baseUrl = baseUrl.replace(/\/$/, "");
18
+ this.fetch = fetchImpl;
19
+ }
20
+
21
+ async #request(path, params = {}) {
22
+ const url = new URL(this.baseUrl + path);
23
+ for (const [name, value] of Object.entries(params)) {
24
+ if (value !== undefined && value !== null) url.searchParams.set(name, String(value));
25
+ }
26
+ const res = await this.fetch(url, { headers: { Authorization: `Bearer ${this.apiKey}` } });
27
+ if (res.ok) return res;
28
+
29
+ let body;
30
+ try {
31
+ body = await res.json();
32
+ } catch {
33
+ body = undefined;
34
+ }
35
+ // 402 (out of credits) uses a flat shape; every other error uses { error: { code, message } }.
36
+ const code = res.status === 402 ? "QUOTA_EXCEEDED" : body?.error?.code;
37
+ const message = res.status === 402 ? "Out of credits" : body?.error?.message ?? `HTTP ${res.status}`;
38
+ throw new TranscriptYTError(message, { status: res.status, code, body });
39
+ }
40
+
41
+ /**
42
+ * Fetch a transcript. Returns parsed JSON for format "json" (default), otherwise the file body as a string.
43
+ * @param {string} url YouTube URL or 11-character video ID
44
+ */
45
+ async getTranscript(url, { language, translateTo, format, includeSegments, timestamps, paragraphs } = {}) {
46
+ const res = await this.#request("/v1/transcript", {
47
+ url,
48
+ language,
49
+ translate_to: translateTo,
50
+ format,
51
+ includeSegments,
52
+ timestamps,
53
+ paragraphs,
54
+ });
55
+ return !format || format === "json" ? res.json() : res.text();
56
+ }
57
+
58
+ /** List a video's caption tracks. Free. */
59
+ async listLanguages(url) {
60
+ return (await this.#request("/v1/languages", { url })).json();
61
+ }
62
+
63
+ /** Plan and remaining credits. Free. */
64
+ async getUsage() {
65
+ return (await this.#request("/v1/usage")).json();
66
+ }
67
+ }
68
+
69
+ export default TranscriptYT;
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "transcriptyt",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "YouTube Transcript API client: get any YouTube video's transcript as JSON, text, SRT, or VTT in 150+ languages.",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "default": "./index.js"
12
+ }
13
+ },
14
+ "files": ["index.js", "index.d.ts", "README.md", "LICENSE"],
15
+ "engines": { "node": ">=18" },
16
+ "keywords": ["youtube", "transcript", "youtube-transcript", "youtube-transcript-api", "captions", "subtitles", "srt", "vtt", "mcp", "llm"],
17
+ "homepage": "https://transcript-yt.com",
18
+ "repository": { "type": "git", "url": "git+https://github.com/rajdeep-automation/transcriptyt.git", "directory": "js" },
19
+ "bugs": "https://github.com/rajdeep-automation/transcriptyt/issues",
20
+ "license": "MIT"
21
+ }