Então, quando executo o Pytube dentro do script, ele leva 30 segundos para terminar, mas quando executo em uma função, ele leva apenas 0,96 segundos para terminar. Por quê? Alguém pode explicar em termos simples, já que sou iniciante em Python?
aqui levou apenas 0,96 segundos para terminar "dentro de uma função"
aqui demorou 30s para terminar em uma linha normal
e a função realmente pega todos os vídeos? porque eu imprimo o índice aleatório e ele me dá um pequeno número como 60 de 3000 vídeos aqui está o script
import pytube
import time
StarterTick = time.time()
print(StarterTick,type(StarterTick))
VideoList = "list=PLKB9puQeauyBTnMmRWsB4VVfbbWR0tKCc"
PlayList = f"https://www.youtube.com/playlist?{VideoList}"
def getRandomVideo():
PlayListVideos = pytube.contrib.playlist.Playlist(PlayList,)
randomIndex = random.randint(0,len(PlayList) -1) # -1 cuz list start with 0 so if we have 5 items it would be 4 but len would return 5
print(f"your random index is {randomIndex}")
return PlayListVideos[randomIndex] # just return a random video from youtube list
# this way it takes 30 s to finish PlayListVideos = pytube.contrib.playlist.Playlist(PlayList)
print(f"here is your random Video {getRandomVideo()}")
print("programm finished")
print(f"THe programm took {time.time() - StarterTick:>3.2f} seconds to finish")