0% found this document useful (0 votes)
8 views1 page

FastAPI Video Fetch and Download API

This document outlines a FastAPI application with two endpoints for handling video data from URLs. The '/fetch-video' endpoint retrieves video information such as title, thumbnail, duration, and formats without downloading the video. The '/download' endpoint initiates the download of the video in a specified quality format.

Uploaded by

trinotex999
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

FastAPI Video Fetch and Download API

This document outlines a FastAPI application with two endpoints for handling video data from URLs. The '/fetch-video' endpoint retrieves video information such as title, thumbnail, duration, and formats without downloading the video. The '/download' endpoint initiates the download of the video in a specified quality format.

Uploaded by

trinotex999
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

from fastapi import FastAPI, HTTPException

from yt_dlp import YoutubeDL

app = FastAPI()

@[Link]("/fetch-video")
async def fetch_video(url: str):
ydl_opts = {'format': 'best'}
with YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
return {
"title": [Link]("title"),
"thumbnail": [Link]("thumbnail"),
"duration": [Link]("duration"),
"formats": [Link]("formats"),
}

@[Link]("/download")
async def download_video(url: str, quality: str):
ydl_opts = {
'format': quality,
'outtmpl': '%(title)s.%(ext)s',
}
with YoutubeDL(ydl_opts) as ydl:
[Link]([url])
return {"message": "Download started"}

You might also like