Skip to content

Instantly share code, notes, and snippets.

@adammenges

adammenges/youtube.py

Last active Aug 29, 2015
Embed
What would you like to do?
Download whole playlist of videos from youtube with Python
#############################
#
# Needed it to download this guy: https://www.youtube.com/playlist?list=PLPemlF-zX2ydW5QoNsHpQiLCQKIKdjvoo
#
# Figured why not stick it up on github too.
#
#############################
import pafy
import os
playlist_url = raw_input("What's the URL of the playlist? ")
playlist = pafy.get_playlist(playlist_url)
videos = playlist['items']
directory = "./" + playlist['title']
if not os.path.exists(directory):
os.makedirs(directory)
for video in videos:
p = video['pafy']
print p.title
best = p.getbest(preftype="mp4")
filepath = directory + "/" + best.title + "." + best.extension
best.download(filepath=filepath)
print "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment