全能视频下载器

黑科技!使用MediaSouce的视频下载技术!

질문, 리뷰하거나, 이 스크립트를 신고하세요.
  1. // ==UserScript==
  2. // @name 全能视频下载器
  3. // @namespace https://qinlili.bid
  4. // @version 0.2
  5. // @description 黑科技!使用MediaSouce的视频下载技术!
  6. // @author 琴梨梨
  7. // @match https://library.koolearn.com/*
  8. // @match *://www.pmphmooc.com/*
  9. // @grant none
  10. // ==/UserScript==
  11. //这个下载器也可以用于其他网站,自己改一下match地址就行了捏
  12.  
  13. (function() {
  14. 'use strict';
  15. //https://stackoverflow.com/questions/49129643/how-do-i-merge-an-array-of-uint8arrays
  16. const concat=(arrays)=> {
  17. // sum of individual array lengths
  18. let totalLength = arrays.reduce((acc, value) => acc + value.length, 0);
  19.  
  20. if (!arrays.length) return null;
  21.  
  22. let result = new Uint8Array(totalLength);
  23.  
  24. // for each array - copy it over result
  25. // next array is copied right after the previous one
  26. let length = 0;
  27. for(let array of arrays) {
  28. result.set(array, length);
  29. length += array.length;
  30. }
  31.  
  32. return result;
  33. }
  34. const dlFile = (link, name) => {
  35. let eleLink = document.createElement('a');
  36. eleLink.download = name;
  37. eleLink.style.display = 'none';
  38. eleLink.href = link;
  39. document.body.appendChild(eleLink);
  40. eleLink.click();
  41. document.body.removeChild(eleLink);
  42. }
  43.  
  44.  
  45.  
  46. (function (addSourceBuffer) {
  47. MediaSource.prototype.addSourceBuffer = function (mime) {
  48. console.log(mime)
  49. switch (mime.substr(0,5)){
  50. case "audio":
  51. window.ams=addSourceBuffer.call(this, mime);
  52. return window.ams
  53. window.audioBuffer=[];
  54. break;
  55. case "video":
  56. window.vms=addSourceBuffer.call(this, mime);
  57. return window.vms
  58. window.videoBuffer=[];
  59. break;
  60. default:
  61. return addSourceBuffer.call(this, mime);
  62. }
  63. };
  64. })(MediaSource.prototype.addSourceBuffer);
  65.  
  66. window.videoBuffer=[];
  67. window.audioBuffer=[];
  68.  
  69. (function (appendBuffer) {
  70. SourceBuffer.prototype.appendBuffer = function (source) {
  71. if(this==window.ams){
  72. console.log("audio buffer get")
  73. window.audioBuffer[window.audioBuffer.length]=source
  74. }
  75. if(this==window.vms){
  76. console.log("video buffer get")
  77. window.videoBuffer[window.videoBuffer.length]=source
  78. }
  79. appendBuffer.call(this, source);
  80. };
  81. })(SourceBuffer.prototype.appendBuffer);
  82. const title=document.createElement("button")
  83. document.body.insertBefore(title,document.body.firstChild);
  84. title.innerText+="[点我开始下载视频]"
  85. title.addEventListener("click",()=>{
  86. alert("请仔细阅读说明:\n本工具使用MediaSource下载视频\n点击确认后将以16倍速播放视频\n视频会在播放完成后开始下载\n请保持页面前台运行,千万不要拖拽进度条!!!")
  87. title.innerText="[正在保存视频,请等待播放完成]"
  88. const video=document.getElementsByTagName("video")[0]
  89. video.addEventListener("ended",()=>{
  90. title.innerText="[正在导出视频]"
  91. var audioFile=new Blob([concat(window.audioBuffer)])
  92. dlFile(URL.createObjectURL(audioFile),"音频.m4a")
  93. var videoFile=new Blob([concat(window.videoBuffer)])
  94. dlFile(URL.createObjectURL(videoFile),"视频.mp4")
  95. })
  96. video.playbackRate=16
  97. })
  98.  
  99.  
  100. })();