通用视频脚本搭配automa
1、全能视频下载器脚本1
// ==UserScript==
// @name 全能视频下载器-自用-MT 修复版
// @namespace https://qinlili.bid
// @version 0.43
// @description 修复首段播放异常,完整抓取MediaSource视频;建议搭配ffmpeg合并视频音频使用。
// @author 原:琴梨梨, 修复:ChatGPT
// @match *://*/*
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
// 工具函数:合并多个 Uint8Array
const concat = (arrays) => {
if (!arrays.length) return null;
let totalLength = arrays.reduce((acc, value) => acc + value.length, 0);
let result = new Uint8Array(totalLength);
let offset = 0;
for (let arr of arrays) {
result.set(arr, offset);
offset += arr.length;
}
return result;
};
// 工具函数:下载 Blob
const dlFile = (link, name) => {
const a = document.createElement('a');
a.download = name;
a.href = link;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
// 初始化缓冲数组
window.videoBuffer = [];
window.audioBuffer = [];
// 拦截 addSourceBuffer
(function (original) {
MediaSource.prototype.addSourceBuffer = function (mime) {
console.log('[下载脚本] 检测到媒体类型:', mime);
if (mime.startsWith("video")) {
window.vms = original.call(this, mime);
return window.vms;
}
if (mime.startsWith("audio")) {
window.ams = original.call(this, mime);
return window.ams;
}
return original.call(this, mime);
};
})(MediaSource.prototype.addSourceBuffer);
// 拦截 appendBuffer
(function (original) {
SourceBuffer.prototype.appendBuffer = function (source) {
if (this === window.vms) {
console.log('[下载脚本] 捕获视频片段');
window.videoBuffer.push(new Uint8Array(source)); // ✅ 拷贝数据
}
if (this === window.ams) {
console.log('[下载脚本] 捕获音频片段');
window.audioBuffer.push(new Uint8Array(source)); // ✅ 拷贝数据
}
return original.call(this, source);
};
})(SourceBuffer.prototype.appendBuffer);
// 下载按钮 UI
const btn = document.createElement("button");
btn.id = "media_download_video_script";
btn.innerText = "[点我开始下载视频]";
btn.style = `
position: fixed;
top: 12px;
left: 12px;
z-index: 9999;
padding: 10px 14px;
background: #1976d2;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
`;
document.addEventListener("DOMContentLoaded", () => {
document.body.appendChild(btn);
});
// 按钮逻辑
btn.addEventListener("click", () => {
alert("📥 视频将以 16 倍速播放下载,请保持页面前台运行,勿拖动进度条!");
const video = document.querySelector("video");
if (!video) return alert("❌ 没有找到 video 元素");
btn.innerText = "[正在播放以缓存视频…]";
// 播放完导出
video.addEventListener("ended", () => {
btn.innerText = "[导出中…]";
const sanitize = (str) => str.replace(/[/\\:*?"<>|]/g, '').trim();
const title = sanitize(document.title || "download");
const videoBlob = new Blob([concat(window.videoBuffer)], { type: "video/mp4" });
const audioBlob = new Blob([concat(window.audioBuffer)], { type: "audio/mp4" });
dlFile(URL.createObjectURL(videoBlob), `${title}.mp4`);
dlFile(URL.createObjectURL(audioBlob), `${title}.m4a`);
btn.innerText = "[下载完成]";
});
// 开始快放下载
video.playbackRate = 16;
video.play().catch((err) => {
console.error("播放失败", err);
alert("❌ 视频无法播放,请确认是否支持快放!");
});
});
// 防止按钮被 DOM 动态清除
setInterval(() => {
if (!document.querySelector("#media_download_video_script")) {
document.body.appendChild(btn);
}
}, 1000);
})();效果图:

2、全能视频下载器脚本2备用
// ==UserScript==
// @name 全能视频下载器-自用-MT
// @namespace https://qinlili.bid
// @version 0.42
// @description 黑科技!使用MediaSouce的视频下载技术!
// @author 原:琴梨梨,现:MT
// @match *://*/*
// @grant none
// @license MIT
// @downloadURL https://update.greasyfork.org/scripts/518375/%E5%85%A8%E8%83%BD%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD%E5%99%A8-%E8%87%AA%E7%94%A8-MT.user.js
// @updateURL https://update.greasyfork.org/scripts/518375/%E5%85%A8%E8%83%BD%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD%E5%99%A8-%E8%87%AA%E7%94%A8-MT.meta.js
// ==/UserScript==
//这个下载器也可以用于其他网站,自己改一下match地址就行了捏
//这个基于[全能视频下载器-自用]改写的,下载后视频可以用ffmpeg将mp4和mp4a合并,然后用vlc media player播放。或者直接使用potplayer播放(可能出现音频问题)。
(function() {
'use strict';
//https://stackoverflow.com/questions/49129643/how-do-i-merge-an-array-of-uint8arrays
const concat=(arrays)=> {
// sum of individual array lengths
let totalLength = arrays.reduce((acc, value) => acc + value.length, 0);
if (!arrays.length) return null;
let result = new Uint8Array(totalLength);
// for each array - copy it over result
// next array is copied right after the previous one
let length = 0;
for(let array of arrays) {
result.set(array, length);
length += array.length;
}
return result;
}
const dlFile = (link, name) => {
let eleLink = document.createElement('a');
eleLink.download = name;
eleLink.style.display = 'none';
eleLink.href = link;
document.body.appendChild(eleLink);
eleLink.click();
document.body.removeChild(eleLink);
}
(function (addSourceBuffer) {
MediaSource.prototype.addSourceBuffer = function (mime) {
console.log(mime)
switch (mime.substr(0,5)){
case "audio":
window.ams=addSourceBuffer.call(this, mime);
return window.ams
window.audioBuffer=[];
break;
case "video":
window.vms=addSourceBuffer.call(this, mime);
return window.vms
window.videoBuffer=[];
break;
default:
return addSourceBuffer.call(this, mime);
}
};
})(MediaSource.prototype.addSourceBuffer);
window.videoBuffer=[];
window.audioBuffer=[];
(function (appendBuffer) {
SourceBuffer.prototype.appendBuffer = function (source) {
if(this==window.ams){
console.log("audio buffer get")
window.audioBuffer[window.audioBuffer.length]=source
}
if(this==window.vms){
console.log("video buffer get")
//window.videoBuffer[window.videoBuffer.length]=source
window.videoBuffer.push(new Uint8Array(source)) // 拷贝一下
}
appendBuffer.call(this, source);
};
})(SourceBuffer.prototype.appendBuffer);
const title=document.createElement("button")
title.style=`
position:absolute;
z-index:9999;
padding:12px 8px;
`
title.setAttribute('id','media_download_video_script')
document.body.insertBefore(title,document.body.firstChild);
title.innerText+="[点我开始下载视频]"
title.addEventListener("click",()=>{
alert("请仔细阅读说明:\n本工具使用MediaSource下载视频\n点击确认后将以16倍速播放视频\n视频会在播放完成后开始下载\n请保持页面前台运行,千万不要拖拽进度条!!!")
title.innerText="[正在保存视频,请等待播放完成]"
const video=document.getElementsByTagName("video")[0]
video.addEventListener("ended",()=>{
title.innerText="[正在导出视频]"
//获取网页标题并处理
var pageTitle = document.title;
function sanitizeFileName(title) {
return title.replace(/[/\\:*?"<>|]/g, '');
}
var sanitizedTitle = sanitizeFileName(pageTitle);
// 创建视频文件Blob并下载
//var videoFile = new Blob([concat(window.videoBuffer)])
var videoFile = new Blob([concat(window.videoBuffer)], {type:'video/mp4'})
dlFile(URL.createObjectURL(videoFile), sanitizedTitle + ".mp4")
var audioFile=new Blob([concat(window.audioBuffer)])
dlFile(URL.createObjectURL(audioFile),sanitizedTitle + ".m4a")
})
video.playbackRate=16
})
window.setInterval(()=>{
if(document.querySelector('#media_download_video_script')==null){
document.body.insertBefore(title,document.body.firstChild);
}
},1000)
})();
