Skip to content

Commit c873140

Browse files
committed
Minimal working state
1 parent f1917d6 commit c873140

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

app/main.py

+4-16
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,12 @@ async def home(request: Request):
2828
async def download(request: VideoRequest):
2929
""" Download a video or audio based on the frontend request """
3030
url = request.url
31-
ydl_opts = {
32-
'quiet': True,
33-
'extract_flat': True,
34-
}
31+
print(request)
3532

3633
try:
37-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
38-
info = ydl.extract_info(url, download=False)
39-
if not info:
40-
raise HTTPException(status_code=400, detail="Could not retrieve video info")
41-
42-
video_data = {
43-
"title": info.get("title"),
44-
"author": info.get("uploader"),
45-
"thumbnail": info.get("thumbnail"),
46-
"resolutions": sorted(set(f["format_note"] for f in info.get("formats", []) if "format_note" in f))
47-
}
48-
return video_data
34+
video = await download_video(url)
35+
print(video)
36+
return FileResponse(path=f"{video}", media_type="video/mp4" )
4937
except Exception as e:
5038
raise HTTPException(status_code=500, detail=str(e))
5139

app/modules/downloader.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def download_audio(video_url, output_path, thumb):
8585
except Exception as e:
8686
print(f"Audio download failed: {e}")
8787

88-
def download_video(url, output_path="downloads/%(title)s.%(ext)s",):
88+
async def download_video(url ):
8989
"""Downloads video with user-selected format."""
90-
90+
output_path="downloads/%(title)s.%(ext)s"
9191
ydl_opts = {
9292
'format': 'bestvideo+bestaudio/best',
9393
'merge_output_format': 'mp4',
@@ -101,7 +101,12 @@ def download_video(url, output_path="downloads/%(title)s.%(ext)s",):
101101
# ydl_opts['cookiefile'] = 'cookies/youtube.txt'
102102

103103
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
104-
ydl.download([url])
104+
video_info = ydl.extract_info(url, download=True)
105+
video_file = ydl.prepare_filename(video_info)
106+
107+
print(video_file)
108+
return str(video_file)
109+
105110
except Exception as e:
106111
print(f"Video download failed: {e}")
107112

downloads/1 Second Video.mp4

162 KB
Binary file not shown.

templates/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h4>Choose Resolution</h4>
106106

107107
// Send request to FastAPI backend
108108
const response = await fetch("/download", {
109-
method: "GET",
109+
method: "POST",
110110
headers: { "Content-Type": "application/json" },
111111
body: JSON.stringify({
112112
url: videoData.url,

0 commit comments

Comments
 (0)