From c1a497288933c9c8804536db0f707ef9b3bdb984 Mon Sep 17 00:00:00 2001 From: nikili0n Date: Tue, 15 Aug 2023 20:51:44 +0300 Subject: [PATCH] fix extension and downloading --- src/api/api_v1/endpoints/main.py | 13 +++++++------ src/templates/index.html | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/api/api_v1/endpoints/main.py b/src/api/api_v1/endpoints/main.py index 593b7fe..b8658be 100644 --- a/src/api/api_v1/endpoints/main.py +++ b/src/api/api_v1/endpoints/main.py @@ -11,7 +11,6 @@ from src.exceptions.download_exceptions import SiteNotImplementedException main_router = APIRouter() - templates = Jinja2Templates(directory="templates") @@ -24,13 +23,15 @@ async def index(request: Request): async def get_url_for_download_video(request: Request, link: str = Form(...)): file_name = VideoDownloader.get_unique_video_filename() ydl_opts = { - "forceurl": True, - 'outtmpl': f'downloads/%(extractor_key)s/{file_name}.%(ext)s' - } + "forceurl": True, + "format": "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best", + "merge_output_format": "mp4", + 'outtmpl': f'downloads/%(extractor_key)s/{file_name}.%(ext)s', + } downloader = VideoDownloader(link=link, ydl_opts=ydl_opts) try: result = downloader.download() - link_to_download_video = str(request.base_url) + f"{file_name}.{result['formats'][-1]['ext']}" + link_to_download_video = str(request.base_url) + f"{file_name}.{result['ext']}" except SiteNotImplementedException as ex: raise HTTPException( status_code=400, @@ -44,4 +45,4 @@ async def download_video(file_path): base = os.path.dirname(os.path.dirname(os.path.abspath(file_path))) base_download_dir = os.path.join(base, "src", "downloads") youtube_dir = os.path.join(base_download_dir, "Youtube") - return FileResponse(youtube_dir + f'/{file_path}', media_type="multipart/form-data") + return FileResponse(youtube_dir + f'/{file_path}', media_type="video") diff --git a/src/templates/index.html b/src/templates/index.html index 7984935..ebf5dcd 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -77,7 +77,7 @@

Ссылка для скачивания:


- +