This project is a Cloudflare Worker that provides an API for retrieving transcripts from YouTube videos. It allows users to fetch transcript data in JSON, SRT, or plain text format.
- Fetch transcripts from YouTube videos using the video URL
- Support for multiple output formats: JSON, SRT, and plain text
- OpenAPI specification for easy integration
- Error handling for invalid URLs, missing transcripts, and more
GET /api/transcript
url
(required): The full URL of the YouTube videooutput
(optional): The desired output format (json, srt, or text). Defaults to json.
https://your-worker-url.workers.dev/api/transcript?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ&output=json
-
JSON (default):
[ { "text": "Never gonna give you up", "start": 0.5, "duration": 2.3 }, ... ]
-
SRT:
1 00:00:00,500 --> 00:00:02,800 Never gonna give you up 2 00:00:02,800 --> 00:00:05,100 Never gonna let you down
-
Plain Text:
Never gonna give you up Never gonna let you down ...
The API provides an OpenAPI specification at the /openapi.json
endpoint. This can be used to generate client libraries or integrate with API documentation tools.
The API returns appropriate HTTP status codes and error messages for various scenarios:
- 400: Bad request (Invalid YouTube URL or output format)
- 404: Transcript not available for the video
- 429: Rate limit exceeded
- 500: Internal server error
This project is designed to run on Cloudflare Workers. To set up the development environment:
-
Install Wrangler:
npm install -g wrangler
-
Authenticate Wrangler with your Cloudflare account:
wrangler login
Follow the prompts to log in through your browser. -
Clone this repository:
git clone https://github.com/jamesflores/youtube-subtitles-worker.git
cd youtube-subtitles-worker -
Configure your wrangler.toml file with your account details and Worker name.
-
Run the development server:
wrangler dev
This will start a local server for testing your Worker. -
To deploy to Cloudflare Workers:
wrangler deploy
MIT License
Submit a pull request
james [at] jamesflores [dot] net