webm to mpv opener

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

Mint 2019.06.03.. Lásd a legutóbbi verzió

  1. // ==UserScript==
  2. // @name webm to mpv opener
  3. // @version 1.0.3
  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 http*://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. //mpv_server.py, on your computer somewhere
  25.  
  26. import os
  27. import subprocess, urlparse
  28. import SimpleHTTPServer, SocketServer
  29. PORT = 4040
  30.  
  31. class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
  32.  
  33. def do_GET(self):
  34. parsedParams = urlparse.urlparse(self.path)
  35. parsed_query = urlparse.parse_qs(parsedParams.query)
  36. url = parsed_query['i'][0]
  37. self.send_response(204)
  38. os.system('pkill mpv') #only one
  39. subprocess.Popen(
  40. ['mpv','-no-audio',url], #disabled audio
  41. stdout=subprocess.PIPE
  42. )
  43.  
  44. Handler = MyHandler
  45. httpd = SocketServer.TCPServer(('', PORT), Handler)
  46. print "serving at port ", PORT
  47. httpd.serve_forever()
  48.  
  49. //mpv_server_launcher.command, auto start | system preferences > users & groups > login items
  50.  
  51. #!/bin/bash
  52. nohup python /Users/david/Dropbox/Documents/scripts/mpv_server.py >/dev/null 2>&1 &
  53. osascript -e 'tell application "Terminal" to quit'
  54.  
  55. */