Reputation: 11
I'm trying to download from Youtube using pytube,firsty I had a common issue which I think was an issue in the module itself,so I upgraded it with github,then another error occured in this code:
#importing the module
from pytube import YouTube
#where to Save
save_path = "E:\Mohamed's sessions\pytube"
#link of the youtube video to be downloaded
link = "https://www.youtube.com/watch?v=w9TcErzdoTg"
#creating an object using YouTube which was imported beofre
yt = YouTube(link) # now this yt is an object created by the class youtube and has the attribute link
#filtering out all the files with mp4 extinsion
mp4files = yt.filter("mp4")
#setting the video name
yt.set_filename("Reiner and Bertholdt Transformation scene")
#get the video with the extension and resolution passed in the get() function
d_video = yt.get(mp4files[-1].extension,mp4files[-1].resolution)
try:
#downloading the video
d_video.download(save_path)
except:
print("Some Error!")
print('Task Completed!')
The error title is: AttributeError: 'YouTube' object has no attribute 'filter' How Can I fix it?
Upvotes: 1
Views: 6667
Reputation: 85
The above program requires .mp4 to be added along with the file name otherwise we won't be able to open the file.
Upvotes: 2
Reputation: 131
Here is a simpler code that may solve the problem you have encountered:
from pytube import YouTube
link = "https://www.youtube.com/watch?v=w9TcErzdoTg"
yt = YouTube(link)
try:
yt.streams.filter(progressive = True,
file_extension = "mp4").first().download(output_path = "E:\Mohamed's sessions\pytube",
filename = "Reiner and Bertholdt Transformation scene")
except:
print("Some Error!")
print('Task Completed!')
Upvotes: 13