Download YouTube playlist a set of MP3s

Requirements

python3 -m pip install pytube
sudo apt-get install rename

Script

Save the following lines as a file, eg pytubemp3.py. Don’t forget to set your own playlists

from pytube import Playlist

links = ["https://www.youtube.com/watch?v=vvvvv&list=xxxxxxx",
         "https://www.youtube.com/watch?v=vvvvv&list=xxxxxxx"]

for link in links:
    playlist = Playlist("https://youtube.com/playlist?" + link.split("&")[1])
    for video in playlist.videos:
        print("Downloading: ", video.title,"from", video.watch_url)
        video.streams.filter(only_audio=True).first().download()

Make sure your script is formatted with indents as the image below:

Then run:

  1. python pytubemp3.py . This step save the audio of youtube video as mp4 file.
  2. rename "s/mp4$/mp3/" *.mp4. This step replace the suffix mp4 with mp3

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.