M3u8&mp4 Detect

try to take over the world!

  1. // ==UserScript==
  2. // @name M3u8&mp4 Detect
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @run-at document-start
  8. // @match http*://*/*
  9. // @grant unsafeWindow
  10. // @grant GM_setClipboard
  11. // @grant GM_notification
  12. // @grant GM_log
  13. // @grant GM_registerMenuCommand
  14. // @grant GM_openInTab
  15. // ==/UserScript==
  16.  
  17. let menu_id = {};
  18. function handler_m3u8(url){
  19. if(menu_id[url] == undefined){
  20. let idx = Object.keys(menu_id).length+1;
  21. let _id = GM_registerMenuCommand(`[${idx}] m3u8 open and copy`, function(){
  22. GM_openInTab(url);
  23. let out = document.title.replace(/\||<|>|\?|\*|:|\/|\\|"|\n/g, ' ');
  24. let cmd = `ffmpeg -i "${url}" -vcodec copy -acodec copy -absf aac_adtstoasc "${out}.mp4"\n`;
  25. GM_setClipboard(cmd);
  26. });
  27. GM_registerMenuCommand(`[${idx}] copy command`, function(){
  28. let out = document.title.replace(/\||<|>|\?|\*|:|\/|\\|"|\n/g, ' ');
  29. let cmd = `ffmpeg -i "${url}" -vcodec copy -acodec copy -absf aac_adtstoasc "${out}.mp4"\n`;
  30. GM_setClipboard(cmd);
  31. });
  32.  
  33. menu_id[url] = _id;
  34. }
  35. }
  36.  
  37. function handler_mp4(url){
  38. if(menu_id[url] == undefined){
  39. let idx = Object.keys(menu_id).length+1;
  40. let _id = GM_registerMenuCommand(`[${idx}] mp4 open`, function(){
  41. GM_openInTab(url);
  42. GM_setClipboard(url);
  43. });
  44. GM_registerMenuCommand(`[${idx}] mp4 open`, function(){
  45. let out = document.title.replace(/\||<|>|\?|\*|:|\/|\\|"|\n/g, ' ');
  46. GM_download(url, `${out}.mp4`);
  47. });
  48. menu_id[url] = _id;
  49. }
  50. }
  51.  
  52. (function(open) {
  53. XMLHttpRequest.prototype.open = function() {
  54. this.addEventListener("readystatechange", function() {
  55. //console.log(this.readyState);
  56. }, false);
  57. let url = arguments[1];
  58. if(/http.*\.m3u8.*/.test(url)){
  59. GM_log(url);
  60. GM_notification({
  61. 'text': url,
  62. 'title': "Got m3u8 url ",
  63. 'timeout': 2000,
  64. });
  65.  
  66. handler_m3u8(url);
  67. }
  68. else if(/http.*\.mp4.*/.test(url)){
  69. GM_log(url);
  70. GM_notification({
  71. 'text': url,
  72. 'title': "Got mp4 url ",
  73. 'timeout': 2000,
  74. });
  75. handler_m3u8(url);
  76. }
  77. open.apply(this, arguments);
  78. };
  79. })(XMLHttpRequest.prototype.open);
  80.