0

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?

Picture is here

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>```
  • Guessing this is a format issue: downloaded format not compatible with HTML5 `video` tag. See threads like [this one](https://stackoverflow.com/questions/21192713/how-to-playback-mkv-video-in-web-browser) for a potential solution. – v25 Feb 26 '21 at 18:16
  • @v25 I updated my code. This new code downloads mp4 video and works on Firefox for desktop but not for Safari for iPad or Firefox for iPad. I think its maybe just a compatibility issue that iPad has? – TricolorHen061 Feb 26 '21 at 21:37

0 Answers0