Compare commits
3 Commits
5b204904a7
...
master
Author | SHA1 | Date | |
---|---|---|---|
49dae65bca | |||
8472b29247 | |||
881037a195 |
19
README.md
19
README.md
@ -21,23 +21,24 @@
|
||||
|
||||
## 参数
|
||||
```javascript
|
||||
//自动快进
|
||||
evanEnv.enableAutoForward = true
|
||||
//快进抓取
|
||||
jsMedia.setSpeed(10);
|
||||
//完成后自动下载
|
||||
evanEnv.enableAutoDownload = true
|
||||
jsMedia.enableAutoDownload = true;
|
||||
//手工触发下载
|
||||
jsMedia.download();
|
||||
```
|
||||
|
||||
## FFmpeg合并示例
|
||||
```shell
|
||||
ffmpeg -i mediasource_0_0_0.mp4 -i mediasource_0_1_0.mp4 -c copy -bsf:a aac_adtstoasc out.mp4
|
||||
ffmpeg -i audio.mp4 -acodec copy audio.aac
|
||||
ffmpeg -i audio.aac -i video.mp4 -c copy -bsf:a aac_adtstoasc out.mp4
|
||||
```
|
||||
|
||||
## 大文件分段需要先文件合并
|
||||
copy /b mediasource_0_0_*.mp4 out.mp4
|
||||
|
||||
## 常见问题
|
||||
- 合并后声音播放不正常:由于部分网站使用了HE-AAC v2(AAC+SBR+PS)作为音频编码,大部分播放器还不支持此音频流格式,故声音不正常,使用Windows自带的视频播放器播放正常
|
||||
|
||||
```
|
||||
copy /b media_0_*.mp4 out.mp4
|
||||
```
|
||||
|
||||
## 特别说明
|
||||
- 仅限内部交流使用,请勿用于非法用途
|
154
downloadMedia.js
154
downloadMedia.js
@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name Universal encrypted video downloader
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 0.1
|
||||
// @version 1.1
|
||||
// @description Bypass the encrypted video download protection via js hook
|
||||
// @author Evan
|
||||
// @match https://www.bilibili.com/video/*
|
||||
@ -12,68 +12,84 @@
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
evanEnv = new Object();
|
||||
evanEnv.mediaSources = [];
|
||||
evanEnv.enableAutoForward = true;
|
||||
evanEnv.enableAutoDownload = true;
|
||||
jsMedia = new Object();
|
||||
jsMedia.mediaSources = [];
|
||||
jsMedia.enableAutoDownload = true;
|
||||
//1G
|
||||
jsMedia.fragmentSize = 1024*1024*1024;
|
||||
|
||||
(function () {
|
||||
evanEnv.videos = document.getElementsByTagName('video');
|
||||
evanEnv.downloadRawData = function (bufferList, fileName = 'out', ext = '.mp4') {
|
||||
var buffList = new Array();
|
||||
var totalLength = 0;
|
||||
|
||||
for (var i = 0; i < bufferList.length; i++) {
|
||||
totalLength += bufferList[i].byteLength;
|
||||
if (totalLength > 1073741824 || i == bufferList.length - 1) {
|
||||
buffList.push(new Uint8Array(totalLength));
|
||||
totalLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
var lastLength = 0;
|
||||
var part = 0;
|
||||
for (var ix = 0; ix < bufferList.length; ix++) {
|
||||
//10485760
|
||||
//1073741824
|
||||
|
||||
buffList[part].set(new Uint8Array(bufferList[ix]), lastLength);
|
||||
lastLength += bufferList[ix].byteLength;
|
||||
if (lastLength > 1073741824) {
|
||||
part++;
|
||||
lastLength = 0
|
||||
}
|
||||
}
|
||||
|
||||
for (var iz = 0; iz < buffList.length; iz++) {
|
||||
var buff = buffList[iz];
|
||||
let url = window.URL.createObjectURL(new Blob([buff], { type: "arraybuffer" }))
|
||||
let mediaSourceSeq = 0;
|
||||
jsMedia.videos = document.getElementsByTagName('video');
|
||||
jsMedia.addZero = function(num){
|
||||
return ('00' + num).slice(-3);
|
||||
};
|
||||
jsMedia.downloadBlob = function (buff, fileName) {
|
||||
let url = window.URL.createObjectURL(new Blob(buff, { type: "arraybuffer" }))
|
||||
const link = document.createElement('a');
|
||||
link.style.display = 'none';
|
||||
link.href = url;
|
||||
link.setAttribute('download', fileName + "_" + iz + ext);
|
||||
link.setAttribute('download', fileName);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
};
|
||||
jsMedia.calcBlobLength = function (buffList) {
|
||||
let totalLength = 0;
|
||||
for (let i = 0; i < buffList.length; i++) {
|
||||
totalLength = totalLength + buffList[i].byteLength;
|
||||
}
|
||||
return totalLength;
|
||||
};
|
||||
jsMedia.MyMediaSourceBuffer = function () {
|
||||
this.id = 0;
|
||||
this.rawData1 = [];
|
||||
this.rawData2 = [];
|
||||
let currentSlot = 0;
|
||||
let downloadedIndex = 0;
|
||||
this.download = function () {
|
||||
let lastSlot = currentSlot;
|
||||
if (currentSlot === 0) {
|
||||
currentSlot = 1;
|
||||
} else {
|
||||
currentSlot = 0;
|
||||
}
|
||||
|
||||
if (lastSlot == 0) {
|
||||
jsMedia.downloadBlob(this.rawData1, 'media_' + this.id + '_' + jsMedia.addZero(downloadedIndex) + '.mp4');
|
||||
this.rawData1 = [];
|
||||
} else {
|
||||
jsMedia.downloadBlob(this.rawData2, 'media_' + this.id + '_' + jsMedia.addZero(downloadedIndex) + '.mp4');
|
||||
this.rawData2 = [];
|
||||
}
|
||||
downloadedIndex++;
|
||||
};
|
||||
this.appendBuffer = function (buf) {
|
||||
let totalLength = 0;
|
||||
if (currentSlot === 0) {
|
||||
this.rawData1.push(buf);
|
||||
totalLength = jsMedia.calcBlobLength(this.rawData1);
|
||||
} else {
|
||||
this.rawData2.push(buf);
|
||||
totalLength = jsMedia.calcBlobLength(this.rawData2);
|
||||
}
|
||||
if (totalLength >= jsMedia.fragmentSize) {
|
||||
this.download();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
evanEnv.download = function () {
|
||||
for (var i = 0; i < evanEnv.mediaSources.length; i++) {
|
||||
var currentItem = evanEnv.mediaSources[i];
|
||||
if (currentItem.downloaded == undefined || currentItem.downloaded == false) {
|
||||
for (var x = 0; x < currentItem.rawSources.length; x++) {
|
||||
evanEnv.downloadRawData(currentItem.rawSources[x], 'mediasource_' + i + '_' + x);
|
||||
}
|
||||
}
|
||||
currentItem.downloaded = true;
|
||||
};
|
||||
|
||||
jsMedia.download = function(){
|
||||
for (let i = 0, length = jsMedia.mediaSources.length; i < length; i++) {
|
||||
jsMedia.mediaSources[i].download();
|
||||
}
|
||||
};
|
||||
evanEnv.downloadMediaSource = function (mediaSource) {
|
||||
for (var x = 0; x < mediaSource.rawSources.length; x++) {
|
||||
evanEnv.downloadRawData(mediaSource.rawSources[x], 'mediasource_' + x);
|
||||
mediaSource.downloaded = true;
|
||||
|
||||
jsMedia.setSpeed = function (speed) {
|
||||
for (let i = 0, length = jsMedia.videos.length; i < length; i++) {
|
||||
jsMedia.videos[i].playbackRate = speed;
|
||||
}
|
||||
};
|
||||
|
||||
@ -81,41 +97,31 @@ evanEnv.enableAutoDownload = true;
|
||||
MediaSource.prototype.addSourceBuffer = function (mimeType) {
|
||||
var mediaSourceThis = this;
|
||||
|
||||
evanEnv.mediaSources.push(this);
|
||||
this.lastPos = 0;
|
||||
if (evanEnv.enableAutoDownload) {
|
||||
this.onsourceended = function () {
|
||||
evanEnv.download();
|
||||
};
|
||||
this.onsourceclose = function () {
|
||||
evanEnv.downloadMediaSource(this);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var retSourceBuffer = proxy_addSourceBuffer.apply(this, [].slice.call(arguments));
|
||||
if (this.rawSources == undefined) {
|
||||
this.rawSources = [];
|
||||
}
|
||||
var buffList = [];
|
||||
this.rawSources.push(buffList);
|
||||
retSourceBuffer.rawData = buffList;
|
||||
if (evanEnv.enableAutoForward) {
|
||||
retSourceBuffer.onupdate = function () {
|
||||
if (this.buffered != this.buffered.length > 0) {
|
||||
var endPos = this.buffered.end(0);
|
||||
if (endPos > 5 && endPos - mediaSourceThis.lastPos > 25) {
|
||||
evanEnv.videos[0].currentTime = endPos - 3;
|
||||
mediaSourceThis.lastPos = evanEnv.videos[0].currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
retSourceBuffer.mySourceBuffer = new jsMedia.MyMediaSourceBuffer();
|
||||
retSourceBuffer.mySourceBuffer.id = mediaSourceSeq;
|
||||
jsMedia.mediaSources.push(retSourceBuffer.mySourceBuffer);
|
||||
|
||||
|
||||
if (jsMedia.enableAutoDownload) {
|
||||
this.onsourceended = function () {
|
||||
jsMedia.download();
|
||||
};
|
||||
this.onsourceclose = function () {
|
||||
jsMedia.download();
|
||||
};
|
||||
}
|
||||
|
||||
mediaSourceSeq++;
|
||||
return retSourceBuffer;
|
||||
};
|
||||
var proxy_appendBuffer = SourceBuffer.prototype.appendBuffer;
|
||||
SourceBuffer.prototype.appendBuffer = function (buf) {
|
||||
this.rawData.push(buf);
|
||||
this.mySourceBuffer.appendBuffer(buf);
|
||||
return proxy_appendBuffer.apply(this, [].slice.call(arguments));
|
||||
};
|
||||
})();
|
Reference in New Issue
Block a user