Search code examples
pythonpytube

Empty Playlists in Pytube


I was trying to work with a playlist in Pytube, but my playlist was always shown to be empty by Pytube even though there are videos in my playlist. I'm running the latest version of pytube (10.8.5). Is there any way to fix this? I've tried the regex answer, but it didn't work for me.

I would greatly appreciate any answer!

Here is the code that I was testing:

from pytube import Playlist

playlist = Playlist("https://www.youtube.com/playlist?list=PLBN5m5aVVqE7kCNHZN-NBHDUIdnpp0XU_")
print(len(playlist.video_urls)) #Returns 0 even though there are 2 videos in my playlist

Solution

  • What could be the problem is the playlist itself that you are trying to access... If the playlist has been set to private on YouTube then you won't get any details from it, while on the other hand if the playlist was set to public then you will get details from it.

    I've created two playlist to use as example...

    Private Playlist:

    from pytube import Playlist
    
    playlist = Playlist("https://www.youtube.com/playlist?list=PL-gXZHm4upIs5_28uuBOjWwxcldN8ZBDG")
    print(len(playlist.video_urls))  # This will print 0...
    

    Public Playlist:

    from pytube import Playlist
    
    playlist = Playlist("https://www.youtube.com/playlist?list=PL-gXZHm4upIvf2Dvq6GQHcC_HiavwUkl1")
    print(len(playlist.video_urls))  # This will print 1...
    

    So for the playlist you have created, in order to download from it you will have make it accessible and set public.