bipindhk.

Discovering Music: Downloading YouTube Playlist with Pytube

I was scrolling the IG and this reel poped up. 

He shared this fantastic list of music, and as someone who loves discovering new tunes, I couldn’t wait to listen to each one. Some songs like ‘Take it Easy’ by The Eagles and ‘All along the Watchtower’ by Jimi Hendrix were already favorites of mine. But the excitement to explore the rest of the list pushed me to find a way to download these songs from YouTube. Thankfully, I came across Pytube, which made it super easy for me to save the entire playlist to my computer. Now, I can enjoy these tunes anytime, anywhere.

I started my jupyterlab server and did the following

				
					from pytube import YouTube
from pytube import Search

def download_audio_by_name(video_name, output_path):
    try:
        search_results = Search(video_name)
        if len(search_results.results) > 0:
            yt = YouTube(search_results.results[0].watch_url)
            audio_stream = yt.streams.filter(only_audio=True).first()
            audio_stream.download(output_path)
            print(f"Audio for video '{video_name}' downloaded successfully!")
        else:
            print(f"No video found with the name '{video_name}'.")
    except Exception as e:
        print("Error:", str(e))

if __name__ == "__main__":
    video_names = [
    "(Don’t Fear) the Reaper by Blue Öyster Cult",
    "Edge of Seventeen by Stevie Nicks",
    "House of the Rising Sun by The Animals",
    "Spirit in the Sky by Norman Greenbaum",
    "Rich Girl by Daryl Hall and John Oates",
    "Jungle by Jimi Hendrix",
    "California Dreamin’ - single version by The Mamas & The Papas",
    "I Got a Name by Jim Croce",
    "I Need You by Lynyrd Skynyrd",
    "All Along the Watchtower by Jimi Hendrix",
    "Mississippi by Mountain",
    "Take It Easy by Eagles",
    "Rocket Man (I Think It’s Going to Be a Long, Long Time) by Elton John",
    "Strawberry Fields Forever by The Beatles",
    "It’s Late by Queen",
    "Barracuda by Heart",
    "Movin’ Out (Anthony’s Song) by Billy Joel",
    "Mr. Blue Sky by Electric Light Orchestra",
    "Southern Nights by Glen Campbell",
    "Sunshine of Your Love by Cream",
    "Going Down by Freddie King",
    "My Sweet Lord by George Harrison",
    "Into the Mystic by Van Morrison",
    "Sultans of Swing by Dire Straits",
    "The Chain by Fleetwood Mac",
    "Moonage Daydream by David Bowie",
    "Magic Carpet Ride by Steppenwolf",
    "Lenny by Stevie Ray Vaughan",
    "Bad Moon Rising by Creedence Clearwater Revival",
    "Jane by Jefferson Starship",
    "Feelin’ Alright by Joe Cocker",
    "I Want You (She’s so Heavy) by the Beatles",
    "Immigrant Song by Led Zeppelin",
    "Rhiannon by Fleetwood Mac",
    "Reelin’ in the Years by Steely Dan",
    "Layla by Derek & the Dominos, Duane Allman",
    "For What It’s Worth by Buffalo Springfield",
    "Take Me Home, Country Roads by John Denver",
    "Peace Train by Yusef / Cat Stevens",
    "Wish You Were Here by Pink Floyd",
    "Midnight Rider by Allman Brothers Band",
    "Fire And Rain by James Taylor",
    "Black Dog- Remaster by Led Zeppelin"
]
    output_path = input("Enter the output directory path: ")
    
    for video_name in video_names:
        download_audio_by_name(video_name, output_path)
				
			

I’ve got all songs locally downloaded after a minute:

Scroll to Top