Skip to content

Instantly share code, notes, and snippets.

@adammenges
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adammenges/da6f336a23414a800904 to your computer and use it in GitHub Desktop.
Save adammenges/da6f336a23414a800904 to your computer and use it in GitHub Desktop.
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