initial commit

This commit is contained in:
2023-08-12 13:06:41 +03:00
committed by nikili0n
commit 3a6eccebb5
10 changed files with 631 additions and 0 deletions

View File

@ -0,0 +1,34 @@
from fastapi import APIRouter, Form, HTTPException
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.templating import Jinja2Templates
from src.core.ydl import VideoDownloader
from src.exceptions.download_exceptions import SiteNotImplementedException
main_router = APIRouter()
templates = Jinja2Templates(directory="templates")
@main_router.get("/", response_class=HTMLResponse)
async def index(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@main_router.post('/submit')
def disable_cat(request: Request, link: str = Form(...)):
downloader = VideoDownloader(link=link, ydl_opts={
"forceurl": True,
"username": "garick.badalov@yandex.ru",
"password": "garik876.",
})
try:
result = downloader.download()
except SiteNotImplementedException as ex:
raise HTTPException(
status_code=400,
detail=ex.message
)
return templates.TemplateResponse("index.html", {"request": request, "result": result["url"]})

5
src/api/deps.py Normal file
View File

@ -0,0 +1,5 @@
from src.core.ydl import VideoDownloader
def get_downloader(link: str, opts: dict):
return VideoDownloader(link=link, ydl_opts=opts)