Skip to content

Instantly share code, notes, and snippets.

@stav
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stav/aa48960d9195287d7f95 to your computer and use it in GitHub Desktop.
Save stav/aa48960d9195287d7f95 to your computer and use it in GitHub Desktop.
Python YouTube downloader: :see https://github.com/stav/clipy
# Python YouTube downloader
# 1. start script
# 2. copy youtube url into clipboard
# 3. press ctrl-d to start downloading
import sys
import pygtk
pygtk.require('2.0')
import gtk
import keybinder
import notify2 # https://pypi.python.org/pypi/notify2
sys.path.insert(0, '/srv/_platforms/pafy')
import pafy # https://github.com/np1/pafy
# https://github.com/rg3/youtube-dl Small command-line program to download videos from YouTube.com
# https://github.com/Zulko/moviepy Python module for script-based movie editing
def clip():
summary = 'ClipClip'
text = gtk.clipboard_get().wait_for_text().strip()
engaged = False
if '//www.youtube.com/' in text:
engaged = True
video = pafy.new(text)
best = video.getbest(preftype="mp4")
summary += ' video engaged (%s)' % video.length
text += '\n%s\n%s' % (video.title, best)
print 'engaged:', text
notify2.Notification(summary, text).show()
if engaged:
myfilename = "/home/stav/Videos/clpclp/" + best.title + "." + best.extension
best.download(filepath=myfilename)
#gtk.main_quit()
if __name__ == '__main__':
notify2.init("ClipClip")
keybinder.bind("<Ctrl>D", clip)
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment