My Bookmarks

  • No bookmark found

Most Active Members

How to download whole playlist videos from YouTube using Python3 min read

As we discussed in previous article how to download single video from YouTube to a specified folder

link: https://freshlybuilt.com/how-to-download-video-using-pythonpytube/

Now Here in this article, we will be discussing about How to download whole playlist videos from YouTube using Python to a specified location or folder.

source: quickmeme.com

Some recap of previous article:

How to install pytube in python???

pip install pytube

Now let get start for our work

>>> from pytube import Playlist
>>> freshlybuilt = Playlist("https://www.youtube.com/watch?v=Edpy1szoG80&list=PL153hDY-y1E00uQtCVCVC8xJ25TYX8yPU")
>>> freshlybuilt.download_all()
>>> # or if you want to download in a specific directory
>>> freshlybuilt.download_all('/path/to/directory/')
>>> # freshlybuilt.download_all('Downloads/')

This will download the highest quality stream available (generally 720p) from the given playlist. Later more options would be given for user’s flexibility to choose video resolution.

You can also select quality of video according to you as explained in previous article, for example

>>> from pytube import YouTube
>>> freshlybuilt.streams.get_by_itag(22)

To know more about get_by_itag , please read our previous article.

Now Question arises , Can we download the only audio from the given link?

Yes, we can download only Audio also. Here we go….

>>> freshlybuilt.streams.filter(only_audio=True).all()
  [<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">,
  <Stream: itag="171" mime_type="audio/webm" abr="128kbps" acodec="vorbis">,
  <Stream: itag="249" mime_type="audio/webm" abr="50kbps" acodec="opus">,
  <Stream: itag="250" mime_type="audio/webm" abr="70kbps" acodec="opus">,
  <Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus">]

If you want only to list  mp4 streams, Then we do in given below way:

>>> freshlybuilt.streams.filter(subtype='mp4').all()
 [<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
  <Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">,
  <Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028">,
  <Stream: itag="136" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.4d401f">,
  <Stream: itag="135" mime_type="video/mp4" res="480p" fps="30fps" vcodec="avc1.4d401e">,
  <Stream: itag="134" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.4d401e">,
  <Stream: itag="133" mime_type="video/mp4" res="240p" fps="30fps" vcodec="avc1.4d4015">,
  <Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400c">,
  <Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">]

You can also apply multiple filter on single downloadable video, for example:

>>> freshlybuilt.streams.filter(subtype='mp4', progressive=True).all()
>>> # this can also be expressed as:
>>> freshlybuilt.streams.filter(subtype='mp4').filter(progressive=True).all()
  [<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
  <Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">]

Note: All video’s does not have downloadable permission, so above mentioned code can be failed under such circumstances.

Source: memehappen.com

Bookmark(0)

Add a Comment

Your email address will not be published. Required fields are marked *