I am trying to make a YouTube front end website thing. When I enter a YouTube video name, it returns a blank video. I attached an image of it. What is wrong with the code? Does it have something to do with formats when youtube-dl downloads them?
Main.py:
import youtube_dl
import random
import os
for x in os.listdir("./"):
if x.endswith((".mp4", ".webm", ".mkv")):
os.remove(x)
app = flask.Flask(__name__)
@app.route("/")
def main():
return flask.render_template("main.html")
@app.route("/download/", methods=["POST", "GET"])
def download():
if flask.request.method == "POST":
number = random.randint(1, 400)
ytdl = youtube_dl.YoutubeDL({"outtmpl" : f"{number}"})
title = flask.request.form.get("title")
ytdl.download([f"ytsearch:{title}"])
return flask.redirect(f"/video/{number}")
@app.route("/video/<number>")
def video(number):
return flask.render_template("video.html", number=number)
@app.route("/source/<number>")
def source(number):
for x in os.listdir("./"):
if x.startswith(f"{number}"):
return flask.send_file(x)
app.run("0.0.0.0")
Main.html:
<h1>Please enter a title</h1>
<form method="POST" action="/download/{{title}}">
<input type="text" name="title">
<button type="submit">Ok</button>
</form```
Video.html:
```html
<video width="320" height="240" controls playsinline>
<source src="/source/{{number}}" type="video/mp4" />
</video>```