Last active
August 29, 2015 14:06
-
-
Save adammenges/da6f336a23414a800904 to your computer and use it in GitHub Desktop.
Download whole playlist of videos from youtube with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################# | |
# | |
# 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