mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Revoke old blob url when video download complete
This commit is contained in:
parent
8fc84db1dd
commit
f81269bc01
@ -566,7 +566,7 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/dark-schedule.min.js"] = (()=>{return(e,t)=>{class s{constructor(e){if(arguments.length===0){const e=new Date;this.hour=e.getHours();this.minute=e.getMinutes()}else if(arguments.length===1){[this.hour,this.minute]=e.split(":").slice(0,2).map(e=>this.validatePart(e));this.normalize()}else if(arguments.length===2){[this.hour,this.minute]=arguments}}validatePart(e){const t=parseInt(e);if(!isNaN(t)&&0<=t&&t<=59){return t}else{return null}}normalize(){while(this.minute<0){this.minute+=60;this.hour-=1}while(this.minute>=60){this.minute-=60;this.hour+=1}while(this.hour<0){this.hour+=24}while(this.hour>=24){this.hour-=24}}lessThan(e){if(this.hour<e.hour||this.hour===e.hour&&this.minute<e.minute){return true}return false}greaterThan(e){if(this.hour>e.hour||this.hour===e.hour&&this.minute>e.minute){return true}return false}equals(e){return this.hour===e.hour&&this.minute===e.minute}isInRange(e,t){if(e.equals(t)){return false}let s=this.greaterThan(e)&&this.lessThan(t);if(e.greaterThan(t)){s=this.greaterThan(e)||this.lessThan(t)}const i=s||this.equals(e);return i}static millisecondsBefore(e){const t=new s;const i=(new Date).getSeconds();const r=1e3*(t.hour*3600+t.minute*60+i);const n=1e3*(e.hour*3600+e.minute*60);let h=n-r;if(t.greaterThan(e)||t.equals(e)&&i!==0){h+=24*3600*1e3}return h}}function i(){if(e.darkSchedule){const r=new s(e.darkScheduleStart);const n=new s(e.darkScheduleEnd);const h=new s;const u=h.isInRange(r,n);if(e.useDarkStyle!==u){e.useDarkStyle=u;saveSettings(e);t.fetchByKey("useDarkStyle")}let o=0;if(u){o=s.millisecondsBefore(n)}else{o=s.millisecondsBefore(r)}if(o!==0){setTimeout(()=>i(),o)}}}i();return{export:s}}})();
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/force-wide.min.js"] = (()=>{return(e,t)=>{t.applyImportantStyle("forceWideStyle")}})();
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/clear-cache.min.js"] = (()=>{return(e,n)=>{return{settingsWidget:{after:()=>$("input[key=useCache]").parent().parent(),content:`<li class="indent-center">\n <button\n class="gui-settings-button"\n title="清除缓存"\n id="clear-cache">\n 清除缓存\n </button>\n </li>`,success:()=>{$("#clear-cache").on("click",()=>{e.cache={};Toast.show("已删除全部缓存.","清除缓存",5e3)});if(typeof offlineData!=="undefined"){$("button#clear-cache").parent().addClass("hidden")}}}}}})();
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.js"] = (()=>{return(e,t)=>{const s=(unsafeWindow||window).aid;const o=(unsafeWindow||window).cid;if(s===undefined||o===undefined){console.error(`unable to get aid or cid. aid=${s}, cid=${o}`);return}class n{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async download(){const e=new r(this);await e.fetchVideoInfo();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});return e.download()}static get availableFormats(){return new Promise((e,t)=>{const a=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&otype=json`;const r=new XMLHttpRequest;r.addEventListener("load",()=>{const t=JSON.parse(r.responseText).data;const s=t.accept_quality;const o=t.accept_format.split(",");const a=t.accept_description;const i=[];while(s.length>0){const e=new n(s.pop(),o.pop(),a.pop());i.push(e)}e(i)});r.addEventListener("error",()=>t(`获取清晰度信息失败.`));r.withCredentials=true;r.open("GET",a);r.send()})}}class a{constructor(e,t,s,o){this.length=e;this.size=t;this.url=s;this.backupUrls=o}}class r{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null}fetchVideoInfo(){return new Promise((e,t)=>{const n=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&qn=${this.format.quality}&otype=json`;const r=new XMLHttpRequest;r.addEventListener("load",()=>{const s=JSON.parse(r.responseText).data;if(s.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const o=s.durl;this.fragments=o.map(e=>new a(e.length,e.size,e.url.replace("http:","https:"),e.backup_url.map(e=>e.replace("http:","https:"))));if(this.fragments.length>1){t("暂不支持分段视频的下载.")}e(this.fragments)});r.withCredentials=true;r.open("GET",n);r.send()})}download(){return new Promise((e,t)=>{const[s]=this.fragments;const o=new XMLHttpRequest;o.open("GET",s.url);o.responseType="arraybuffer";o.withCredentials=false;o.addEventListener("progress",e=>{this.progress&&this.progress(e.loaded/s.size)});o.addEventListener("load",()=>{if(o.status===200){const t=new Blob([o.response],{type:"video/x-flv"});const n=URL.createObjectURL(t);const a=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");const r=s.url.indexOf(".flv")!==-1?".flv":".mp4";$("a#video-complete").attr("href",n).attr("download",a+r);e(n)}else{t(`请求失败.`)}});o.addEventListener("error",()=>{t(`下载失败.`)});o.send()})}}return{settingsWidget:{after:()=>$("span.settings-category").filter((e,t)=>t.innerHTML==="视频与直播").parent(),content:t.data.downloadVideoDom.text,success:()=>{n.availableFormats.then(e=>{e.forEach(e=>{async function t(){$(".download-video-panel").removeClass("quality").addClass("progress");await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});$(".download-video-panel").removeClass("progress").addClass("quality");document.getElementById("video-complete").click()}$(`<li>${e.displayName}</li>`).on("click",t).prependTo("ol.video-quality")});t.applyStyle("downloadVideoStyle");$("#download-video").on("click",()=>{$(".download-video-panel").toggleClass("opened")}).parent().removeClass("hidden")});$(".video-error").on("click",()=>{$(".video-error").text("");$(".download-video-panel").removeClass("error").removeClass("progress").addClass("quality")})}}}}})();
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.js"] = (()=>{return(e,t)=>{const s=(unsafeWindow||window).aid;const o=(unsafeWindow||window).cid;if(s===undefined||o===undefined){console.error(`unable to get aid or cid. aid=${s}, cid=${o}`);return}class n{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async download(){const e=new a(this);await e.fetchVideoInfo();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});return e.download()}static get availableFormats(){return new Promise((e,t)=>{const r=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&otype=json`;const a=new XMLHttpRequest;a.addEventListener("load",()=>{const t=JSON.parse(a.responseText).data;const s=t.accept_quality;const o=t.accept_format.split(",");const r=t.accept_description;const i=[];while(s.length>0){const e=new n(s.pop(),o.pop(),r.pop());i.push(e)}e(i)});a.addEventListener("error",()=>t(`获取清晰度信息失败.`));a.withCredentials=true;a.open("GET",r);a.send()})}}class r{constructor(e,t,s,o){this.length=e;this.size=t;this.url=s;this.backupUrls=o}}class a{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null}fetchVideoInfo(){return new Promise((e,t)=>{const n=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&qn=${this.format.quality}&otype=json`;const a=new XMLHttpRequest;a.addEventListener("load",()=>{const s=JSON.parse(a.responseText).data;if(s.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const o=s.durl;this.fragments=o.map(e=>new r(e.length,e.size,e.url.replace("http:","https:"),e.backup_url.map(e=>e.replace("http:","https:"))));if(this.fragments.length>1){t("暂不支持分段视频的下载.")}e(this.fragments)});a.withCredentials=true;a.open("GET",n);a.send()})}download(){return new Promise((e,t)=>{const[s]=this.fragments;const o=new XMLHttpRequest;o.open("GET",s.url);o.responseType="arraybuffer";o.withCredentials=false;o.addEventListener("progress",e=>{this.progress&&this.progress(e.loaded/s.size)});o.addEventListener("load",()=>{if(o.status===200){const t=new Blob([o.response],{type:"video/x-flv"});const n=URL.createObjectURL(t);const r=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");const a=s.url.indexOf(".flv")!==-1?".flv":".mp4";const i=$("a#video-complete").attr("href");if(i){URL.revokeObjectURL(i)}$("a#video-complete").attr("href",n).attr("download",r+a);this.progress&&this.progress(0);document.getElementById("video-complete").click();e(n)}else{t(`请求失败.`)}});o.addEventListener("error",()=>{t(`下载失败.`)});o.send()})}}return{settingsWidget:{after:()=>$("span.settings-category").filter((e,t)=>t.innerHTML==="视频与直播").parent(),content:t.data.downloadVideoDom.text,success:()=>{n.availableFormats.then(e=>{e.forEach(e=>{async function t(){$(".download-video-panel").removeClass("quality").addClass("progress");await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});$(".download-video-panel").removeClass("progress").addClass("quality")}$(`<li>${e.displayName}</li>`).on("click",t).prependTo("ol.video-quality")});t.applyStyle("downloadVideoStyle");$("#download-video").on("click",()=>{$(".download-video-panel").toggleClass("opened")}).parent().removeClass("hidden")});$(".video-error").on("click",()=>{$(".video-error").text("");$(".download-video-panel").removeClass("error").removeClass("progress").addClass("quality")})}}}}})();
|
||||
|
||||
class ResourceType
|
||||
{
|
||||
|
||||
@ -566,7 +566,7 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/dark-schedule.min.js"] = (()=>{return(e,t)=>{class s{constructor(e){if(arguments.length===0){const e=new Date;this.hour=e.getHours();this.minute=e.getMinutes()}else if(arguments.length===1){[this.hour,this.minute]=e.split(":").slice(0,2).map(e=>this.validatePart(e));this.normalize()}else if(arguments.length===2){[this.hour,this.minute]=arguments}}validatePart(e){const t=parseInt(e);if(!isNaN(t)&&0<=t&&t<=59){return t}else{return null}}normalize(){while(this.minute<0){this.minute+=60;this.hour-=1}while(this.minute>=60){this.minute-=60;this.hour+=1}while(this.hour<0){this.hour+=24}while(this.hour>=24){this.hour-=24}}lessThan(e){if(this.hour<e.hour||this.hour===e.hour&&this.minute<e.minute){return true}return false}greaterThan(e){if(this.hour>e.hour||this.hour===e.hour&&this.minute>e.minute){return true}return false}equals(e){return this.hour===e.hour&&this.minute===e.minute}isInRange(e,t){if(e.equals(t)){return false}let s=this.greaterThan(e)&&this.lessThan(t);if(e.greaterThan(t)){s=this.greaterThan(e)||this.lessThan(t)}const i=s||this.equals(e);return i}static millisecondsBefore(e){const t=new s;const i=(new Date).getSeconds();const r=1e3*(t.hour*3600+t.minute*60+i);const n=1e3*(e.hour*3600+e.minute*60);let h=n-r;if(t.greaterThan(e)||t.equals(e)&&i!==0){h+=24*3600*1e3}return h}}function i(){if(e.darkSchedule){const r=new s(e.darkScheduleStart);const n=new s(e.darkScheduleEnd);const h=new s;const u=h.isInRange(r,n);if(e.useDarkStyle!==u){e.useDarkStyle=u;saveSettings(e);t.fetchByKey("useDarkStyle")}let o=0;if(u){o=s.millisecondsBefore(n)}else{o=s.millisecondsBefore(r)}if(o!==0){setTimeout(()=>i(),o)}}}i();return{export:s}}})();
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/force-wide.min.js"] = (()=>{return(e,t)=>{t.applyImportantStyle("forceWideStyle")}})();
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/clear-cache.min.js"] = (()=>{return(e,n)=>{return{settingsWidget:{after:()=>$("input[key=useCache]").parent().parent(),content:`<li class="indent-center">\n <button\n class="gui-settings-button"\n title="清除缓存"\n id="clear-cache">\n 清除缓存\n </button>\n </li>`,success:()=>{$("#clear-cache").on("click",()=>{e.cache={};Toast.show("已删除全部缓存.","清除缓存",5e3)});if(typeof offlineData!=="undefined"){$("button#clear-cache").parent().addClass("hidden")}}}}}})();
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.js"] = (()=>{return(e,t)=>{const s=(unsafeWindow||window).aid;const o=(unsafeWindow||window).cid;if(s===undefined||o===undefined){console.error(`unable to get aid or cid. aid=${s}, cid=${o}`);return}class n{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async download(){const e=new r(this);await e.fetchVideoInfo();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});return e.download()}static get availableFormats(){return new Promise((e,t)=>{const a=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&otype=json`;const r=new XMLHttpRequest;r.addEventListener("load",()=>{const t=JSON.parse(r.responseText).data;const s=t.accept_quality;const o=t.accept_format.split(",");const a=t.accept_description;const i=[];while(s.length>0){const e=new n(s.pop(),o.pop(),a.pop());i.push(e)}e(i)});r.addEventListener("error",()=>t(`获取清晰度信息失败.`));r.withCredentials=true;r.open("GET",a);r.send()})}}class a{constructor(e,t,s,o){this.length=e;this.size=t;this.url=s;this.backupUrls=o}}class r{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null}fetchVideoInfo(){return new Promise((e,t)=>{const n=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&qn=${this.format.quality}&otype=json`;const r=new XMLHttpRequest;r.addEventListener("load",()=>{const s=JSON.parse(r.responseText).data;if(s.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const o=s.durl;this.fragments=o.map(e=>new a(e.length,e.size,e.url.replace("http:","https:"),e.backup_url.map(e=>e.replace("http:","https:"))));if(this.fragments.length>1){t("暂不支持分段视频的下载.")}e(this.fragments)});r.withCredentials=true;r.open("GET",n);r.send()})}download(){return new Promise((e,t)=>{const[s]=this.fragments;const o=new XMLHttpRequest;o.open("GET",s.url);o.responseType="arraybuffer";o.withCredentials=false;o.addEventListener("progress",e=>{this.progress&&this.progress(e.loaded/s.size)});o.addEventListener("load",()=>{if(o.status===200){const t=new Blob([o.response],{type:"video/x-flv"});const n=URL.createObjectURL(t);const a=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");const r=s.url.indexOf(".flv")!==-1?".flv":".mp4";$("a#video-complete").attr("href",n).attr("download",a+r);e(n)}else{t(`请求失败.`)}});o.addEventListener("error",()=>{t(`下载失败.`)});o.send()})}}return{settingsWidget:{after:()=>$("span.settings-category").filter((e,t)=>t.innerHTML==="视频与直播").parent(),content:t.data.downloadVideoDom.text,success:()=>{n.availableFormats.then(e=>{e.forEach(e=>{async function t(){$(".download-video-panel").removeClass("quality").addClass("progress");await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});$(".download-video-panel").removeClass("progress").addClass("quality");document.getElementById("video-complete").click()}$(`<li>${e.displayName}</li>`).on("click",t).prependTo("ol.video-quality")});t.applyStyle("downloadVideoStyle");$("#download-video").on("click",()=>{$(".download-video-panel").toggleClass("opened")}).parent().removeClass("hidden")});$(".video-error").on("click",()=>{$(".video-error").text("");$(".download-video-panel").removeClass("error").removeClass("progress").addClass("quality")})}}}}})();
|
||||
offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.js"] = (()=>{return(e,t)=>{const s=(unsafeWindow||window).aid;const o=(unsafeWindow||window).cid;if(s===undefined||o===undefined){console.error(`unable to get aid or cid. aid=${s}, cid=${o}`);return}class n{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async download(){const e=new a(this);await e.fetchVideoInfo();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});return e.download()}static get availableFormats(){return new Promise((e,t)=>{const r=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&otype=json`;const a=new XMLHttpRequest;a.addEventListener("load",()=>{const t=JSON.parse(a.responseText).data;const s=t.accept_quality;const o=t.accept_format.split(",");const r=t.accept_description;const i=[];while(s.length>0){const e=new n(s.pop(),o.pop(),r.pop());i.push(e)}e(i)});a.addEventListener("error",()=>t(`获取清晰度信息失败.`));a.withCredentials=true;a.open("GET",r);a.send()})}}class r{constructor(e,t,s,o){this.length=e;this.size=t;this.url=s;this.backupUrls=o}}class a{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null}fetchVideoInfo(){return new Promise((e,t)=>{const n=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&qn=${this.format.quality}&otype=json`;const a=new XMLHttpRequest;a.addEventListener("load",()=>{const s=JSON.parse(a.responseText).data;if(s.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const o=s.durl;this.fragments=o.map(e=>new r(e.length,e.size,e.url.replace("http:","https:"),e.backup_url.map(e=>e.replace("http:","https:"))));if(this.fragments.length>1){t("暂不支持分段视频的下载.")}e(this.fragments)});a.withCredentials=true;a.open("GET",n);a.send()})}download(){return new Promise((e,t)=>{const[s]=this.fragments;const o=new XMLHttpRequest;o.open("GET",s.url);o.responseType="arraybuffer";o.withCredentials=false;o.addEventListener("progress",e=>{this.progress&&this.progress(e.loaded/s.size)});o.addEventListener("load",()=>{if(o.status===200){const t=new Blob([o.response],{type:"video/x-flv"});const n=URL.createObjectURL(t);const r=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");const a=s.url.indexOf(".flv")!==-1?".flv":".mp4";const i=$("a#video-complete").attr("href");if(i){URL.revokeObjectURL(i)}$("a#video-complete").attr("href",n).attr("download",r+a);this.progress&&this.progress(0);document.getElementById("video-complete").click();e(n)}else{t(`请求失败.`)}});o.addEventListener("error",()=>{t(`下载失败.`)});o.send()})}}return{settingsWidget:{after:()=>$("span.settings-category").filter((e,t)=>t.innerHTML==="视频与直播").parent(),content:t.data.downloadVideoDom.text,success:()=>{n.availableFormats.then(e=>{e.forEach(e=>{async function t(){$(".download-video-panel").removeClass("quality").addClass("progress");await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});$(".download-video-panel").removeClass("progress").addClass("quality")}$(`<li>${e.displayName}</li>`).on("click",t).prependTo("ol.video-quality")});t.applyStyle("downloadVideoStyle");$("#download-video").on("click",()=>{$(".download-video-panel").toggleClass("opened")}).parent().removeClass("hidden")});$(".video-error").on("click",()=>{$(".video-error").text("");$(".download-video-panel").removeClass("error").removeClass("progress").addClass("quality")})}}}}})();
|
||||
|
||||
class ResourceType
|
||||
{
|
||||
|
||||
2
min/download-video.min.js
vendored
2
min/download-video.min.js
vendored
@ -1 +1 @@
|
||||
(()=>{return(e,t)=>{const s=(unsafeWindow||window).aid;const o=(unsafeWindow||window).cid;if(s===undefined||o===undefined){console.error(`unable to get aid or cid. aid=${s}, cid=${o}`);return}class n{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async download(){const e=new r(this);await e.fetchVideoInfo();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});return e.download()}static get availableFormats(){return new Promise((e,t)=>{const a=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&otype=json`;const r=new XMLHttpRequest;r.addEventListener("load",()=>{const t=JSON.parse(r.responseText).data;const s=t.accept_quality;const o=t.accept_format.split(",");const a=t.accept_description;const i=[];while(s.length>0){const e=new n(s.pop(),o.pop(),a.pop());i.push(e)}e(i)});r.addEventListener("error",()=>t(`获取清晰度信息失败.`));r.withCredentials=true;r.open("GET",a);r.send()})}}class a{constructor(e,t,s,o){this.length=e;this.size=t;this.url=s;this.backupUrls=o}}class r{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null}fetchVideoInfo(){return new Promise((e,t)=>{const n=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&qn=${this.format.quality}&otype=json`;const r=new XMLHttpRequest;r.addEventListener("load",()=>{const s=JSON.parse(r.responseText).data;if(s.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const o=s.durl;this.fragments=o.map(e=>new a(e.length,e.size,e.url.replace("http:","https:"),e.backup_url.map(e=>e.replace("http:","https:"))));if(this.fragments.length>1){t("暂不支持分段视频的下载.")}e(this.fragments)});r.withCredentials=true;r.open("GET",n);r.send()})}download(){return new Promise((e,t)=>{const[s]=this.fragments;const o=new XMLHttpRequest;o.open("GET",s.url);o.responseType="arraybuffer";o.withCredentials=false;o.addEventListener("progress",e=>{this.progress&&this.progress(e.loaded/s.size)});o.addEventListener("load",()=>{if(o.status===200){const t=new Blob([o.response],{type:"video/x-flv"});const n=URL.createObjectURL(t);const a=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");const r=s.url.indexOf(".flv")!==-1?".flv":".mp4";$("a#video-complete").attr("href",n).attr("download",a+r);e(n)}else{t(`请求失败.`)}});o.addEventListener("error",()=>{t(`下载失败.`)});o.send()})}}return{settingsWidget:{after:()=>$("span.settings-category").filter((e,t)=>t.innerHTML==="视频与直播").parent(),content:t.data.downloadVideoDom.text,success:()=>{n.availableFormats.then(e=>{e.forEach(e=>{async function t(){$(".download-video-panel").removeClass("quality").addClass("progress");await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});$(".download-video-panel").removeClass("progress").addClass("quality");document.getElementById("video-complete").click()}$(`<li>${e.displayName}</li>`).on("click",t).prependTo("ol.video-quality")});t.applyStyle("downloadVideoStyle");$("#download-video").on("click",()=>{$(".download-video-panel").toggleClass("opened")}).parent().removeClass("hidden")});$(".video-error").on("click",()=>{$(".video-error").text("");$(".download-video-panel").removeClass("error").removeClass("progress").addClass("quality")})}}}}})();
|
||||
(()=>{return(e,t)=>{const s=(unsafeWindow||window).aid;const o=(unsafeWindow||window).cid;if(s===undefined||o===undefined){console.error(`unable to get aid or cid. aid=${s}, cid=${o}`);return}class n{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async download(){const e=new a(this);await e.fetchVideoInfo();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});return e.download()}static get availableFormats(){return new Promise((e,t)=>{const r=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&otype=json`;const a=new XMLHttpRequest;a.addEventListener("load",()=>{const t=JSON.parse(a.responseText).data;const s=t.accept_quality;const o=t.accept_format.split(",");const r=t.accept_description;const i=[];while(s.length>0){const e=new n(s.pop(),o.pop(),r.pop());i.push(e)}e(i)});a.addEventListener("error",()=>t(`获取清晰度信息失败.`));a.withCredentials=true;a.open("GET",r);a.send()})}}class r{constructor(e,t,s,o){this.length=e;this.size=t;this.url=s;this.backupUrls=o}}class a{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null}fetchVideoInfo(){return new Promise((e,t)=>{const n=`https://api.bilibili.com/x/player/playurl?avid=${s}&cid=${o}&qn=${this.format.quality}&otype=json`;const a=new XMLHttpRequest;a.addEventListener("load",()=>{const s=JSON.parse(a.responseText).data;if(s.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const o=s.durl;this.fragments=o.map(e=>new r(e.length,e.size,e.url.replace("http:","https:"),e.backup_url.map(e=>e.replace("http:","https:"))));if(this.fragments.length>1){t("暂不支持分段视频的下载.")}e(this.fragments)});a.withCredentials=true;a.open("GET",n);a.send()})}download(){return new Promise((e,t)=>{const[s]=this.fragments;const o=new XMLHttpRequest;o.open("GET",s.url);o.responseType="arraybuffer";o.withCredentials=false;o.addEventListener("progress",e=>{this.progress&&this.progress(e.loaded/s.size)});o.addEventListener("load",()=>{if(o.status===200){const t=new Blob([o.response],{type:"video/x-flv"});const n=URL.createObjectURL(t);const r=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");const a=s.url.indexOf(".flv")!==-1?".flv":".mp4";const i=$("a#video-complete").attr("href");if(i){URL.revokeObjectURL(i)}$("a#video-complete").attr("href",n).attr("download",r+a);this.progress&&this.progress(0);document.getElementById("video-complete").click();e(n)}else{t(`请求失败.`)}});o.addEventListener("error",()=>{t(`下载失败.`)});o.send()})}}return{settingsWidget:{after:()=>$("span.settings-category").filter((e,t)=>t.innerHTML==="视频与直播").parent(),content:t.data.downloadVideoDom.text,success:()=>{n.availableFormats.then(e=>{e.forEach(e=>{async function t(){$(".download-video-panel").removeClass("quality").addClass("progress");await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});$(".download-video-panel").removeClass("progress").addClass("quality")}$(`<li>${e.displayName}</li>`).on("click",t).prependTo("ol.video-quality")});t.applyStyle("downloadVideoStyle");$("#download-video").on("click",()=>{$(".download-video-panel").toggleClass("opened")}).parent().removeClass("hidden")});$(".video-error").on("click",()=>{$(".video-error").text("");$(".download-video-panel").removeClass("error").removeClass("progress").addClass("quality")})}}}}})();
|
||||
@ -130,9 +130,16 @@
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
const title = document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili", "");
|
||||
const extension = fragment.url.indexOf(".flv") !== -1 ? ".flv" : ".mp4";
|
||||
const oldBlobUrl = $("a#video-complete").attr("href");
|
||||
if (oldBlobUrl)
|
||||
{
|
||||
URL.revokeObjectURL(oldBlobUrl);
|
||||
}
|
||||
$("a#video-complete")
|
||||
.attr("href", blobUrl)
|
||||
.attr("download", title + extension);
|
||||
this.progress && this.progress(0);
|
||||
document.getElementById("video-complete").click();
|
||||
resolve(blobUrl);
|
||||
}
|
||||
else
|
||||
@ -171,7 +178,6 @@
|
||||
$(".download-video-panel")
|
||||
.removeClass("progress")
|
||||
.addClass("quality");
|
||||
document.getElementById("video-complete").click();
|
||||
}
|
||||
$(`<li>${format.displayName}</li>`)
|
||||
.on("click", formatClick)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user