I'm getting an attribute error for this line(Line 15).
videoStream.download(download_Folder)
when i try to run the code i get "AttributeError: 'function' object has no attribute 'download'".
Here's the full code if it helps.
import tkinter as tk
from tkinter import Button, Entry, Label, StringVar, messagebox, filedialog
from pytube import YouTube
def download_url():
Youtube_link = video_link.get()
download_Folder = download_folder1.get()
getVideo = YouTube(Youtube_link)
AorV = messagebox.askyesno('Video Type','Do you want Audio only?')
if AorV == 'yes' :
videoStream = getVideo.streams.get_audio_only
videoStream.download(download_Folder)
else:
videoStream = getVideo.streams.first
videoStream.download(download_Folder)
messagebox.showinfo('Success','Downloaded to \n'+download_Folder)
def browse_folder():
folder_name = filedialog.askdirectory(initialdir='D:\aweso\Downloads')
download_folder1.set(folder_name)
#GUI
root = tk.Tk()
root.geometry('300x200')
root.resizable(False,False)
root.title('Youtube Downloader')
url_label = Label(root, text='Youtube URL')
url_label.pack()
video_link = StringVar()
url_link = Entry(root, textvariable= video_link)
url_link.pack()
download_folder1 = StringVar()
download_folder1.set('Select Folder')
downloadvid = Button(root, text='Download',command=download_url)
downloadvid.pack()
selected_folder = Label(root,textvariable=download_folder1)
selected_folder.pack()
browse = Button(root,text='Browse',command=browse_folder)
browse.pack()
root.mainloop()
The StreamQuery
objects exposed by getVideo.streams
have get_audio_only()
and first()
as methods, not attributes - you have to call them like the functions they are.
https://pytube.io/en/latest/api.html#pytube.query.StreamQuery.first
https://pytube.io/en/latest/api.html#pytube.query.StreamQuery.get_audio_only