Search code examples
pythonpython-3.xpytube

How to download in-between videos from Youtube playlist using pytube


Suppose there are 10 videos in a playlist. It's simple to download the whole playlist, that is 1 to 10 videos, using a couple of pytube commands. How can we download, suppose 6 to 10? I am using 3.6.5 version.

I am currently using this code:

from pytube import Playlist
pl = Playlist("url")
pl.download_all('location')

Solution

  • You'll have to individually get each URL.

    Try the following

    from pytube import Playlist, YouTube
    
    pl = Playlist("url")
    pl.populate_video_urls()
    
    for u in pl.video_urls[5:]:
        YouTube(u).streams.first().download()