diff --git a/bilibili-evolved.offline.user.js b/bilibili-evolved.offline.user.js index 23c24f845..d846559e5 100644 --- a/bilibili-evolved.offline.user.js +++ b/bilibili-evolved.offline.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name Bilibili Evolved (Offline) -// @version 132.20 +// @version 132.21 // @description 增强哔哩哔哩Web端体验(离线版): 修复界面瑕疵, 删除广告, 使用夜间模式浏览, 下载视频或视频封面, 以及增加对触屏设备的支持等. // @author Grant Howard, Coulomb-G // @copyright 2018, Grant Howrad (https://github.com/the1812) @@ -885,7 +885,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(e.length===0){const e=new Date;this.hour=e.getHours();this.minute=e.getMinutes()}else if(e.length===1){const[t]=e;[this.hour,this.minute]=t.split(":").slice(0,2).map(e=>this.validatePart(e));this.normalize()}else if(v.length===2){[this.hour,this.minute]=e}}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.houre.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,t)=>{return{settingsWidget:{category:"其他",content:`
\n \n 清除缓存\n \n
`,success:()=>{$("#clear-cache").on("click",()=>{e.cache={};Toast.success("已删除全部缓存.","清除缓存",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 o=t.attributes.videoInfo.export.VideoInfo;const n=t.attributes.videoInfo.export.BangumiInfo;const s=t.attributes.videoInfo.export.DanmakuInfo;const i={aid:undefined,cid:undefined,isBangumi:false,isMovie:false};class a{constructor(e,t,o){this.quality=e;this.internalName=t;this.displayName=o}async downloadInfo(){const e=new l(this);await e.fetchVideoInfo();return e}static get availableFormats(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText);if(o.code!==0){t("获取清晰度信息失败.")}const s=o.data;const i=s.accept_quality;const r=s.accept_format.split(",");const l=s.accept_description;const d=[];while(i.length>0){const e=new a(i.pop(),r.pop(),l.pop());d.push(e)}e(d)});n.addEventListener("error",()=>t(`获取清晰度信息失败.`));n.withCredentials=true;n.open("GET",o);n.send()})}}class r{constructor(e,t,o,n){this.length=e;this.size=t;this.url=o;this.backupUrls=n}}class l{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null;this.loaded=0;this.totalSize=null;this.workingXhr=null;this.fragmentSplitFactor=8}fetchVideoInfo(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&qn=${this.format.quality}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText.replace(/http:/g,"https:")).data;if(o.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const s=o.durl;this.fragments=s.map(e=>new r(e.length,e.size,e.url,e.backup_url));e(this.fragments)});n.withCredentials=true;n.open("GET",o);n.send()})}cancelDownload(){if(this.workingXhr){this.workingXhr.forEach(e=>e.abort())}}downloadFragment(e){const t=[];const o=Math.round(e.size/this.fragmentSplitFactor);let n=0;while(n<=e.size){const s=`bytes=${n}-${Math.min(e.size-1,Math.round(n+o))}`;t.push(new Promise((t,o)=>{let n=0;const i=new XMLHttpRequest;i.open("GET",e.url);i.responseType="arraybuffer";i.withCredentials=false;i.addEventListener("progress",e=>{this.loaded+=e.loaded-n;n=e.loaded;this.progress&&this.progress(this.loaded/this.totalSize)});i.addEventListener("load",()=>{if((""+i.status)[0]==="2"){t(i.response)}else{o(`请求失败.`)}});i.addEventListener("abort",()=>o("下载已取消."));i.addEventListener("error",()=>o(`下载失败.`));i.setRequestHeader("Range",s);i.send()}));n=Math.round(n+o)}this.workingXhr=Promise.all(t);return this.workingXhr}copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM_setClipboard(e,"text")}extension(e){return(e||this.fragments[0]).url.indexOf(".flv")!==-1?".flv":".mp4"}makeBlob(e,t=null){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=$("a#video-complete").attr("href");if(e&&$(`.link[href=${e}]`).length===0){URL.revokeObjectURL(e)}}downloadSingle(e){const[t]=e;const o=this.makeBlob(t);const n=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","")+this.extension();return[o,n]}async downloadMultiple(e){const t=new JSZip;const o=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");if(e.length>1){e.forEach((e,n)=>{const s=this.fragments[n];t.file(`${o} - ${n+1}${this.extension(s)}`,this.makeBlob(e,s))})}else{const[n]=e;t.file(`${o}${this.extension()}`,this.makeBlob(n))}if(settings.downloadDanmaku){const e=new s(i.cid);await e.fetchInfo();t.file(`${o}.xml`,e.rawXML)}const n=await t.generateAsync({type:"blob"});const a=o+".zip";return[n,a]}async download(){const e=[];this.loaded=0;this.totalSize=this.fragments.map(e=>e.size).reduce((e,t)=>e+t);for(const t of this.fragments){const o=await this.downloadFragment(t);e.push(o)}if(e.length<1){throw new Error("下载失败.")}let t=null;let o=null;if(e.length===1&&!settings.downloadDanmaku){[t,o]=this.downloadSingle(e)}else{[t,o]=await this.downloadMultiple(e)}const n=URL.createObjectURL(t);this.cleanUpOldBlobUrl();this.progress&&this.progress(0);return{url:n,filename:o}}}function d(){(async()=>{let e=(unsafeWindow||window).aid;let t=(unsafeWindow||window).cid;if(e===undefined||t===undefined){const n=document.URL.match(/\/av(\d+)/);const s=document.URL.match(/\/ep(\d+)/);if(n&&n[1]){const s=await new o(n[1]).fetchInfo();e=s.aid;t=s.cid}}return[e,t]})().then(e=>{const[o,n]=e;if(o===undefined||n===undefined){return}i.aid=o;i.cid=n;a.availableFormats.then(e=>{let[o]=e;const n=()=>o.downloadInfo().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});async function s(){if(!o){return}$(".download-video-panel").removeClass("action").addClass("progress");const e=await n();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});document.querySelector(".download-progress-cancel>span").onclick=(()=>e.cancelDownload());const t=await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});if(!t){return}const s=document.getElementById("video-complete");s.setAttribute("href",t.url);s.setAttribute("download",t.filename);s.click();const i=`下载完成. 再次保存`;Toast.success(i,"下载视频");$(".download-video-panel").removeClass("progress").addClass("quality")}async function i(){if(!o){return}const e=await n();e.copyUrl();Toast.success("已复制链接到剪贴板.","复制链接",3e3);$(".download-video-panel").removeClass("action").addClass("quality")}$(".video-action>#video-action-download").on("click",s);$(".video-action>#video-action-copy").on("click",i);e.forEach(e=>{$(`
  • ${e.displayName}
  • `).on("click",()=>{o=e;$(".download-video-panel").removeClass("quality").addClass("action")}).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{settingsWidget:{category:"视频与直播",content:t.data.downloadVideoDom.text,success:d}}}})(); +offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.js"] = (()=>{return(e,t)=>{const o=t.attributes.videoInfo.export.VideoInfo;const n=t.attributes.videoInfo.export.BangumiInfo;const s=t.attributes.videoInfo.export.DanmakuInfo;const i={aid:undefined,cid:undefined,isBangumi:false,isMovie:false};class a{constructor(e,t,o){this.quality=e;this.internalName=t;this.displayName=o}async downloadInfo(){const e=new l(this);await e.fetchVideoInfo();return e}static get availableFormats(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText);if(o.code!==0){t("获取清晰度信息失败.")}const s=o.data;const i=s.accept_quality;const r=s.accept_format.split(",");const l=s.accept_description;const d=[];while(i.length>0){const e=new a(i.pop(),r.pop(),l.pop());d.push(e)}e(d)});n.addEventListener("error",()=>t(`获取清晰度信息失败.`));n.withCredentials=true;n.open("GET",o);n.send()})}}class r{constructor(e,t,o,n){this.length=e;this.size=t;this.url=o;this.backupUrls=n}}class l{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null;this.loaded=0;this.totalSize=null;this.workingXhr=null;this.fragmentSplitFactor=6*5}fetchVideoInfo(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&qn=${this.format.quality}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText.replace(/http:/g,"https:")).data;if(o.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const s=o.durl;this.fragments=s.map(e=>new r(e.length,e.size,e.url,e.backup_url));e(this.fragments)});n.withCredentials=true;n.open("GET",o);n.send()})}cancelDownload(){if(this.workingXhr){this.workingXhr.forEach(e=>e.abort())}}downloadFragment(e){const t=[];const o=Math.round(e.size/this.fragmentSplitFactor);let n=0;while(n{let n=0;const i=new XMLHttpRequest;i.open("GET",e.url);i.responseType="arraybuffer";i.withCredentials=false;i.addEventListener("progress",e=>{this.loaded+=e.loaded-n;n=e.loaded;this.progress&&this.progress(this.loaded/this.totalSize)});i.addEventListener("load",()=>{if((""+i.status)[0]==="2"){t(i.response)}else{o(`请求失败.`)}});i.addEventListener("abort",()=>o("下载已取消."));i.addEventListener("error",()=>o(`下载失败.`));i.setRequestHeader("Range",s);i.send()}));n=Math.round(n+o)}this.workingXhr=Promise.all(t);return this.workingXhr}copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM_setClipboard(e,"text")}extension(e){return(e||this.fragments[0]).url.indexOf(".flv")!==-1?".flv":".mp4"}makeBlob(e,t=null){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=$("a#video-complete").attr("href");if(e&&$(`.link[href=${e}]`).length===0){URL.revokeObjectURL(e)}}downloadSingle(e){const[t]=e;const o=this.makeBlob(t);const n=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","")+this.extension();return[o,n]}async downloadMultiple(e){const t=new JSZip;const o=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");if(e.length>1){e.forEach((e,n)=>{const s=this.fragments[n];t.file(`${o} - ${n+1}${this.extension(s)}`,this.makeBlob(e,s))})}else{const[n]=e;t.file(`${o}${this.extension()}`,this.makeBlob(n))}if(settings.downloadDanmaku){const e=new s(i.cid);await e.fetchInfo();t.file(`${o}.xml`,e.rawXML)}const n=await t.generateAsync({type:"blob"});const a=o+".zip";return[n,a]}async download(){const e=[];this.loaded=0;this.totalSize=this.fragments.map(e=>e.size).reduce((e,t)=>e+t);for(const t of this.fragments){const o=await this.downloadFragment(t);e.push(o)}if(e.length<1){throw new Error("下载失败.")}let t=null;let o=null;if(e.length===1&&!settings.downloadDanmaku){[t,o]=this.downloadSingle(e)}else{[t,o]=await this.downloadMultiple(e)}const n=URL.createObjectURL(t);this.cleanUpOldBlobUrl();this.progress&&this.progress(0);return{url:n,filename:o}}}function d(){(async()=>{let e=(unsafeWindow||window).aid;let t=(unsafeWindow||window).cid;if(e===undefined||t===undefined){const n=document.URL.match(/\/av(\d+)/);const s=document.URL.match(/\/ep(\d+)/);if(n&&n[1]){const s=await new o(n[1]).fetchInfo();e=s.aid;t=s.cid}}return[e,t]})().then(e=>{const[o,n]=e;if(o===undefined||n===undefined){return}i.aid=o;i.cid=n;a.availableFormats.then(e=>{let[o]=e;const n=()=>o.downloadInfo().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});async function s(){if(!o){return}$(".download-video-panel").removeClass("action").addClass("progress");const e=await n();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});document.querySelector(".download-progress-cancel>span").onclick=(()=>e.cancelDownload());const t=await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});if(!t){return}const s=document.getElementById("video-complete");s.setAttribute("href",t.url);s.setAttribute("download",t.filename);s.click();const i=`下载完成. 再次保存`;Toast.success(i,"下载视频");$(".download-video-panel").removeClass("progress").addClass("quality")}async function i(){if(!o){return}const e=await n();e.copyUrl();Toast.success("已复制链接到剪贴板.","复制链接",3e3);$(".download-video-panel").removeClass("action").addClass("quality")}$(".video-action>#video-action-download").on("click",s);$(".video-action>#video-action-copy").on("click",i);e.forEach(e=>{$(`
  • ${e.displayName}
  • `).on("click",()=>{o=e;$(".download-video-panel").removeClass("quality").addClass("action")}).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{settingsWidget:{category:"视频与直播",content:t.data.downloadVideoDom.text,success:d}}}})(); offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/video-info.min.js"] = (()=>{return()=>{class t{constructor(t){this.aid=t}async fetchInfo(){const t=JSON.parse(await downloadText(`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}`));if(t.code!==0){throw new Error(t.message)}const i=t.data;this.cid=i.cid;this.pageCount=i.videos;this.coverUrl=i.pic;this.tagId=i.tid;this.tagName=i.tname;this.title=i.title;this.description=i.desc;this.up={uid:i.owner.mid,name:i.owner.name,faceUrl:i.owner.face};this.pages=i.pages.map(t=>{return{cid:t.cid,title:t.part,pageNumber:t.page}});return this}async fetchDanmaku(){this.danmaku=new e(this.cid);return this.danmaku.fetchInfo()}}class i{constructor(t,i){this.text=t;this.p=i}}class e{constructor(t){this.cid=t}async fetchInfo(){const t=await downloadText(`https://api.bilibili.com/x/v1/dm/list.so?oid=${this.cid}`);this.rawXML=t;const e=(new DOMParser).parseFromString(t,"application/xml").documentElement;this.xml=e;this.danmakus=[].map.call(e.querySelectorAll("d[p]"),t=>{return new i(t.innerHTML,t.getAttribute("p"))})}}class a{constructor(t){this.ep=t;this.videos=[]}async fetchInfo(){const i=await downloadText(`https://www.bilibili.com/bangumi/play/ep${this.ep}/`);const e=JSON.parse(i.match(/window\.__INITIAL_STATE__=(.*);\(function\(\){/)[1]);this.title=e.mediaInfo.title;this.cover=e.mediaInfo.cover;this.squareCover=e.mediaInfo.square_cover;this.aid=e.epInfo.aid;this.cid=e.epInfo.cid;this.videos=e.epList.map(async i=>{return{title:i.index_title,aid:i.aid,cid:i.cid,info:await new t(i.aid).fetchInfo()}});return this}}return{export:{VideoInfo:t,BangumiInfo:a,Danmaku:i,DanmakuInfo:e}}}})(); offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/about.min.html"] = `

    Bilibili Evolved

    开源组件

      `; offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/about.min.scss"] = `.about.gui-settings-footer{height:24px;font-size:14px;justify-content:space-between;padding:6px 24px;border-top:1px dashed #8884;}.about.gui-settings-footer>span{opacity:0.2;}.bilibili-evolved-about{display:flex;width:400px;height:70vh;background-color:white;position:fixed;top:15%;left:calc(50% - 200px);z-index:100000;box-shadow:0px 3px 20px 2px #0004;border-top:4px solid $customStyleColor;flex-direction:column;transition:all .2s ease-out;transform-origin:center;transform:scale(0);}.bilibili-evolved-about.opened{transform:scale(1);}.bilibili-evolved-info a{margin:0 4px;}.bilibili-evolved-info>p{margin:8px 0;}.bilibili-evolved-about>div{flex:1 0 0;display:flex;align-items:center;justify-content:space-between;flex-direction:column;padding:8px;}.bilibili-evolved-about>div.about-block{flex:4 0 0;padding:32px;align-items:stretch;}.bilibili-evolved-about h1{font-size:36px;margin-bottom:16px;}.bilibili-evolved-about h2{font-size:18px;margin-bottom:8px;}.open-source-components>li{margin:12px 0;padding:12px 24px;background:rgba(0,0,0,0.2);border-left:4px solid $customStyleColor;cursor:pointer;transition:all .2s ease-out;}.open-source-components>li:hover{opacity:0.8;}.component-name{font-size:18px;font-weight:bold;}.component-info{margin-top:8px;}#about-link{cursor:pointer;transition:all .2s;}.bilibili-evolved-about a{color:$customStyleColor;}#about-link:hover{opacity:1;color:$customStyleColor;}#about-close{background-color:#8884;border-color:transparent;opacity:1;transition:all .2s ease-out;width:80px;height:32px;color:inherit;cursor:pointer;}#about-close:hover{opacity:0.8;}#about-close:active{outline:none;opacity:0.6;}`; diff --git a/bilibili-evolved.preview-offline.user.js b/bilibili-evolved.preview-offline.user.js index f3f19dc1a..f6eff4ec2 100644 --- a/bilibili-evolved.preview-offline.user.js +++ b/bilibili-evolved.preview-offline.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name Bilibili Evolved (Preview Offline) -// @version 132.20 +// @version 132.21 // @description 增强哔哩哔哩Web端体验(预览离线版): 修复界面瑕疵, 删除广告, 使用夜间模式浏览, 下载视频或视频封面, 以及增加对触屏设备的支持等. // @author Grant Howard, Coulomb-G // @copyright 2018, Grant Howrad (https://github.com/the1812) @@ -885,7 +885,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(e.length===0){const e=new Date;this.hour=e.getHours();this.minute=e.getMinutes()}else if(e.length===1){const[t]=e;[this.hour,this.minute]=t.split(":").slice(0,2).map(e=>this.validatePart(e));this.normalize()}else if(v.length===2){[this.hour,this.minute]=e}}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.houre.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,t)=>{return{settingsWidget:{category:"其他",content:`
      \n \n 清除缓存\n \n
      `,success:()=>{$("#clear-cache").on("click",()=>{e.cache={};Toast.success("已删除全部缓存.","清除缓存",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 o=t.attributes.videoInfo.export.VideoInfo;const n=t.attributes.videoInfo.export.BangumiInfo;const s=t.attributes.videoInfo.export.DanmakuInfo;const i={aid:undefined,cid:undefined,isBangumi:false,isMovie:false};class a{constructor(e,t,o){this.quality=e;this.internalName=t;this.displayName=o}async downloadInfo(){const e=new l(this);await e.fetchVideoInfo();return e}static get availableFormats(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText);if(o.code!==0){t("获取清晰度信息失败.")}const s=o.data;const i=s.accept_quality;const r=s.accept_format.split(",");const l=s.accept_description;const d=[];while(i.length>0){const e=new a(i.pop(),r.pop(),l.pop());d.push(e)}e(d)});n.addEventListener("error",()=>t(`获取清晰度信息失败.`));n.withCredentials=true;n.open("GET",o);n.send()})}}class r{constructor(e,t,o,n){this.length=e;this.size=t;this.url=o;this.backupUrls=n}}class l{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null;this.loaded=0;this.totalSize=null;this.workingXhr=null;this.fragmentSplitFactor=8}fetchVideoInfo(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&qn=${this.format.quality}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText.replace(/http:/g,"https:")).data;if(o.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const s=o.durl;this.fragments=s.map(e=>new r(e.length,e.size,e.url,e.backup_url));e(this.fragments)});n.withCredentials=true;n.open("GET",o);n.send()})}cancelDownload(){if(this.workingXhr){this.workingXhr.forEach(e=>e.abort())}}downloadFragment(e){const t=[];const o=Math.round(e.size/this.fragmentSplitFactor);let n=0;while(n<=e.size){const s=`bytes=${n}-${Math.min(e.size-1,Math.round(n+o))}`;t.push(new Promise((t,o)=>{let n=0;const i=new XMLHttpRequest;i.open("GET",e.url);i.responseType="arraybuffer";i.withCredentials=false;i.addEventListener("progress",e=>{this.loaded+=e.loaded-n;n=e.loaded;this.progress&&this.progress(this.loaded/this.totalSize)});i.addEventListener("load",()=>{if((""+i.status)[0]==="2"){t(i.response)}else{o(`请求失败.`)}});i.addEventListener("abort",()=>o("下载已取消."));i.addEventListener("error",()=>o(`下载失败.`));i.setRequestHeader("Range",s);i.send()}));n=Math.round(n+o)}this.workingXhr=Promise.all(t);return this.workingXhr}copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM_setClipboard(e,"text")}extension(e){return(e||this.fragments[0]).url.indexOf(".flv")!==-1?".flv":".mp4"}makeBlob(e,t=null){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=$("a#video-complete").attr("href");if(e&&$(`.link[href=${e}]`).length===0){URL.revokeObjectURL(e)}}downloadSingle(e){const[t]=e;const o=this.makeBlob(t);const n=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","")+this.extension();return[o,n]}async downloadMultiple(e){const t=new JSZip;const o=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");if(e.length>1){e.forEach((e,n)=>{const s=this.fragments[n];t.file(`${o} - ${n+1}${this.extension(s)}`,this.makeBlob(e,s))})}else{const[n]=e;t.file(`${o}${this.extension()}`,this.makeBlob(n))}if(settings.downloadDanmaku){const e=new s(i.cid);await e.fetchInfo();t.file(`${o}.xml`,e.rawXML)}const n=await t.generateAsync({type:"blob"});const a=o+".zip";return[n,a]}async download(){const e=[];this.loaded=0;this.totalSize=this.fragments.map(e=>e.size).reduce((e,t)=>e+t);for(const t of this.fragments){const o=await this.downloadFragment(t);e.push(o)}if(e.length<1){throw new Error("下载失败.")}let t=null;let o=null;if(e.length===1&&!settings.downloadDanmaku){[t,o]=this.downloadSingle(e)}else{[t,o]=await this.downloadMultiple(e)}const n=URL.createObjectURL(t);this.cleanUpOldBlobUrl();this.progress&&this.progress(0);return{url:n,filename:o}}}function d(){(async()=>{let e=(unsafeWindow||window).aid;let t=(unsafeWindow||window).cid;if(e===undefined||t===undefined){const n=document.URL.match(/\/av(\d+)/);const s=document.URL.match(/\/ep(\d+)/);if(n&&n[1]){const s=await new o(n[1]).fetchInfo();e=s.aid;t=s.cid}}return[e,t]})().then(e=>{const[o,n]=e;if(o===undefined||n===undefined){return}i.aid=o;i.cid=n;a.availableFormats.then(e=>{let[o]=e;const n=()=>o.downloadInfo().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});async function s(){if(!o){return}$(".download-video-panel").removeClass("action").addClass("progress");const e=await n();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});document.querySelector(".download-progress-cancel>span").onclick=(()=>e.cancelDownload());const t=await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});if(!t){return}const s=document.getElementById("video-complete");s.setAttribute("href",t.url);s.setAttribute("download",t.filename);s.click();const i=`下载完成. 再次保存`;Toast.success(i,"下载视频");$(".download-video-panel").removeClass("progress").addClass("quality")}async function i(){if(!o){return}const e=await n();e.copyUrl();Toast.success("已复制链接到剪贴板.","复制链接",3e3);$(".download-video-panel").removeClass("action").addClass("quality")}$(".video-action>#video-action-download").on("click",s);$(".video-action>#video-action-copy").on("click",i);e.forEach(e=>{$(`
    • ${e.displayName}
    • `).on("click",()=>{o=e;$(".download-video-panel").removeClass("quality").addClass("action")}).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{settingsWidget:{category:"视频与直播",content:t.data.downloadVideoDom.text,success:d}}}})(); +offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.js"] = (()=>{return(e,t)=>{const o=t.attributes.videoInfo.export.VideoInfo;const n=t.attributes.videoInfo.export.BangumiInfo;const s=t.attributes.videoInfo.export.DanmakuInfo;const i={aid:undefined,cid:undefined,isBangumi:false,isMovie:false};class a{constructor(e,t,o){this.quality=e;this.internalName=t;this.displayName=o}async downloadInfo(){const e=new l(this);await e.fetchVideoInfo();return e}static get availableFormats(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText);if(o.code!==0){t("获取清晰度信息失败.")}const s=o.data;const i=s.accept_quality;const r=s.accept_format.split(",");const l=s.accept_description;const d=[];while(i.length>0){const e=new a(i.pop(),r.pop(),l.pop());d.push(e)}e(d)});n.addEventListener("error",()=>t(`获取清晰度信息失败.`));n.withCredentials=true;n.open("GET",o);n.send()})}}class r{constructor(e,t,o,n){this.length=e;this.size=t;this.url=o;this.backupUrls=n}}class l{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null;this.loaded=0;this.totalSize=null;this.workingXhr=null;this.fragmentSplitFactor=6*5}fetchVideoInfo(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&qn=${this.format.quality}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText.replace(/http:/g,"https:")).data;if(o.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const s=o.durl;this.fragments=s.map(e=>new r(e.length,e.size,e.url,e.backup_url));e(this.fragments)});n.withCredentials=true;n.open("GET",o);n.send()})}cancelDownload(){if(this.workingXhr){this.workingXhr.forEach(e=>e.abort())}}downloadFragment(e){const t=[];const o=Math.round(e.size/this.fragmentSplitFactor);let n=0;while(n{let n=0;const i=new XMLHttpRequest;i.open("GET",e.url);i.responseType="arraybuffer";i.withCredentials=false;i.addEventListener("progress",e=>{this.loaded+=e.loaded-n;n=e.loaded;this.progress&&this.progress(this.loaded/this.totalSize)});i.addEventListener("load",()=>{if((""+i.status)[0]==="2"){t(i.response)}else{o(`请求失败.`)}});i.addEventListener("abort",()=>o("下载已取消."));i.addEventListener("error",()=>o(`下载失败.`));i.setRequestHeader("Range",s);i.send()}));n=Math.round(n+o)}this.workingXhr=Promise.all(t);return this.workingXhr}copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM_setClipboard(e,"text")}extension(e){return(e||this.fragments[0]).url.indexOf(".flv")!==-1?".flv":".mp4"}makeBlob(e,t=null){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=$("a#video-complete").attr("href");if(e&&$(`.link[href=${e}]`).length===0){URL.revokeObjectURL(e)}}downloadSingle(e){const[t]=e;const o=this.makeBlob(t);const n=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","")+this.extension();return[o,n]}async downloadMultiple(e){const t=new JSZip;const o=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");if(e.length>1){e.forEach((e,n)=>{const s=this.fragments[n];t.file(`${o} - ${n+1}${this.extension(s)}`,this.makeBlob(e,s))})}else{const[n]=e;t.file(`${o}${this.extension()}`,this.makeBlob(n))}if(settings.downloadDanmaku){const e=new s(i.cid);await e.fetchInfo();t.file(`${o}.xml`,e.rawXML)}const n=await t.generateAsync({type:"blob"});const a=o+".zip";return[n,a]}async download(){const e=[];this.loaded=0;this.totalSize=this.fragments.map(e=>e.size).reduce((e,t)=>e+t);for(const t of this.fragments){const o=await this.downloadFragment(t);e.push(o)}if(e.length<1){throw new Error("下载失败.")}let t=null;let o=null;if(e.length===1&&!settings.downloadDanmaku){[t,o]=this.downloadSingle(e)}else{[t,o]=await this.downloadMultiple(e)}const n=URL.createObjectURL(t);this.cleanUpOldBlobUrl();this.progress&&this.progress(0);return{url:n,filename:o}}}function d(){(async()=>{let e=(unsafeWindow||window).aid;let t=(unsafeWindow||window).cid;if(e===undefined||t===undefined){const n=document.URL.match(/\/av(\d+)/);const s=document.URL.match(/\/ep(\d+)/);if(n&&n[1]){const s=await new o(n[1]).fetchInfo();e=s.aid;t=s.cid}}return[e,t]})().then(e=>{const[o,n]=e;if(o===undefined||n===undefined){return}i.aid=o;i.cid=n;a.availableFormats.then(e=>{let[o]=e;const n=()=>o.downloadInfo().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});async function s(){if(!o){return}$(".download-video-panel").removeClass("action").addClass("progress");const e=await n();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});document.querySelector(".download-progress-cancel>span").onclick=(()=>e.cancelDownload());const t=await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});if(!t){return}const s=document.getElementById("video-complete");s.setAttribute("href",t.url);s.setAttribute("download",t.filename);s.click();const i=`下载完成. 再次保存`;Toast.success(i,"下载视频");$(".download-video-panel").removeClass("progress").addClass("quality")}async function i(){if(!o){return}const e=await n();e.copyUrl();Toast.success("已复制链接到剪贴板.","复制链接",3e3);$(".download-video-panel").removeClass("action").addClass("quality")}$(".video-action>#video-action-download").on("click",s);$(".video-action>#video-action-copy").on("click",i);e.forEach(e=>{$(`
    • ${e.displayName}
    • `).on("click",()=>{o=e;$(".download-video-panel").removeClass("quality").addClass("action")}).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{settingsWidget:{category:"视频与直播",content:t.data.downloadVideoDom.text,success:d}}}})(); offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/video-info.min.js"] = (()=>{return()=>{class t{constructor(t){this.aid=t}async fetchInfo(){const t=JSON.parse(await downloadText(`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}`));if(t.code!==0){throw new Error(t.message)}const i=t.data;this.cid=i.cid;this.pageCount=i.videos;this.coverUrl=i.pic;this.tagId=i.tid;this.tagName=i.tname;this.title=i.title;this.description=i.desc;this.up={uid:i.owner.mid,name:i.owner.name,faceUrl:i.owner.face};this.pages=i.pages.map(t=>{return{cid:t.cid,title:t.part,pageNumber:t.page}});return this}async fetchDanmaku(){this.danmaku=new e(this.cid);return this.danmaku.fetchInfo()}}class i{constructor(t,i){this.text=t;this.p=i}}class e{constructor(t){this.cid=t}async fetchInfo(){const t=await downloadText(`https://api.bilibili.com/x/v1/dm/list.so?oid=${this.cid}`);this.rawXML=t;const e=(new DOMParser).parseFromString(t,"application/xml").documentElement;this.xml=e;this.danmakus=[].map.call(e.querySelectorAll("d[p]"),t=>{return new i(t.innerHTML,t.getAttribute("p"))})}}class a{constructor(t){this.ep=t;this.videos=[]}async fetchInfo(){const i=await downloadText(`https://www.bilibili.com/bangumi/play/ep${this.ep}/`);const e=JSON.parse(i.match(/window\.__INITIAL_STATE__=(.*);\(function\(\){/)[1]);this.title=e.mediaInfo.title;this.cover=e.mediaInfo.cover;this.squareCover=e.mediaInfo.square_cover;this.aid=e.epInfo.aid;this.cid=e.epInfo.cid;this.videos=e.epList.map(async i=>{return{title:i.index_title,aid:i.aid,cid:i.cid,info:await new t(i.aid).fetchInfo()}});return this}}return{export:{VideoInfo:t,BangumiInfo:a,Danmaku:i,DanmakuInfo:e}}}})(); offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/about.min.html"] = `

      Bilibili Evolved

      开源组件

        `; offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/about.min.scss"] = `.about.gui-settings-footer{height:24px;font-size:14px;justify-content:space-between;padding:6px 24px;border-top:1px dashed #8884;}.about.gui-settings-footer>span{opacity:0.2;}.bilibili-evolved-about{display:flex;width:400px;height:70vh;background-color:white;position:fixed;top:15%;left:calc(50% - 200px);z-index:100000;box-shadow:0px 3px 20px 2px #0004;border-top:4px solid $customStyleColor;flex-direction:column;transition:all .2s ease-out;transform-origin:center;transform:scale(0);}.bilibili-evolved-about.opened{transform:scale(1);}.bilibili-evolved-info a{margin:0 4px;}.bilibili-evolved-info>p{margin:8px 0;}.bilibili-evolved-about>div{flex:1 0 0;display:flex;align-items:center;justify-content:space-between;flex-direction:column;padding:8px;}.bilibili-evolved-about>div.about-block{flex:4 0 0;padding:32px;align-items:stretch;}.bilibili-evolved-about h1{font-size:36px;margin-bottom:16px;}.bilibili-evolved-about h2{font-size:18px;margin-bottom:8px;}.open-source-components>li{margin:12px 0;padding:12px 24px;background:rgba(0,0,0,0.2);border-left:4px solid $customStyleColor;cursor:pointer;transition:all .2s ease-out;}.open-source-components>li:hover{opacity:0.8;}.component-name{font-size:18px;font-weight:bold;}.component-info{margin-top:8px;}#about-link{cursor:pointer;transition:all .2s;}.bilibili-evolved-about a{color:$customStyleColor;}#about-link:hover{opacity:1;color:$customStyleColor;}#about-close{background-color:#8884;border-color:transparent;opacity:1;transition:all .2s ease-out;width:80px;height:32px;color:inherit;cursor:pointer;}#about-close:hover{opacity:0.8;}#about-close:active{outline:none;opacity:0.6;}`; diff --git a/min/download-video.min.js b/min/download-video.min.js index f6984a3ca..f7d7805a9 100644 --- a/min/download-video.min.js +++ b/min/download-video.min.js @@ -1 +1 @@ -(()=>{return(e,t)=>{const o=t.attributes.videoInfo.export.VideoInfo;const n=t.attributes.videoInfo.export.BangumiInfo;const s=t.attributes.videoInfo.export.DanmakuInfo;const i={aid:undefined,cid:undefined,isBangumi:false,isMovie:false};class a{constructor(e,t,o){this.quality=e;this.internalName=t;this.displayName=o}async downloadInfo(){const e=new l(this);await e.fetchVideoInfo();return e}static get availableFormats(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText);if(o.code!==0){t("获取清晰度信息失败.")}const s=o.data;const i=s.accept_quality;const r=s.accept_format.split(",");const l=s.accept_description;const d=[];while(i.length>0){const e=new a(i.pop(),r.pop(),l.pop());d.push(e)}e(d)});n.addEventListener("error",()=>t(`获取清晰度信息失败.`));n.withCredentials=true;n.open("GET",o);n.send()})}}class r{constructor(e,t,o,n){this.length=e;this.size=t;this.url=o;this.backupUrls=n}}class l{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null;this.loaded=0;this.totalSize=null;this.workingXhr=null;this.fragmentSplitFactor=8}fetchVideoInfo(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&qn=${this.format.quality}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText.replace(/http:/g,"https:")).data;if(o.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const s=o.durl;this.fragments=s.map(e=>new r(e.length,e.size,e.url,e.backup_url));e(this.fragments)});n.withCredentials=true;n.open("GET",o);n.send()})}cancelDownload(){if(this.workingXhr){this.workingXhr.forEach(e=>e.abort())}}downloadFragment(e){const t=[];const o=Math.round(e.size/this.fragmentSplitFactor);let n=0;while(n<=e.size){const s=`bytes=${n}-${Math.min(e.size-1,Math.round(n+o))}`;t.push(new Promise((t,o)=>{let n=0;const i=new XMLHttpRequest;i.open("GET",e.url);i.responseType="arraybuffer";i.withCredentials=false;i.addEventListener("progress",e=>{this.loaded+=e.loaded-n;n=e.loaded;this.progress&&this.progress(this.loaded/this.totalSize)});i.addEventListener("load",()=>{if((""+i.status)[0]==="2"){t(i.response)}else{o(`请求失败.`)}});i.addEventListener("abort",()=>o("下载已取消."));i.addEventListener("error",()=>o(`下载失败.`));i.setRequestHeader("Range",s);i.send()}));n=Math.round(n+o)}this.workingXhr=Promise.all(t);return this.workingXhr}copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM_setClipboard(e,"text")}extension(e){return(e||this.fragments[0]).url.indexOf(".flv")!==-1?".flv":".mp4"}makeBlob(e,t=null){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=$("a#video-complete").attr("href");if(e&&$(`.link[href=${e}]`).length===0){URL.revokeObjectURL(e)}}downloadSingle(e){const[t]=e;const o=this.makeBlob(t);const n=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","")+this.extension();return[o,n]}async downloadMultiple(e){const t=new JSZip;const o=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");if(e.length>1){e.forEach((e,n)=>{const s=this.fragments[n];t.file(`${o} - ${n+1}${this.extension(s)}`,this.makeBlob(e,s))})}else{const[n]=e;t.file(`${o}${this.extension()}`,this.makeBlob(n))}if(settings.downloadDanmaku){const e=new s(i.cid);await e.fetchInfo();t.file(`${o}.xml`,e.rawXML)}const n=await t.generateAsync({type:"blob"});const a=o+".zip";return[n,a]}async download(){const e=[];this.loaded=0;this.totalSize=this.fragments.map(e=>e.size).reduce((e,t)=>e+t);for(const t of this.fragments){const o=await this.downloadFragment(t);e.push(o)}if(e.length<1){throw new Error("下载失败.")}let t=null;let o=null;if(e.length===1&&!settings.downloadDanmaku){[t,o]=this.downloadSingle(e)}else{[t,o]=await this.downloadMultiple(e)}const n=URL.createObjectURL(t);this.cleanUpOldBlobUrl();this.progress&&this.progress(0);return{url:n,filename:o}}}function d(){(async()=>{let e=(unsafeWindow||window).aid;let t=(unsafeWindow||window).cid;if(e===undefined||t===undefined){const n=document.URL.match(/\/av(\d+)/);const s=document.URL.match(/\/ep(\d+)/);if(n&&n[1]){const s=await new o(n[1]).fetchInfo();e=s.aid;t=s.cid}}return[e,t]})().then(e=>{const[o,n]=e;if(o===undefined||n===undefined){return}i.aid=o;i.cid=n;a.availableFormats.then(e=>{let[o]=e;const n=()=>o.downloadInfo().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});async function s(){if(!o){return}$(".download-video-panel").removeClass("action").addClass("progress");const e=await n();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});document.querySelector(".download-progress-cancel>span").onclick=(()=>e.cancelDownload());const t=await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});if(!t){return}const s=document.getElementById("video-complete");s.setAttribute("href",t.url);s.setAttribute("download",t.filename);s.click();const i=`下载完成. 再次保存`;Toast.success(i,"下载视频");$(".download-video-panel").removeClass("progress").addClass("quality")}async function i(){if(!o){return}const e=await n();e.copyUrl();Toast.success("已复制链接到剪贴板.","复制链接",3e3);$(".download-video-panel").removeClass("action").addClass("quality")}$(".video-action>#video-action-download").on("click",s);$(".video-action>#video-action-copy").on("click",i);e.forEach(e=>{$(`
      • ${e.displayName}
      • `).on("click",()=>{o=e;$(".download-video-panel").removeClass("quality").addClass("action")}).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{settingsWidget:{category:"视频与直播",content:t.data.downloadVideoDom.text,success:d}}}})(); \ No newline at end of file +(()=>{return(e,t)=>{const o=t.attributes.videoInfo.export.VideoInfo;const n=t.attributes.videoInfo.export.BangumiInfo;const s=t.attributes.videoInfo.export.DanmakuInfo;const i={aid:undefined,cid:undefined,isBangumi:false,isMovie:false};class a{constructor(e,t,o){this.quality=e;this.internalName=t;this.displayName=o}async downloadInfo(){const e=new l(this);await e.fetchVideoInfo();return e}static get availableFormats(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText);if(o.code!==0){t("获取清晰度信息失败.")}const s=o.data;const i=s.accept_quality;const r=s.accept_format.split(",");const l=s.accept_description;const d=[];while(i.length>0){const e=new a(i.pop(),r.pop(),l.pop());d.push(e)}e(d)});n.addEventListener("error",()=>t(`获取清晰度信息失败.`));n.withCredentials=true;n.open("GET",o);n.send()})}}class r{constructor(e,t,o,n){this.length=e;this.size=t;this.url=o;this.backupUrls=n}}class l{constructor(e,t){this.format=e;this.fragments=t||[];this.progress=null;this.loaded=0;this.totalSize=null;this.workingXhr=null;this.fragmentSplitFactor=6*5}fetchVideoInfo(){return new Promise((e,t)=>{const o=`https://api.bilibili.com/x/player/playurl?avid=${i.aid}&cid=${i.cid}&qn=${this.format.quality}&otype=json`;const n=new XMLHttpRequest;n.addEventListener("load",()=>{const o=JSON.parse(n.responseText.replace(/http:/g,"https:")).data;if(o.quality!==this.format.quality){t("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const s=o.durl;this.fragments=s.map(e=>new r(e.length,e.size,e.url,e.backup_url));e(this.fragments)});n.withCredentials=true;n.open("GET",o);n.send()})}cancelDownload(){if(this.workingXhr){this.workingXhr.forEach(e=>e.abort())}}downloadFragment(e){const t=[];const o=Math.round(e.size/this.fragmentSplitFactor);let n=0;while(n{let n=0;const i=new XMLHttpRequest;i.open("GET",e.url);i.responseType="arraybuffer";i.withCredentials=false;i.addEventListener("progress",e=>{this.loaded+=e.loaded-n;n=e.loaded;this.progress&&this.progress(this.loaded/this.totalSize)});i.addEventListener("load",()=>{if((""+i.status)[0]==="2"){t(i.response)}else{o(`请求失败.`)}});i.addEventListener("abort",()=>o("下载已取消."));i.addEventListener("error",()=>o(`下载失败.`));i.setRequestHeader("Range",s);i.send()}));n=Math.round(n+o)}this.workingXhr=Promise.all(t);return this.workingXhr}copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM_setClipboard(e,"text")}extension(e){return(e||this.fragments[0]).url.indexOf(".flv")!==-1?".flv":".mp4"}makeBlob(e,t=null){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=$("a#video-complete").attr("href");if(e&&$(`.link[href=${e}]`).length===0){URL.revokeObjectURL(e)}}downloadSingle(e){const[t]=e;const o=this.makeBlob(t);const n=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","")+this.extension();return[o,n]}async downloadMultiple(e){const t=new JSZip;const o=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","");if(e.length>1){e.forEach((e,n)=>{const s=this.fragments[n];t.file(`${o} - ${n+1}${this.extension(s)}`,this.makeBlob(e,s))})}else{const[n]=e;t.file(`${o}${this.extension()}`,this.makeBlob(n))}if(settings.downloadDanmaku){const e=new s(i.cid);await e.fetchInfo();t.file(`${o}.xml`,e.rawXML)}const n=await t.generateAsync({type:"blob"});const a=o+".zip";return[n,a]}async download(){const e=[];this.loaded=0;this.totalSize=this.fragments.map(e=>e.size).reduce((e,t)=>e+t);for(const t of this.fragments){const o=await this.downloadFragment(t);e.push(o)}if(e.length<1){throw new Error("下载失败.")}let t=null;let o=null;if(e.length===1&&!settings.downloadDanmaku){[t,o]=this.downloadSingle(e)}else{[t,o]=await this.downloadMultiple(e)}const n=URL.createObjectURL(t);this.cleanUpOldBlobUrl();this.progress&&this.progress(0);return{url:n,filename:o}}}function d(){(async()=>{let e=(unsafeWindow||window).aid;let t=(unsafeWindow||window).cid;if(e===undefined||t===undefined){const n=document.URL.match(/\/av(\d+)/);const s=document.URL.match(/\/ep(\d+)/);if(n&&n[1]){const s=await new o(n[1]).fetchInfo();e=s.aid;t=s.cid}}return[e,t]})().then(e=>{const[o,n]=e;if(o===undefined||n===undefined){return}i.aid=o;i.cid=n;a.availableFormats.then(e=>{let[o]=e;const n=()=>o.downloadInfo().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});async function s(){if(!o){return}$(".download-video-panel").removeClass("action").addClass("progress");const e=await n();e.progress=(e=>{$(".download-progress-value").text(`${fixed(e*100)}`);$(".download-progress-foreground").css("transform",`scaleX(${e})`)});document.querySelector(".download-progress-cancel>span").onclick=(()=>e.cancelDownload());const t=await e.download().catch(e=>{$(".download-video-panel").addClass("error");$(".video-error").text(e)});if(!t){return}const s=document.getElementById("video-complete");s.setAttribute("href",t.url);s.setAttribute("download",t.filename);s.click();const i=`下载完成. 再次保存`;Toast.success(i,"下载视频");$(".download-video-panel").removeClass("progress").addClass("quality")}async function i(){if(!o){return}const e=await n();e.copyUrl();Toast.success("已复制链接到剪贴板.","复制链接",3e3);$(".download-video-panel").removeClass("action").addClass("quality")}$(".video-action>#video-action-download").on("click",s);$(".video-action>#video-action-copy").on("click",i);e.forEach(e=>{$(`
      • ${e.displayName}
      • `).on("click",()=>{o=e;$(".download-video-panel").removeClass("quality").addClass("action")}).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{settingsWidget:{category:"视频与直播",content:t.data.downloadVideoDom.text,success:d}}}})(); \ No newline at end of file diff --git a/video/download-video/download-video.js b/video/download-video/download-video.js index 1192b31e1..fb6366f9c 100644 --- a/video/download-video/download-video.js +++ b/video/download-video/download-video.js @@ -81,7 +81,7 @@ this.loaded = 0; this.totalSize = null; this.workingXhr = null; - this.fragmentSplitFactor = 8; + this.fragmentSplitFactor = 6 * 5; } fetchVideoInfo() { @@ -125,7 +125,7 @@ const promises = []; const partialLength = Math.round(fragment.size / this.fragmentSplitFactor); let startByte = 0; - while (startByte <= fragment.size) + while (startByte < fragment.size) { const range = `bytes=${startByte}-${Math.min(fragment.size - 1, Math.round(startByte + partialLength))}`; promises.push(new Promise((resolve, reject) =>