{"id":47821112,"url":"https://github.com/farhandigital/youtube-transcript-edge","last_synced_at":"2026-04-03T19:09:39.367Z","repository":{"id":342735427,"uuid":"1174469669","full_name":"farhandigital/youtube-transcript-edge","owner":"farhandigital","description":"A JavaScript library to fetch transcripts from YouTube videos. Designed for edge environments like Cloudflare Workers.","archived":false,"fork":false,"pushed_at":"2026-03-31T23:57:37.000Z","size":545,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-01T01:52:32.949Z","etag":null,"topics":["cloudflare-workers","library","npm","typescript","youtube"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/farhandigital.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-06T13:32:17.000Z","updated_at":"2026-03-31T23:57:40.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/farhandigital/youtube-transcript-edge","commit_stats":null,"previous_names":["farhandigital/youtube-transcript-edge"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/farhandigital/youtube-transcript-edge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farhandigital%2Fyoutube-transcript-edge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farhandigital%2Fyoutube-transcript-edge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farhandigital%2Fyoutube-transcript-edge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farhandigital%2Fyoutube-transcript-edge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/farhandigital","download_url":"https://codeload.github.com/farhandigital/youtube-transcript-edge/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farhandigital%2Fyoutube-transcript-edge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31372195,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-workers","library","npm","typescript","youtube"],"created_at":"2026-04-03T19:09:38.675Z","updated_at":"2026-04-03T19:09:39.362Z","avatar_url":"https://github.com/farhandigital.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# youtube-transcript-edge\n\nA JavaScript library to fetch transcripts from YouTube videos. Designed for edge environments like Cloudflare Workers.\n\n**Note:** This project was originally forked from [https://github.com/ericmmartin/youtube-transcript-plus](https://github.com/ericmmartin/youtube-transcript-plus), which only works in Node.js environments. This edge-compatible version removes Node.js specific modules (like `fs`, `path`) to run perfectly on Cloudflare Workers, Vercel Edge, Deno, and Bun.\n\nThis package uses YouTube's unofficial API, so it may break if YouTube changes its internal structure.\n\n## Installation\n\n```bash\n$ bun add youtube-transcript-edge\n```\n\n## Usage\n\n### Basic Usage\n\n```javascript\nimport { fetchTranscript } from 'youtube-transcript-edge';\n\n// Fetch transcript using default settings\nfetchTranscript('videoId_or_URL').then(console.log).catch(console.error);\n```\n\n### Custom User-Agent\n\nYou can pass a custom `userAgent` string to mimic different browsers or devices.\n\n```javascript\nfetchTranscript('videoId_or_URL', {\n  userAgent:\n    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',\n})\n  .then(console.log)\n  .catch(console.error);\n```\n\n### Custom Fetch Functions\n\nYou can inject custom `videoFetch`, `playerFetch`, and `transcriptFetch` functions to modify the fetch behavior, such as using a proxy or custom headers. The library makes three types of HTTP requests:\n\n1. **`videoFetch`**: Fetches the YouTube video page (GET request)\n2. **`playerFetch`**: Calls YouTube's Innertube API to get caption tracks (POST request)\n3. **`transcriptFetch`**: Downloads the actual transcript data (GET request)\n\n```javascript\nfetchTranscript('videoId_or_URL', {\n  videoFetch: async ({ url, lang, userAgent }) =\u003e {\n    // Custom logic for video page fetch (GET)\n    return fetch(`https://my-proxy-server.com/?url=${encodeURIComponent(url)}`, {\n      headers: {\n        ...(lang \u0026\u0026 { 'Accept-Language': lang }),\n        'User-Agent': userAgent,\n      },\n    });\n  },\n  playerFetch: async ({ url, method, body, headers, lang, userAgent }) =\u003e {\n    // Custom logic for Innertube API call (POST)\n    return fetch(`https://my-proxy-server.com/?url=${encodeURIComponent(url)}`, {\n      method,\n      headers: {\n        ...(lang \u0026\u0026 { 'Accept-Language': lang }),\n        'User-Agent': userAgent,\n        ...headers,\n      },\n      body,\n    });\n  },\n  transcriptFetch: async ({ url, lang, userAgent }) =\u003e {\n    // Custom logic for transcript data fetch (GET)\n    return fetch(`https://my-proxy-server.com/?url=${encodeURIComponent(url)}`, {\n      headers: {\n        ...(lang \u0026\u0026 { 'Accept-Language': lang }),\n        'User-Agent': userAgent,\n      },\n    });\n  },\n})\n  .then(console.log)\n  .catch(console.error);\n```\n\n### Language Support\n\nYou can specify the language for the transcript using the `lang` option.\n\n```javascript\nfetchTranscript('videoId_or_URL', {\n  lang: 'fr', // Fetch transcript in French\n})\n  .then(console.log)\n  .catch(console.error);\n```\n\n### Error Handling\n\nThe library throws specific errors for different failure scenarios. Each error includes a `videoId` property for programmatic handling.\n\n```javascript\nimport {\n  YoutubeTranscriptVideoUnavailableError,\n  YoutubeTranscriptDisabledError,\n  YoutubeTranscriptNotAvailableError,\n  YoutubeTranscriptNotAvailableLanguageError,\n} from 'youtube-transcript-edge';\n\nfetchTranscript('videoId_or_URL')\n  .then(console.log)\n  .catch((error) =\u003e {\n    if (error instanceof YoutubeTranscriptVideoUnavailableError) {\n      console.error('Video is unavailable:', error.videoId);\n    } else if (error instanceof YoutubeTranscriptDisabledError) {\n      console.error('Transcripts are disabled:', error.videoId);\n    } else if (error instanceof YoutubeTranscriptNotAvailableError) {\n      console.error('No transcript available:', error.videoId);\n    } else if (error instanceof YoutubeTranscriptNotAvailableLanguageError) {\n      console.error('Language not available:', error.lang, error.availableLangs);\n    } else {\n      console.error('An unexpected error occurred:', error.message);\n    }\n  });\n```\n\n### Example Usage Files\n\nThe repository includes several example files in the `example/` directory to demonstrate different use cases of the library:\n\n1. **`basic-usage.js`**: Demonstrates the simplest way to fetch a transcript using the default settings.\n3. **`language-usage.js`**: Shows how to fetch a transcript in a specific language (e.g., French).\n4. **`proxy-usage.js`**: Demonstrates how to use a proxy server to fetch transcripts, which can be useful for bypassing rate limits or accessing restricted content.\n5. **`custom-fetch-usage.js`**: Shows how to use all three custom fetch functions (`videoFetch`, `playerFetch`, `transcriptFetch`) with logging and custom headers.\n\nThese examples can be found in the `example/` directory of the repository.\n\n### TypeScript Types\n\nAll types are exported for TypeScript consumers:\n\n```typescript\nimport type {\n  TranscriptConfig,\n  TranscriptResponse,\n  FetchParams,\n} from 'youtube-transcript-edge';\n```\n\n### API\n\n### `fetchTranscript(videoId: string, config?: TranscriptConfig)`\n\nFetches the transcript for a YouTube video.\n\n- **`videoId`**: The YouTube video ID or URL.\n- **`config`**: Optional configuration object with the following properties:\n  - **`lang`**: Language code (e.g., `'en'`, `'fr'`) for the transcript.\n  - **`userAgent`**: Custom User-Agent string.\n  - **`videoFetch`**: Custom fetch function for the video page request (GET).\n  - **`playerFetch`**: Custom fetch function for the YouTube Innertube API request (POST).\n  - **`transcriptFetch`**: Custom fetch function for the transcript data request (GET).\n\nReturns a `Promise\u003cTranscriptResponse[]\u003e` where each item in the array represents a transcript segment with the following properties:\n\n- **`text`**: The text of the transcript segment.\n- **`duration`**: The duration of the segment in seconds.\n- **`offset`**: The start time of the segment in seconds.\n- **`lang`**: The language of the transcript.\n\n## Errors\n\nThe library throws the following errors:\n\n- **`YoutubeTranscriptVideoUnavailableError`**: The video is unavailable or has been removed. Properties: `videoId`.\n- **`YoutubeTranscriptDisabledError`**: Transcripts are disabled for the video. Properties: `videoId`.\n- **`YoutubeTranscriptNotAvailableError`**: No transcript is available for the video. Properties: `videoId`.\n- **`YoutubeTranscriptNotAvailableLanguageError`**: The transcript is not available in the specified language. Properties: `videoId`, `lang`, `availableLangs`.\n- **`YoutubeTranscriptTooManyRequestError`**: YouTube is rate-limiting requests from your IP.\n- **`YoutubeTranscriptInvalidVideoIdError`**: The provided video ID or URL is invalid.\n\n## License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarhandigital%2Fyoutube-transcript-edge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarhandigital%2Fyoutube-transcript-edge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarhandigital%2Fyoutube-transcript-edge/lists"}