mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Fix progress
This commit is contained in:
parent
d0e1aac539
commit
a7c3845821
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
min/download-video.min.js
vendored
2
min/download-video.min.js
vendored
File diff suppressed because one or more lines are too long
@ -81,7 +81,7 @@
|
|||||||
this.loaded = 0;
|
this.loaded = 0;
|
||||||
this.totalSize = null;
|
this.totalSize = null;
|
||||||
this.workingXhr = null;
|
this.workingXhr = null;
|
||||||
this.fragmentSplitFactor = 10;
|
this.fragmentSplitFactor = 8;
|
||||||
}
|
}
|
||||||
fetchVideoInfo()
|
fetchVideoInfo()
|
||||||
{
|
{
|
||||||
@ -123,24 +123,27 @@
|
|||||||
downloadFragment(fragment)
|
downloadFragment(fragment)
|
||||||
{
|
{
|
||||||
const promises = [];
|
const promises = [];
|
||||||
const partialLength = fragment.length / this.fragmentSplitFactor;
|
const partialLength = Math.round(fragment.size / this.fragmentSplitFactor);
|
||||||
let startByte = 0;
|
let startByte = 0;
|
||||||
while (startByte <= fragment.length)
|
while (startByte <= fragment.size)
|
||||||
{
|
{
|
||||||
const range = `bytes=${startByte}-${Math.min(fragment.length - 1, startByte + partialLength)}`;
|
const range = `bytes=${startByte}-${Math.min(fragment.size - 1, Math.round(startByte + partialLength))}`;
|
||||||
promises.push(new Promise((resolve, reject) =>
|
promises.push(new Promise((resolve, reject) =>
|
||||||
{
|
{
|
||||||
|
let loaded = 0;
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", fragment.url);
|
xhr.open("GET", fragment.url);
|
||||||
xhr.responseType = "arraybuffer";
|
xhr.responseType = "arraybuffer";
|
||||||
xhr.withCredentials = false;
|
xhr.withCredentials = false;
|
||||||
xhr.addEventListener("progress", (e) =>
|
xhr.addEventListener("progress", (e) =>
|
||||||
{
|
{
|
||||||
this.progress && this.progress((this.loaded + e.loaded) / this.totalSize);
|
this.loaded += e.loaded - loaded;
|
||||||
|
loaded = e.loaded;
|
||||||
|
this.progress && this.progress(this.loaded / this.totalSize);
|
||||||
});
|
});
|
||||||
xhr.addEventListener("load", () =>
|
xhr.addEventListener("load", () =>
|
||||||
{
|
{
|
||||||
if (xhr.status === 200)
|
if (("" + xhr.status)[0] === "2")
|
||||||
{
|
{
|
||||||
resolve(xhr.response);
|
resolve(xhr.response);
|
||||||
}
|
}
|
||||||
@ -154,7 +157,7 @@
|
|||||||
xhr.setRequestHeader("Range", range);
|
xhr.setRequestHeader("Range", range);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}));
|
}));
|
||||||
startByte += partialLength;
|
startByte = Math.round(startByte + partialLength);
|
||||||
}
|
}
|
||||||
this.workingXhr = Promise.all(promises);
|
this.workingXhr = Promise.all(promises);
|
||||||
return this.workingXhr;
|
return this.workingXhr;
|
||||||
@ -223,7 +226,6 @@
|
|||||||
for (const fragment of this.fragments)
|
for (const fragment of this.fragments)
|
||||||
{
|
{
|
||||||
const data = await this.downloadFragment(fragment);
|
const data = await this.downloadFragment(fragment);
|
||||||
this.loaded += fragment.size;
|
|
||||||
downloadedData.push(data);
|
downloadedData.push(data);
|
||||||
}
|
}
|
||||||
if (downloadedData.length < 1)
|
if (downloadedData.length < 1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user