Search code examples
pythonpytubepafy

How do you get name of every video in a playlist from YouTube in Python using pytube, pafy or another module?


I am trying to make a converter for my own personal use as a project. I have been using pytube and pafy but they don't seem to get the names of the individual videos from a playlist on YouTube.

Can anyone help me find a solution? (I don't have a code as it is connected with a bunch of other files and GUI's)


Solution

  • I created my own solution for this:

    from pytube import Playlist
    play_list = Playlist("https://www.youtube.com/playlist?list=PL4o29bINVT4EG_y-k5jGoOu3-Am8Nvi10")
    print(len(play_list))
    
    for link in play_list:
        print(link)
    for video in play_list.videos:
        name = video.title
        print(name)
    

    This prints the link of every video within a playlist and also the title of each video in a playlist.