Reputation: 161
I don't know what is the problem here, its only accepting the first condition the in if statement if I type 480p or 720p it prints me the "Invalid choice", I'll truly appreciate it if you can find the problem this is taking me crazy. I am trying to make a small project that can solve a daily problem i encounter which is downloading videos from youtube, I know there is a lot of codes similar to this, but i've only read the librarys docs and spent time to make it without looking at any guides.
from pytube import *
import ffmpeg
userurl = (input("Enter a youtube video URL : "))
q = str(input("Which quality you want ? 360p,480p,720p,1080p,4K,Flh :")).lower
yt = YouTube(userurl)
print ("Title of the video : ",yt.title)
def hd1080p():
global q
print(yt.streams.filter(mime_type="video/mp4", res="1080p", adaptive = True, fps = 60))
v = yt.streams.get_highest_resolution()
print("Downloading HD 1080p video")
v.download()
print("Video downloaded")
return
def hd720p():
global q
print(yt.streams.filter(file_extension= 'mp4',res="720p", progressive=True, fps = 60))
yd= yt.streams.get_highest_resolution()
print("Downloading HD 720p video")
yd.download()
print("Finished.")
return
def l480p():
global q
print(yt.streams.filter(file_extension= 'mp4',res="480p", progressive=True, fps = 60))
yd= yt.streams.get_highest_resolution()
print("Downloading 480p video")
yd.download()
print("Finished.")
return
def l360p():
global q
print(yt.streams.filter(file_extension= 'mp4',res="360p", progressive=True,fps = 60))
yd= yt.streams.get_highest_resolution()
print("Downloading 360p video")
yd.download()
print("Finished.")
return
def hd4k():
global q
print(yt.streams.filter(mime_type="video/mp4", res="2160p", adaptive = True))
v = yt.streams.get_highest_resolution()
print("Downloading 4k video")
v.download()
print("Video downloaded")
return
if q == "1080" or q == "1080p":
hd1080p()
elif q == "720" or q == "720p":
hd720p()
elif q == "480" or q == "480p":
l480p()
elif q == "360" or q == "360p":
l360p()
elif q == "4" or q == "4k":
hd4k()
else:
print("invalid choice")
""" yt.streams.filter(mime_type="audio")
a = yt.streams.get_audio_only()
print("Downloading audio")
a.download()
print("audio downloaded")"""
Upvotes: 0
Views: 72
Reputation: 161
I forget to call the method q.lower(), i called it without the parentheses. Thanks to @Chris Doyle
Upvotes: 1