fix extension and downloading

This commit is contained in:
Dantenerosas 2023-08-15 20:51:44 +03:00 committed by nikili0n
parent 6d358d9661
commit 9ad9b1e290
2 changed files with 8 additions and 7 deletions

View File

@ -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")

View File

@ -77,7 +77,7 @@
<div class="col">
<p> Ссылка для скачивания:</p>
<br>
<a id="result" href=""></a>
<a id="result" href="" download></a>
<div class="loader">
<div class="loader_inner"></div>
</div>