How To Make User Download Files Client-side In A Flask Web Application?
Solution 1:
Instead of downloading the video using y.download([url])
you can extract info only like below:
from flask import jsonify
with youtube_dl.YoutubeDL(options) as y:
try:
r = y.extract_info(url, download=False)
return jsonify(r)
except:
return jsonify({'error':'An error has occured'})
Then you can parse the json response to extract the download link and return it to user, so the user will download directly from the video host cdn instead of consuming bandwidth from your backend.
Solution 2:
It's obvious that you are doing server side processing to first download the Youtube video then send it to user as attachment. The main engine (youtube-dl) that does the downloading is located in your backend server not in the end user's PC to have something like you suggested.
There are two approaches to fix the problem:
Deploy your app server in a hosting provider having high bandwidth and high processing. This will significantly reduce your downloading time plus video processing (if any).
If you really want to do all the heavy lifting by the end user. You should opt to client side processing i.e. using JS applications. And for that you can use following JS libraries to do the youtube-dl work.
https://github.com/fent/node-youtube-dlhttps://github.com/fent/node-ytdlhttps://github.com/fent/node-ytdl-core
Post a Comment for "How To Make User Download Files Client-side In A Flask Web Application?"