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()
|
main_router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
templates = Jinja2Templates(directory="templates")
|
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(...)):
|
async def get_url_for_download_video(request: Request, link: str = Form(...)):
|
||||||
file_name = VideoDownloader.get_unique_video_filename()
|
file_name = VideoDownloader.get_unique_video_filename()
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
"forceurl": True,
|
"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)
|
downloader = VideoDownloader(link=link, ydl_opts=ydl_opts)
|
||||||
try:
|
try:
|
||||||
result = downloader.download()
|
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:
|
except SiteNotImplementedException as ex:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=400,
|
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 = os.path.dirname(os.path.dirname(os.path.abspath(file_path)))
|
||||||
base_download_dir = os.path.join(base, "src", "downloads")
|
base_download_dir = os.path.join(base, "src", "downloads")
|
||||||
youtube_dir = os.path.join(base_download_dir, "Youtube")
|
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">
|
<div class="col">
|
||||||
<p> Ссылка для скачивания:</p>
|
<p> Ссылка для скачивания:</p>
|
||||||
<br>
|
<br>
|
||||||
<a id="result" href=""></a>
|
<a id="result" href="" download></a>
|
||||||
<div class="loader">
|
<div class="loader">
|
||||||
<div class="loader_inner"></div>
|
<div class="loader_inner"></div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user