Hi I want to choose and download a video(I am working in google collab) but I have an error
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) in 18 print(x) 19 while lens < 600: ---> 20 video = random.choice(x) 21 print(video) 22 x = YouTube(video)
/usr/lib/python3.7/random.py in choice(self, seq) 257 """Choose a random element from a non-empty sequence.""" 258 try: --> 259 i = self._randbelow(len(seq)) 260 except ValueError: 261 raise IndexError('Cannot choose from an empty sequence') from None
TypeError: object of type 'YouTube' has no len()
my code:
n = 0
x = []
lens = 0
channel= random.choice(urls)
chanell = Channel(channel)
try:
for video in chanell.video_urls:
x.append(video)
n+=1
except Exception:
print(f"Error 404 on chanell{chanell}")
for video in chanell:
append(video+"\n")
pass
print(n)
print(x)
while lens < 600:
video = random.choice(x)
print(video)
x = YouTube(video)
lenght = x.length
download(video)
lens = lens + length
my download function:
def download(url):
video = YouTube(url)
video_streams = video.streams.filter(file_extension = 'mp4').get_by_itag(22)
video_streams.download(filename = "video.mp4")
code for youtube object is:
from pytube import YouTube
from pytube import Channel
from pytube import Playlist