alexmercerind/youtube-search-python

got repeted result in playlist

poohzaza166 opened this issue · 3 comments

import time
from pprint import pprint
from youtubesearchpython import *
m = []
playlist = Playlist('https://www.youtube.com/playlist?list=PLKu0PlxNFnZUjUzSxccTzHOgEYYGlSJk5')
# pprint(playlist.videoss)
# for s in playlist.videos:
#     m.append(s['link'])
while playlist.hasMoreVideos:
    # pprint(playlist.videos)
    playlist.getNextVideos()
    time.sleep(5)
    for sg in playlist.videos:
        m.append(sg['link'])
    # playlist.getNextVideos()
    # for ss in playlist.videos:
    #     m.append(ss['link'])
    # playlist.getNextVideos()

print(m)

print(len(m))

this should return around 300 vid
not tripple that

mytja commented

First things first. Next time correctly fill out issue report with Markdown. I will not answer any issues without correct formatting.

Nothing is wrong with this library. You are repetetively appending existing videos to the list. When you call playlist.getNextVideos(), our internal list doesn't clear itself, instead we append new videos to the list. When you are calling for loop every time while fetching more videos, you append the already existing videos to your m list. I also don't know why is this list mandatory, as you can simply use our internal list.

Have a look at this code:

from youtubesearchpython import *

#m = []
playlist = Playlist('https://www.youtube.com/playlist?list=PLKu0PlxNFnZUjUzSxccTzHOgEYYGlSJk5')

while playlist.hasMoreVideos:
    playlist.getNextVideos()

# It should be here, instead of in the while loop
#for sg in playlist.videos:
#    m.append(sg['link'])

print(len(playlist.videos))

First things first. Next time correctly fill out issue report with Markdown. I will not answer any issues without correct formatting.

Nothing is wrong with this library. You are repetetively appending existing videos to the list. When you call playlist.getNextVideos(), our internal list doesn't clear itself, instead we append new videos to the list. When you are calling for loop every time while fetching more videos, you append the already existing videos to your m list. I also don't know why is this list mandatory, as you can simply use our internal list.

Have a look at this code:

from youtubesearchpython import *

#m = []
playlist = Playlist('https://www.youtube.com/playlist?list=PLKu0PlxNFnZUjUzSxccTzHOgEYYGlSJk5')

while playlist.hasMoreVideos:
    playlist.getNextVideos()

# It should be here, instead of in the while loop
#for sg in playlist.videos:
#    m.append(sg['link'])

print(len(playlist.videos))

thanks this make sense. Also python doc when? so i don't make summation about this library

mytja commented

We already have docs in the README. I don't think we need anything more, the README is informative enough. We also have sync examples and async examples.