fix extension and downloading
This commit is contained in:
parent
934fde77ec
commit
c1a4972889
@ -11,7 +11,6 @@ from src.exceptions.download_exceptions import SiteNotImplementedException
|
||||
|
||||
main_router = APIRouter()
|
||||
|
||||
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
||||
@ -25,12 +24,14 @@ 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'
|
||||
"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")
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user