'how to download youtube video in the highest quality available

This code works perfectly, but I don't want the lowest quality. I want the highest one. When I tried changing the video = youtube. streams.first() to video = youtube.streams.last() I encountered a problem where the video that I downloaded was just a black screen with the audio playing in the background.

from tkinter import *
import pytube


# Functions
def download():
    video_url = url.get()
    try:
        youtube = pytube.YouTube(video_url)
        video = youtube.streams.first()
        video.download("C:/Users/iwanh/Desktop/MP4_MP3s")
        notif.config(fg="green", text="Download complete")
    except Exception as e:
        print(e)
        notif.config(fg="red", text="Video could not be downloaded")


# Main Screen
master = Tk()
master.title("Youtube Video Downloader")

# Labels
Label(master, text="Youtube Video Converter", fg="red", font=("Calibri", 15)).grid(sticky=N, padx=100, row=0)
Label(master, text="Please enter the link to your video below : ", font=("Calibri", 15)).grid(sticky=N, row=1, pady=15)
notif = Label(master, font=("Calibri", 12))
notif.grid(sticky=N, pady=1, row=4)
# Vars
url = StringVar()
# Entry
Entry(master, width=50, textvariable=url).grid(sticky=N, row=2)
# Button
Button(master, width=20, text="Download", font=("Calibri", 12), command=download).grid(sticky=N, row=3, pady=15)
master.mainloop()


Solution 1:[1]

Try To Use

get_highest_resolution()

Instant Of Contact With Streams

This Func. Returns Highest Progressive Quality : )

May Be Checking The Documentation Will Help You Next Time : )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Omar Essam