A FastAPI-based server providing API endpoints for extracting and processing YouTube video data, including metadata, captions, and timestamps.
- Extract video metadata using YouTube's oEmbed API
- Retrieve video captions/transcripts
- Generate timestamped captions
- RESTful API with Swagger/OpenAPI documentation
- Docker support for easy deployment
- Python 3.8+
- FastAPI
- youtube-transcript-api
- Docker (optional)
-
Clone the repository:
git clone https://github.com/chinpeerapat/youtube-api-server.git cd youtube-api-server
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file from the example:cp .env.example .env
-
Run the server:
python -m app.main
-
Clone the repository:
git clone https://github.com/chinpeerapat/youtube-api-server.git cd youtube-api-server
-
Build and start the Docker container:
docker-compose up -d
Once the server is running, you can access:
- API documentation: http://localhost:8000/docs
- Alternative API documentation: http://localhost:8000/redoc
POST /youtube/video-data
Request body:
{
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
Response:
{
"title": "Video Title",
"author_name": "Channel Name",
"author_url": "https://www.youtube.com/channel/...",
"type": "video",
"height": 113,
"width": 200,
"version": "1.0",
"provider_name": "YouTube",
"provider_url": "https://www.youtube.com/",
"thumbnail_url": "https://i.ytimg.com/vi/..."
}
POST /youtube/video-captions
Request body:
{
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"languages": ["en"]
}
Response:
"Text of the captions..."
POST /youtube/video-timestamps
Request body:
{
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"languages": ["en"]
}
Response:
[
"0:00 - Caption at the beginning",
"0:05 - Next caption",
"0:10 - Another caption"
]
youtube-api-server/
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI application initialization
│ ├── models/ # Pydantic models
│ │ ├── __init__.py
│ │ └── youtube.py
│ ├── routes/ # API routes
│ │ ├── __init__.py
│ │ └── youtube.py
│ └── utils/ # Utility functions
│ ├── __init__.py
│ └── youtube_tools.py
├── .env.example # Example environment variables
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
└── docker-compose.yml # Docker Compose configuration
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.