A FastAPI-based service that fetches and formats YouTube video transcripts.
- Extract transcripts from YouTube videos
- Format transcripts with timestamps
- REST API endpoint for easy integration
- Error handling and logging
- Python 3.7+
- youtube_transcript_api
- fastapi
- uvicorn
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
Start the API server:
python transcript_api.py
The API will be available at: http://localhost:8000
POST /transcript
Request body:
{
"url": "YouTube video URL"
}
Example request:
curl -X POST "http://localhost:8000/transcript" \
-H "Content-Type: application/json" \
-d '{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"}'
Example response:
{
"transcript": "[0.00] Never gonna give you up\n[3.58] Never gonna let you down\n[7.16] Never gonna run around and desert you"
}
You can also use the script directly:
echo "https://www.youtube.com/watch?v=dQw4w9WgXcQ" | python youtube_transcript.py
The API returns appropriate HTTP status codes:
- 400: Invalid YouTube URL or transcript unavailable
- 500: Internal server error
All errors are logged with timestamps for debugging.
To run in development mode with auto-reload:
uvicorn transcript_api:app --reload