A simple FastAPI service that downloads YouTube video subtitles and extracts them as plain text files asynchronously.
This service accepts a YouTube video URL, downloads its English subtitles (automatic or manual), converts them to plain text, and stores the result in a file linked to a unique task ID. You can query the processing result by task ID later.
GET /- Description: Checks if the service is running.
- Response:
{
"status": "ok",
"message": "subtitle extractor service running"
}POST /downsub
Content-Type: application/json- Request Body:
{
"url": "https://www.youtube.com/watch?v=VIDEO_ID"
}- Response:
{
"task_id": "unique_task_id_here",
"status": "processing",
"message": "Video processing started: https://www.youtube.com/watch?v=VIDEO_ID"
}- Description: Submits a YouTube video URL for subtitle extraction. Returns a unique
task_idto track progress.
GET /downsub/result/{task_id}- Response (if processing complete):
{
"task_id": "unique_task_id_here",
"content": "Extracted subtitle plain text content ..."
}- Response (if still processing or not ready):
{
"status": "processing"
}- Description: Retrieve the extracted subtitle content by providing the
task_idreceived at submission.
-
Clone the repository.
-
Install dependencies:
pip install -r requirements.txt- Run the FastAPI server:
uvicorn main:app --host 0.0.0.0 --port 5000- The service uses
yt-dlpto download subtitles; please ensureffmpegis installed on your system for best results. - Output subtitle text files are stored in the
output/directory. - The subtitle extraction process runs asynchronously in the background.
curl -X POST "http://localhost:5000/downsub" \
-H "Content-Type: application/json" \
-d '{"url":"https://www.youtube.com/watch?v=LnX3B9oaKzw"}'curl "http://localhost:5000/downsub/result/{task_id}"Replace {task_id} with the actual ID returned from the POST request.
MIT License