initial commit
This commit is contained in:
34
src/api/api_v1/endpoints/main.py
Normal file
34
src/api/api_v1/endpoints/main.py
Normal 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
5
src/api/deps.py
Normal 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)
|
Reference in New Issue
Block a user