A FastAPI-based server that provides convenient endpoints for extracting information from YouTube videos, including video metadata, captions, and timestamped transcripts.
- Get video metadata (title, author, thumbnails, etc.)
- Extract video captions/transcripts
- Generate timestamped transcripts
- Support for multiple languages in captions
- Clean and RESTful API design
- Python 3.7+
- pip (Python package manager)
- Clone the repository:
git clone https://github.com/zaidmukaddam/youtube-api-server.git
cd youtube-api-server
- Install the required dependencies:
pip install -r requirements.txt
Start the server using:
python main.py
By default, the server runs on:
- Host: 0.0.0.0
- Port: 8000
You can customize these using environment variables:
export PORT=8080
export HOST=127.0.0.1
python main.py
POST /video-data
Request Body:
{
"url": "https://www.youtube.com/watch?v=VIDEO_ID"
}
Response: Video metadata including title, author, thumbnails, etc.
POST /video-captions
Request Body:
{
"url": "https://www.youtube.com/watch?v=VIDEO_ID",
"languages": ["en", "es"] // Optional
}
Response: Complete transcript text of the video.
POST /video-timestamps
Request Body:
{
"url": "https://www.youtube.com/watch?v=VIDEO_ID",
"languages": ["en"] // Optional
}
Response: List of timestamps with corresponding caption text.
Using curl:
# Get video metadata
curl -X POST "http://localhost:8000/video-data" \
-H "Content-Type: application/json" \
-d '{"url": "https://www.youtube.com/watch?v=VIDEO_ID"}'
# Get video captions
curl -X POST "http://localhost:8000/video-captions" \
-H "Content-Type: application/json" \
-d '{"url": "https://www.youtube.com/watch?v=VIDEO_ID", "languages": ["en"]}'
The API includes comprehensive error handling for:
- Invalid YouTube URLs
- Missing or unavailable captions
- Network errors
- Invalid language codes
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.