Skip to content Skip to sidebar Skip to footer

How To Make User Download Files Client-side In A Flask Web Application?

I'm trying to build a YouTube Downloader using Flask, using the youtube-dl Python API. I've got everything working, but I have an issue with the actual download of the videos. @app

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:

Post a Comment for "How To Make User Download Files Client-side In A Flask Web Application?"