How to build a frontend for my youtube video downloader program?

Question:

I want to build a basic frontend for the below program, so that when users enter the app they will get the same output as in a python interpreter.
here is the python code

from pytube import YouTube

def Download(link):
  youtubeObject = YouTube(link)
  youtubeObject = youtubeObject.streams.get_highest_resolution()
  try:
      youtubeObject.download()
  except:
    print("There has been an error in downloading your youtube video")
  print("This download has completed! Yahooooo!")

link = input("Put your youtube link here!! URL: ")
Download(link)

I am expecting to build a small app where users can enter their video link and download the video. I just want to learn how to integrate it with a good looking user interface.

Asked By: Debanjan

||

Answers:

  1. A web browser cannot interpret python, so your python code will live on an another computer.
  2. That another computer is a server, and to communicate with the server, you’ll need an API route. e.g (/process)
  3. The frontend will hit the API with the link as a parameter. (let’s say) (/process?link=<youtube-link>)
  4. The logic for handling that API will be written on the server. You can choose any language for that. Since you’re familiar with Python already, use Flask or Fast API.
  5. Once you host your server code you’re ready for communicating with the front-end with simple Fetch API.

References:

  1. https://flask.palletsprojects.com/en/2.2.x/
  2. https://fastapi.tiangolo.com/
  3. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
Answered By: Badal Saibo
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.