webm to mpv opener

Changes 4chan (fileText.webm) urls to a localhost url. The local server opens mpv to play the video.

As of 2016-01-28. See the latest version.

  1. // ==UserScript==
  2. // @name webm to mpv opener
  3. // @version 1.0.1
  4. // @description Changes 4chan (fileText.webm) urls to a localhost url. The local server opens mpv to play the video.
  5. // @namespace https://greasyfork.org/users/3159
  6. // @include https://boards.4chan.org/*/*
  7. // ==/UserScript==
  8. a = document.getElementsByClassName('fileText');
  9. for (i = 0; i < a.length; i++) {
  10. b = a[i].children[0];
  11. if (b.href.indexOf('.webm') > -1) {
  12. b.href = "http://127.0.0.1:4040?i=" + b;
  13. b.removeAttribute('target');
  14. }
  15. }
  16. /*
  17. My mpv config text file (~/config/mpv/mpv.conf) has:
  18. autofit-larger=100%x100%
  19. loop=inf
  20.  
  21. Create a link to mpv:
  22. sudo ln -s /Applications/mpv.app/Contents/MacOS/mpv /usr/bin/mpv
  23.  
  24. On OSX I used Platypus to change mpv_server.py (bellow) into an application.
  25. Add the application to your login auto boot items, use python 2.7
  26.  
  27. import os
  28. import subprocess, urlparse
  29. import SimpleHTTPServer, SocketServer
  30. PORT = 4040
  31.  
  32. class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
  33.  
  34. def do_GET(self):
  35. parsedParams = urlparse.urlparse(self.path)
  36. parsed_query = urlparse.parse_qs(parsedParams.query)
  37. url = parsed_query['i'][0]
  38. self.send_response(204)
  39. os.system('pkill mpv') #only one
  40. subprocess.Popen(
  41. ['mpv','-no-audio',url], #disabled audio
  42. stdout=subprocess.PIPE
  43. )
  44.  
  45. Handler = MyHandler
  46. httpd = SocketServer.TCPServer(('', PORT), Handler)
  47. print "serving at port ", PORT
  48. httpd.serve_forever()
  49.  
  50. */