added link
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import os
|
||||
|
||||
from fastapi import APIRouter, Form, HTTPException
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import HTMLResponse
|
||||
from starlette.responses import HTMLResponse, FileResponse
|
||||
from starlette.templating import Jinja2Templates
|
||||
|
||||
from src.core.ydl import VideoDownloader
|
||||
@ -18,17 +20,30 @@ async def index(request: Request):
|
||||
|
||||
|
||||
@main_router.post('/submit')
|
||||
def disable_cat(request: Request, link: str = Form(...)):
|
||||
downloader = VideoDownloader(link=link, ydl_opts={
|
||||
async def get_url_for_download_video(request: Request, link: str = Form(...)):
|
||||
file_name = VideoDownloader.get_unique_video_filename()
|
||||
ydl_opts = {
|
||||
"forceurl": True,
|
||||
"username": "garick.badalov@yandex.ru",
|
||||
"password": "garik876.",
|
||||
})
|
||||
'outtmpl': f'downloads/%(extractor_key)s/{file_name}.%(ext)s'
|
||||
# "username": "garick.badalov@yandex.ru",
|
||||
# "password": "garik876.",
|
||||
}
|
||||
|
||||
downloader = VideoDownloader(link=link, ydl_opts=ydl_opts)
|
||||
try:
|
||||
result = downloader.download()
|
||||
file_path = str(request.base_url) + f"{file_name}.mp4"
|
||||
except SiteNotImplementedException as ex:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=ex.message
|
||||
)
|
||||
return templates.TemplateResponse("index.html", {"request": request, "result": result["url"]})
|
||||
return templates.TemplateResponse("index.html", {"request": request, "result": file_path})
|
||||
|
||||
|
||||
@main_router.get('/{file_path}', response_class=FileResponse)
|
||||
async def download_video(request: Request, file_path):
|
||||
base = os.path.dirname(os.path.dirname(os.path.abspath(file_path)))
|
||||
BASE_DOWNLOAD_DIR = os.path.join(base, "src", "downloads")
|
||||
BASE_YOUTUBE_DIR = os.path.join(BASE_DOWNLOAD_DIR, "Youtube")
|
||||
return BASE_YOUTUBE_DIR + f'/{file_path}'
|
||||
|
Reference in New Issue
Block a user