This is a Next.js project demonstrating the use of the youtube-caption-extractor npm package. It allows users to fetch subtitles and video details from YouTube videos using this package.
- Fetch subtitles from YouTube videos
- Retrieve video details including title and description
- Support for multiple languages
npm install
npm run devOpen http://localhost:3000. By default, the UI calls the local Next.js API routes.
The API app lives in server/ and can be run separately from Next.js.
For the fastest local loop, run the Hono API directly and point the Next.js API routes at it:
npm --prefix server install
npm run api:dev
CAPTION_API_BASE_URL=http://localhost:8080 npm run devTo test the full local Worker → Cloudflare Container path, run Wrangler with Docker and point the Next.js API routes at Wrangler:
npm --prefix server install
npm run cf:dev
CAPTION_API_BASE_URL=http://localhost:8787 CAPTION_API_TOKEN=<token> npm run devCloudflare dashboard "live instances" only reflects deployed Cloudflare traffic. It does not change when testing the local Hono API or local Wrangler container.
This sample includes a self-contained Cloudflare Containers app in server/. It runs the API as a Dockerized Hono Node server and proxies requests through a Hono Worker.
npm --prefix server install
npm run cf:deployAfter deploy, set Vercel/Next.js server-side environment variables to the Worker URL and shared API token:
CAPTION_API_BASE_URL=https://<your-worker>.<your-subdomain>.workers.dev
CAPTION_API_TOKEN=<same-token-configured-on-the-worker>Do not put CAPTION_API_TOKEN in a NEXT_PUBLIC_* variable. The browser calls the Next.js API routes, and the Next.js server attaches the token when it calls the Worker.
The container endpoint supports:
GET /healthGET /api/subtitles?videoID=<id>&lang=enGET /api/videoDetails?videoID=<id>&lang=en
Optional runtime environment variables:
CAPTION_API_TOKEN— shared bearer token required by the Worker before it proxies to the container.OUTBOUND_PROXY_URL— routes YouTube requests through an HTTP(S) proxy viaundici.CACHE_TTL_SECONDS— controls the warm in-memory response cache, default21600.ALLOWED_ORIGINS— comma-separated browser origins for CORS, default*.CONTAINER_VERSION— version prefix for container instance names; bump it to force fresh instances during rollouts.
From server/, use npx wrangler secret put CAPTION_API_TOKEN to set the shared token on Cloudflare.
From server/, use npx wrangler secret put OUTBOUND_PROXY_URL if the proxy URL contains credentials.
If the API returns youtube_blocked_datacenter_ip, the request reached the Cloudflare container but YouTube blocked the container's outbound datacenter IP. Use direct local API testing (http://localhost:8080) for local machine egress, or configure OUTBOUND_PROXY_URL with a trusted proxy for deployed Cloudflare container testing.
- Enter the YouTube video ID in the "Video ID" field.
- Specify the desired language code in the "Language" field (e.g., 'en', 'es', 'fr') or leave it empty.
- Click "Fetch Data" to retrieve the subtitles and video details.