Created
August 29, 2014 09:04
-
-
Save frafra/7fb65a5155d39abee224 to your computer and use it in GitHub Desktop.
(youtube-dl) + web service + bookmarklet = play just the video/no Flash
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
javascript:(function(){window.location='http://localhost:8080?url='+window.btoa(unescape(encodeURIComponent(window.location)));})() |
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
#!/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