0

Why would this command run as expected in the command line, downloading only the specified part of the video, but using the python library of yt-dlp it would download the whole video instead?? yt-dlp https://www.youtube.com/watch?v=MtN1YnoL46Q --download-sections "*00:02:05-00:02:10" --force-keyframes-at-cuts I'm trying to send the downloaded part of video as a response for my flask api endpoint, but the whole video gets downloaded, its like the ydl_opts get totally ignored.

from flask import Flask, make_response, request
import yt_dlp
from flask_cors import CORS

app = Flask(__name__, static_folder='static')

CORS(app, expose_headers=['Filename'])
 
@app.route("/downloadpart/", methods=['POST'])
def download_cut():
    if request.method == 'POST':
        url = request.form.get('link')  
        ydl_opts = {'format': 'best',
                    'download_sections' : "*00:02:05-00:02:10", 
                    'force_keyframes_at_cuts' : True,
                    }
        try:
            with yt_dlp.YoutubeDL(ydl_opts) as ydl:
                info_dict = ydl.extract_info(url, download=False)
                video_url = info_dict['url']
                video_data = ydl.urlopen(video_url).read()
                headers = {
                    'Content-Type': 'video/mp4',
                }
                return make_response(video_data, 200, headers)
        except Exception as e:
            return make_response(e)
    return make_response("Invalid request", 400)


if __name__ == '__main__':
    #app.run(debug=True) 
    app.run(debug=False, host='0.0.0.0', port=5000) 

Am I writing the ydl_opts wrong? What am I doing wrong? Why is the whole video downloaded instead of the specified part? I dont want to download it on the server an then use something as ffmpeg on it to cut it

JohnnySmith88
  • 162
  • 1
  • 10

0 Answers0