Skip to content

Instantly share code, notes, and snippets.

@frafra
Created August 29, 2014 09:04
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 frafra/7fb65a5155d39abee224 to your computer and use it in GitHub Desktop.
Save frafra/7fb65a5155d39abee224 to your computer and use it in GitHub Desktop.
(youtube-dl) + web service + bookmarklet = play just the video/no Flash
javascript:(function(){window.location='http://localhost:8080?url='+window.btoa(unescape(encodeURIComponent(window.location)));})()
#!/usr/bin/env python
# Install dependencies: # pip install youtube-dl cherrypy
import youtube_dl
import cherrypy
import base64
class YDLRedirect(object):
@cherrypy.expose
def index(self, url):
ydl = youtube_dl.YoutubeDL()
ydl.add_default_info_extractors()
result = ydl.extract_info(base64.b64decode(url).decode('utf-8'), download=False)
if 'entries' in result:
video = result['entries'][0]
else:
video = result
raise cherrypy.HTTPRedirect(video['url'])
if __name__ == '__main__':
cherrypy.config.update({'server.socket_host': '127.0.0.1'}) # just for localhost
#cherrypy.config.update({'server.socket_host': '0.0.0.0'}) # everybody can access
cherrypy.quickstart(YDLRedirect())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment