Skip to content

Commit f78bb74

Browse files
committed
Appealing frontend
1 parent 29ce583 commit f78bb74

File tree

8 files changed

+992
-123
lines changed

8 files changed

+992
-123
lines changed

app/config.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
from dotenv import load_dotenv
3+
4+
load_dotenv()
5+
6+
class Config:
7+
DB_URL = os.getenv("DB_URL")

app/database.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
from sqlalchemy import create_engine
22
from sqlalchemy.ext.declarative import declarative_base
33
from sqlalchemy.orm import sessionmaker
4-
from dotenv import load_dotenv
5-
import os
4+
from config import Config
65

7-
load_dotenv()
86

9-
DB_URL = os.getenv("DB_URL")
10-
engine = create_engine(DB_URL,echo=True)
7+
engine = create_engine(Config.DB_URL,echo=True)
118
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
129

1310
Base = declarative_base()

app/main.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
import crud, models, schemas
55
from pydantic import BaseModel
66
from database import engine, get_db
7-
from fastapi.responses import FileResponse, JSONResponse
7+
from fastapi.responses import FileResponse, JSONResponse, HTMLResponse
88
from fastapi.staticfiles import StaticFiles
99
from fastapi.templating import Jinja2Templates
1010
from fastapi.middleware.gzip import GZipMiddleware
1111
from modules.downloader import download_video, download_audio
1212

1313
app = FastAPI()
1414

15-
# app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=6)
15+
app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=6)
1616

17-
# app.mount("/static", StaticFiles(directory="static"), name="static")
17+
app.mount("/static", StaticFiles(directory="static"), name="static")
1818

1919
templates = Jinja2Templates(directory="templates")
2020

@@ -23,21 +23,21 @@
2323

2424
class VideoRequest(BaseModel):
2525
url: str
26+
resolution: str
27+
format_type: str
2628

2729

28-
@app.get("/")
30+
@app.get("/", response_class=HTMLResponse)
2931
async def home(request: Request):
30-
return templates.TemplateResponse(name="index.html", request=request)
32+
return templates.TemplateResponse("index.html", {"request": request})
3133

3234

3335
@app.post("/download")
3436
async def download(request: VideoRequest):
3537
""" Download a video or audio based on the frontend request """
36-
url = request.url
37-
print(request)
3838

3939
try:
40-
video = await download_video(url)
40+
video = await download_video(request.url, request.resolution)
4141
print(video)
4242
return FileResponse(path=f"{video}", media_type="video/mp4" )
4343
except Exception as e:

app/modules/downloader.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def delete_file(f_path):
5959
except:
6060
time.sleep(5)
6161

62-
def download_audio(video_url, output_path, thumb):
62+
def download_audio(video_url, output_path,):
6363
"""Downloads audio with metadata and thumbnail."""
6464

6565
try:
@@ -85,14 +85,15 @@ def download_audio(video_url, output_path, thumb):
8585
except Exception as e:
8686
print(f"Audio download failed: {e}")
8787

88-
async def download_video(url ):
88+
async def download_video(url, resolution ):
8989
"""Downloads video with user-selected format."""
9090
output_path="downloads/%(title)s.%(ext)s"
9191
ydl_opts = {
92-
'format': 'bestvideo+bestaudio/best',
92+
'format': f'bestvideo[height={resolution}]+bestaudio/best',
9393
'merge_output_format': 'mp4',
9494
'outtmpl': output_path
9595
}
96+
print(resolution)
9697
try:
9798

9899
# if domain == "instagram.com":
@@ -104,7 +105,8 @@ async def download_video(url ):
104105
video_info = ydl.extract_info(url, download=True)
105106
video_file = ydl.prepare_filename(video_info)
106107

107-
print(video_file)
108+
# video_file = "/downloads/1 Second Video.mp4"
109+
108110
return str(video_file)
109111

110112
except Exception as e:

static/bootstrap.min.css

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/styles.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* body {
2+
background-color: #0f051f;
3+
} */

0 commit comments

Comments
 (0)