Skip to content

Instantly share code, notes, and snippets.

@dmiro
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save dmiro/73f02414bac9cc02c6bb to your computer and use it in GitHub Desktop.

Select an option

Save dmiro/73f02414bac9cc02c6bb to your computer and use it in GitHub Desktop.
Download youtube video with pafy library
import pafy
# code at : https://github.com/np1/pafy
# you must copy pafy.py in your project directory
# show info about youtube video
url = "https://www.youtube.com/watch?v=oIlIVFBBbNw"
video = pafy.new(url)
print video.title
print video.duration
# list video formats/ if you want load stream number four -> s[4].download(myfilename)
streams = video.streams
for s in streams:
print(s)
# download best video format 3gp
myfilename ="example.3pg"
best = video.getbest(preftype="3gp")
print best.resolution
print best.extension
best.download(filepath=myfilename, quiet=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment