0

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")"""
2
  • 2
    your allocating q as str.lower this is the method its self. you need to call the method so you get a return value str.lower(). EG. q = str(input("Which quality you want ? 360p,480p,720p,1080p,4K,Flh :")).lower() Commented Jan 21, 2021 at 18:44
  • Man i Love you, this solved the problem. @chris doyle Commented Jan 21, 2021 at 18:46

1 Answer 1

1

I forget to call the method q.lower(), i called it without the parentheses. Thanks to @Chris Doyle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.