From 71a5ca703b52c8a17f51669e984492773d431855 Mon Sep 17 00:00:00 2001 From: the1812 Date: Sat, 26 Oct 2019 11:01:14 +0800 Subject: [PATCH] Add lazy loading for dpi-img --- bilibili-evolved.offline.user.js | 4 +-- bilibili-evolved.preview-offline.user.js | 4 +-- bilibili-evolved.preview.user.js | 2 +- bilibili-evolved.user.js | 2 +- min/bundle.json | 2 +- min/bundle.zip | Bin 1421412 -> 1421832 bytes min/dpi-img.vue.min.js | 2 +- src/style/dpi-img.vue | 37 ++++++++++++++++++++--- 8 files changed, 40 insertions(+), 13 deletions(-) diff --git a/bilibili-evolved.offline.user.js b/bilibili-evolved.offline.user.js index 4ef1a28b9..65d6b2fd9 100644 --- a/bilibili-evolved.offline.user.js +++ b/bilibili-evolved.offline.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name Bilibili Evolved (Offline) -// @version 466.19 +// @version 466.80 // @description Bilibili Evolved 的离线版, 所有功能都已内置于脚本中. // @author Grant Howard, Coulomb-G // @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G) @@ -1084,7 +1084,7 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.css"] = `.download-video{--download-video-background:white;--download-video-foreground:black;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) scale(.95);background:var(--download-video-background);color:var(--download-video-foreground);box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;z-index:10001;pointer-events:none;opacity:0;padding:16px;width:300px;display:flex;flex-direction:column;align-items:stretch;justify-content:space-between;max-height:90%}.download-video,.download-video *{transition:.2s ease-out;-webkit-tap-highlight-color:transparent!important}.download-video.opened{pointer-events:initial;opacity:1;transform:translate(-50%,-50%) scale(1)}body.dark .download-video{--download-video-background:#222;--download-video-foreground:#eee}.round-corner .download-video,.round-corner .download-video .episode-list .v-checkbox,.round-corner .download-video .rpc-settings{border-radius:var(--large-corner-radius)}.round-corner .download-video .button,.round-corner .download-video .cover,.round-corner .download-video .direct-download .progress .background,.round-corner .download-video .direct-download .progress .foreground,.round-corner .download-video .rpc-settings input[type=text],.round-corner .download-video .title,.round-corner .download-video button{border-radius:var(--corner-radius)}.download-video .cover{width:240px;min-height:135px;background-color:#8882}.download-video .header{display:flex;justify-content:space-between;align-items:center}.download-video h1{font-size:16pt;font-weight:700;color:var(--download-video-foreground)}.download-video .header .mdi-close{font-size:16pt;color:var(--download-video-foreground);cursor:pointer}.download-video .header .mdi-close:hover{color:var(--theme-color)}.download-video .info{display:flex;flex-direction:column;align-items:center;margin-top:12px}.download-video .title{display:flex;flex-direction:column;justify-content:space-between;align-items:stretch;margin-top:12px}.download-video .title .bold{width:300px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:center}.download-video .title .size{font-size:10pt;color:var(--download-video-foreground);align-self:center;display:flex;align-items:center;height:24px}.download-video .bold{color:var(--download-video-foreground);font-weight:700;font-size:12pt}.download-video .option-item{display:flex;justify-content:space-between;align-items:center;padding-top:12px;font-size:10pt}.download-video .tabs{display:flex;padding-top:12px;font-size:10pt}.download-video .tabs .tab{padding:6px 12px;border-bottom:2px solid transparent;cursor:pointer}.download-video .tabs .tab.active{color:var(--theme-color);border-bottom-color:var(--theme-color)}.download-video .separator{height:1px;background:#8884;width:100%;margin:12px 0;flex-shrink:0}.download-video h2{font-size:12pt;font-weight:700;color:var(--download-video-foreground)}.download-video .direct-download{display:flex;flex-direction:column;align-items:start;justify-content:space-between}.download-video .button,.download-video button{border:none;outline:0!important;padding:6px 16px;font-size:10pt;cursor:pointer;background:#8884;color:var(--download-video-foreground)}.download-video .button:hover,.download-video button:hover{background:#8886}.download-video .primary{background:var(--theme-color);color:var(--foreground-color);align-self:center}.download-video .primary:hover{background:var(--theme-color-90)}.download-video .busy .button,.download-video .busy .primary,.download-video .busy button,.download-video button:disabled{background-color:#0001;color:#8884;cursor:not-allowed}.download-video .busy .button,.download-video .busy button{cursor:wait!important}.download-video .direct-download .progress{align-self:stretch;display:flex;align-items:center;margin-top:8px}.download-video .direct-download .progress .background{flex-grow:1;height:4px;background:#8884;margin-right:4px;position:relative}.download-video .direct-download .progress .background .foreground{position:absolute;top:0;left:0;height:4px;background:linear-gradient(to right,var(--theme-color),var(--theme-color-60))}.download-video .direct-download .progress .percent{width:50px;text-align:right}.download-video .actions{display:flex;flex-wrap:wrap;justify-content:space-between;margin:8px -4px 0}.download-video .actions>*{margin:4px;flex-grow:1;flex-basis:calc(50% - 16px);display:flex;justify-content:center;align-items:center}.download-video i.mdi-alert-circle{font-size:14pt;color:#ff9800}.download-video .size-warning{position:relative;padding:0 8px}.download-video .size-warning-tip{position:absolute;bottom:100%;left:50%;transform:translateX(-50%);background:var(--download-video-background);color:var(--download-video-foreground);border:1px dashed var(--theme-color);z-index:2;font-size:10pt;width:200px;padding:8px;box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;pointer-events:none;opacity:0}.download-video .size-warning:hover .size-warning-tip{opacity:1}.download-video .episode-list .v-checkbox{padding:4px 8px;margin:4px 0;position:relative;background-color:transparent}.download-video .episode-list .v-checkbox.checked{background-color:#8882}.download-video .episode-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}.download-video .episode-list{overflow:auto;max-height:320px}.download-video button.list-tool{padding:4px;line-height:1;font-size:12pt;margin:0 4px}.download-video .episode-header h2{flex-grow:1}.download-video .selected-count{width:64px;text-align:right}.download-video .aria2-rpc .mdi{margin-left:8px;font-size:14pt;line-height:1}.download-video .aria2-rpc{position:relative}.download-video .rpc-settings{position:absolute;display:flex;flex-direction:column;align-items:stretch;color:var(--download-video-foreground);background:#fff;bottom:120%;left:50%;cursor:initial;box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;transform-origin:bottom;transform:translateX(-50%) scale(.9);opacity:0;pointer-events:none;padding:8px;z-index:3;transition:.3s cubic-bezier(.18,.89,.32,1.28);width:120%}body.dark .download-video .rpc-settings{background:#282828}.download-video .rpc-settings>*{margin:8px}.download-video .rpc-settings.show{opacity:1;transform:translateX(-50%) scale(1);pointer-events:initial}.download-video .rpc-settings input[type=text]{background:0 0;color:var(--download-video-foreground);border:1px solid #8884;padding:4px;margin-left:8px}.download-video .rpc-settings input[type=text]:focus{border-color:var(--theme-color)}.download-video .rpc-settings .operations{display:flex;align-items:center;justify-content:space-evenly}.download-video .final-dir{word-break:break-all}.download-video .rpc-settings-item{display:flex;align-items:center;justify-content:space-between;white-space:nowrap}.download-video .rpc-settings-item input[type=text]{flex-grow:1;margin-left:24px}.download-video button.cancel-download,.download-video button.start-download{margin-top:8px}.download-video .direct-download-header{align-self:stretch;display:flex;justify-content:space-between;align-items:center}body.dark .download-video .direct-download .progress .foreground{background:linear-gradient(to right,var(--theme-color-70),var(--theme-color))}`; offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.html"] = `

下载视频

单个视频
批量导出
警告: 过大的视频大小会在直接下载时占用大量内存, 并可能导致浏览器标签页崩溃. 请考虑降低清晰度或使用导出选项.
预计大小: {{displaySize}}
格式
清晰度
弹幕

直接下载

{{speed}}
{{progressPercent}}%

选集

{{selectedEpisodeCount}}/{{episodeList.length}}

导出

{{showRpcSettings ? '取消' : 'aria2 RPC'}}

aria2 RPC

配置

主机
端口
密钥
限速
默认路径
路径
最终路径: {{rpcSettings.baseDir + rpcSettings.dir}}
方法
开始下载
{{saveRpcSettingsText}}
`; offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.js"] = (()=>{return(e,t)=>{const{getFriendlyTitle:s}=t.import("title");const{VideoInfo:a,DanmakuInfo:i}=t.import("video-info");class n{constructor(){this.menuClasses=["quality","action","progress"];[this.currentMenuClass]=this.menuClasses}get menuPanel(){return document.querySelector(".download-video-panel")}addMenuClass(){this.menuPanel.classList.remove(...this.menuClasses);this.menuPanel.classList.add(this.currentMenuClass);return this.currentMenuClass}resetMenuClass(){[this.currentMenuClass]=this.menuClasses;this.addMenuClass()}nextMenuClass(){const e=this.menuClasses.indexOf(this.currentMenuClass)+1;const t=this.menuClasses[e>=this.menuClasses.length?0:e];this.currentMenuClass=t;this.addMenuClass();return t}closeMenu(){this.menuPanel.classList.remove("opened");setTimeout(()=>this.resetMenuClass(),200)}addError(){this.menuPanel.classList.add("error")}removeError(){this.menuPanel.classList.remove("error");this.resetMenuClass()}async getDashUrl(e){throw new Error("video dash is not supported")}async getUrl(e){if(e){return`https://api.bilibili.com/x/player/playurl?avid=${r.aid}&cid=${r.cid}&qn=${e}&otype=json`}else{return`https://api.bilibili.com/x/player/playurl?avid=${r.aid}&cid=${r.cid}&otype=json`}}}class o extends n{async getDashUrl(e){if(e){return`https://api.bilibili.com/pgc/player/web/playurl?avid=56995872&cid=99547543&qn=${e}&otype=json&fourk=1&fnval=16`}else{return`https://api.bilibili.com/pgc/player/web/playurl?avid=56995872&cid=99547543&otype=json&fourk=1&fnval=16`}}async getUrl(e){if(e){return`https://api.bilibili.com/pgc/player/web/playurl?avid=${r.aid}&cid=${r.cid}&qn=${e}&otype=json`}else{return`https://api.bilibili.com/pgc/player/web/playurl?avid=${r.aid}&cid=${r.cid}&qn=&otype=json`}}}const r={entity:new n,aid:"",cid:""};let l=[];let c=null;class d{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async downloadInfo(e=false){const t=new h(this);await t.fetchVideoInfo(e);return t}static parseFormats(e){const t=e.accept_quality;const s=e.accept_format.split(",");const a=e.accept_description;const i=t.map((e,t)=>{return new d(e,s[t],a[t])});return i}static async getAvailableDashFormats(){const e=await r.entity.getDashUrl();const t=await Ajax.getJsonWithCredentials(e);if(t.code!==0){throw new Error("获取清晰度信息失败.")}return d.parseFormats(t.result)}static async getAvailableFormats(){const e=await r.entity.getUrl();const t=await Ajax.getJsonWithCredentials(e);if(t.code!==0){throw new Error("获取清晰度信息失败.")}const s=t.data||t.result||t;return d.parseFormats(s)}}class h{constructor(e,t){this.fragmentSplitFactor=6*2;this.workingXhr=null;this.progressMap=new Map;this.format=e;this.fragments=t||[];this.videoSpeed=new u(this)}get totalSize(){return this.fragments.map(e=>e.size).reduce((e,t)=>e+t)}async fetchVideoInfo(e=false){if(!e){const e=await r.entity.getUrl(this.format.quality);const t=await Ajax.getTextWithCredentials(e);const s=JSON.parse(t.replace(/http:/g,"https:"));const a=s.data||s.result||s;if(a.quality!==this.format.quality){throw new Error("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const i=a.durl;this.fragments=i.map(e=>{return{length:e.length,size:e.size,url:e.url,backupUrls:e.backup_url}})}else{const{dashToFragment:e,getDashInfo:s}=await t.importAsync("video-dash");const a=await s(r.aid,r.cid,this.format.quality);const i=a.videoDashes.sort(descendingSort(e=>e.bandWidth))[0];const n=a.audioDashes.sort(descendingSort(e=>e.bandWidth))[0];this.fragments=[e(i),e(n)]}return this.fragments}updateProgress(){const e=this.progressMap?[...this.progressMap.values()].reduce((e,t)=>e+t,0)/this.totalSize:0;if(e>1||e<0){console.error(`[下载视频] 进度异常: ${e}`,this.progressMap.values())}this.progress&&this.progress(e)}cancelDownload(){this.videoSpeed.stopMeasure();if(this.workingXhr!==null){this.workingXhr.forEach(e=>e.abort())}else{logError("Cancel Download Failed: forEach in this.workingXhr not found.")}}downloadFragment(e){const t=[];this.workingXhr=[];this.progressMap=new Map;this.updateProgress();let s;if(e.size<=96*1024*1024){s=e.size/this.fragmentSplitFactor}else{s=16*1024*1024}let a=0;const i=e=>[...this.progressMap.keys()].indexOf(e)+1;while(a{const a=new XMLHttpRequest;a.open("GET",e.url);a.responseType="arraybuffer";a.withCredentials=false;a.addEventListener("progress",e=>{console.log(`[下载视频] 视频片段${i(a)}下载进度: ${e.loaded}/${r} bytes loaded, ${o}`);this.progressMap.set(a,e.loaded);this.updateProgress()});a.addEventListener("load",()=>{if((""+a.status)[0]==="2"){console.log(`[下载视频] 视频片段${i(a)}下载完成`);t(a.response)}else{s(`视频片段${i(a)}请求失败, response = ${a.status}`)}});a.addEventListener("abort",()=>s("canceled"));a.addEventListener("error",()=>{console.error(`[下载视频] 视频片段${i(a)}下载失败: ${o}`);this.progressMap.set(a,0);this.updateProgress();a.open("GET",e.url);a.setRequestHeader("Range",o);a.send()});a.setRequestHeader("Range",o);this.progressMap.set(a,0);a.send();this.workingXhr.push(a)}));a=Math.round(a+s)+1}return Promise.all(t)}async copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM.setClipboard(e,"text")}async showUrl(){const e=this.fragments.map(e=>`\n${e.url}\n`).reduce((e,t)=>e+"\r\n"+t);Toast.success(e+`复制全部`,"显示链接");const t=await SpinQuery.select("#copy-link");t.addEventListener("click",async()=>{await this.copyUrl()})}static downloadBlob(e,t){const s=document.createElement("a");let a;if(typeof e==="string"){a=e}else{a=URL.createObjectURL(e)}s.setAttribute("href",a);s.setAttribute("download",t);document.body.appendChild(s);s.click();s.remove();URL.revokeObjectURL(a)}async exportData(e=false){const t=JSON.stringify([{fragments:this.fragments,title:s(),totalSize:this.fragments.map(e=>e.size).reduce((e,t)=>e+t),referer:document.URL.replace(window.location.search,"")}]);if(e){GM.setClipboard(t,"text")}else{const e=new Blob([t],{type:"text/json"});const a=await this.downloadDanmaku();if(a!==null){const t=new JSZip;t.file(`${s()}.json`,e);t.file(s()+"."+this.danmakuOption.toLowerCase(),a);h.downloadBlob(await t.generateAsync({type:"blob"}),`${s()}.zip`)}else{h.downloadBlob(e,`${s()}.json`)}}}async exportAria2(a=false){if(a){const a=await this.downloadDanmaku();if(a!==null){h.downloadBlob(new Blob([a]),`${s()}.${this.danmakuOption==="ASS"?"ass":"xml"}`)}const i=e.aria2RpcOption;const n=this.fragments.map((e,t)=>{let a="";if(this.fragments.length>1){a=" - "+(t+1)}const n=[];if(i.secretKey!==""){n.push(`token:${i.secretKey}`)}n.push([e.url]);n.push({referer:document.URL.replace(window.location.search,""),"user-agent":UserAgent,out:`${s()}${a}${this.extension(e)}`,split:this.fragmentSplitFactor,dir:i.baseDir+i.dir||undefined,"max-download-limit":i.maxDownloadLimit||undefined});const o=encodeURIComponent(`${s()}${a}`);return{params:n,id:o}});const{sendRpc:o}=await t.importAsync("aria2-rpc");await o(n)}else{const e=`\n# Generated by Bilibili Evolved Video Export\n# https://github.com/the1812/Bilibili-Evolved/\n${this.fragments.map((e,t)=>{let a="";if(this.fragments.length>1){a=" - "+(t+1)}return`\n${e.url}\n referer=${document.URL.replace(window.location.search,"")}\n user-agent=${UserAgent}\n out=${s()}${a}${this.extension(e)}\n split=${this.fragmentSplitFactor}\n`.trim()}).join("\n")}\n`.trim();const t=new Blob([e],{type:"text/plain"});const a=await this.downloadDanmaku();if(a!==null){const e=new JSZip;e.file(`${s()}.txt`,t);e.file(s()+"."+this.danmakuOption.toLowerCase(),a);h.downloadBlob(await e.generateAsync({type:"blob"}),`${s()}.zip`)}else{h.downloadBlob(t,`${s()}.txt`)}}}extension(e){const t=e||this.fragments[0];const s=[".flv",".mp4",".m4s"].find(e=>t.url.includes(e));if(s){return s}else{console.warn("No extension detected.");return".flv"}}makeBlob(e,t){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=dq("a#video-complete").getAttribute("href");if(e&&!dq(`.link[href="${e}"]`)){URL.revokeObjectURL(e)}dqa(".toast-card-header").filter(e=>e.innerText.includes("下载视频")).forEach(e=>e.querySelector(".toast-card-dismiss").click())}async downloadDanmaku(){if(this.danmakuOption!=="无"){const e=new i(r.cid);await e.fetchInfo();if(this.danmakuOption==="XML"){return e.rawXML}else{const{convertToAss:s}=await t.importAsync("download-danmaku");return s(e.rawXML)}}else{return null}}async downloadSingle(e){const t=await this.downloadDanmaku();const[a]=e;if(t===null){const e=this.makeBlob(a);const t=s()+this.extension();return{blob:e,filename:t}}else{const e=new JSZip;e.file(s()+this.extension(),this.makeBlob(a));e.file(s()+"."+this.danmakuOption.toLowerCase(),t);const i=await e.generateAsync({type:"blob"});const n=s()+".zip";return{blob:i,filename:n}}}async downloadMultiple(e){const t=new JSZip;const a=s();if(e.length>1){e.forEach((e,s)=>{const i=this.fragments[s];t.file(`${a} - ${s+1}${this.extension(i)}`,this.makeBlob(e,i))})}else{const[s]=e;t.file(`${a}${this.extension()}`,this.makeBlob(s))}const i=await this.downloadDanmaku();if(i!==null){t.file(s()+"."+this.danmakuOption.toLowerCase(),i)}const n=await t.generateAsync({type:"blob"});const o=a+".zip";return{blob:n,filename:o}}async download(){const e=[];this.videoSpeed.startMeasure();for(const t of this.fragments){const s=await this.downloadFragment(t);e.push(s)}if(e.length<1){throw new Error("下载失败.")}let{blob:t,filename:s}=await(async()=>{if(e.length===1){return await this.downloadSingle(e)}else{return await this.downloadMultiple(e)}})();this.cleanUpOldBlobUrl();const a=URL.createObjectURL(t);this.progress&&this.progress(0);this.videoSpeed.stopMeasure();return{url:a,filename:s}}}class u{constructor(e){this.lastProgress=0;this.measureInterval=1e3;this.workingDownloader=e}startMeasure(){this.intervalTimer=setInterval(()=>{const e=this.workingDownloader.progressMap?[...this.workingDownloader.progressMap.values()].reduce((e,t)=>e+t,0):0;const t=e-this.lastProgress;if(this.speedUpdate!==undefined){this.speedUpdate(formatFileSize(t)+"/s")}this.lastProgress=e},this.measureInterval)}stopMeasure(){clearInterval(this.intervalTimer)}}async function p(){const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);const t=await SpinQuery.select(()=>(unsafeWindow||window).cid);if(!(e&&t)){return false}r.aid=e;r.cid=t;if(document.URL.indexOf("bangumi")!==-1){r.entity=new o}else{r.entity=new n}try{l=await d.getAvailableFormats()}catch(e){return false}return true}async function f(){c=l[0];t.applyStyle("downloadVideoStyle");dq("#download-video").addEventListener("click",()=>{dq(".download-video").classList.toggle("opened");dq(".gui-settings-mask").click()});dq("#download-video").addEventListener("mouseover",()=>{document.body.insertAdjacentHTML("beforeend",t.import("downloadVideoHtml"));w()},{once:true})}async function w(){let n;const o=new Map;const u=new Vue({el:".download-video",components:{VDropdown:()=>t.importAsync("v-dropdown.vue"),VCheckbox:()=>t.importAsync("v-checkbox.vue"),RpcProfiles:()=>t.importAsync("aria2-rpc-profiles.vue")},data:{downloadSingle:true,coverUrl:EmptyImageUrl,aid:r.aid,cid:r.cid,dashModel:{value:e.downloadVideoFormat,items:["flv","dash"]},qualityModel:{value:c.displayName,items:l.map(e=>e.displayName)},danmakuModel:{value:e.downloadVideoDefaultDanmaku,items:["无","XML","ASS"]},progressPercent:0,size:"获取大小中",blobUrl:"",episodeList:[],downloading:false,speed:"",batch:false,rpcSettings:e.aria2RpcOption,showRpcSettings:false,busy:false,saveRpcSettingsText:"保存配置",enableDash:e.enableDashDownload},computed:{displaySize(){if(typeof this.size==="string"){return this.size}return formatFileSize(this.size)},sizeWarning(){if(typeof this.size==="string"){return false}return this.size>1073741824},selectedEpisodeCount(){return this.episodeList.filter(e=>e.checked).length},dash(){return this.dashModel.value==="dash"}},methods:{close(){this.$el.classList.remove("opened")},danmakuOptionChange(){e.downloadVideoDefaultDanmaku=this.danmakuModel.value},async dashChange(){const e=this.dashModel.value;let t=[];if(e==="flv"){t=await d.getAvailableFormats()}else{t=await d.getAvailableDashFormats()}l=t;[c]=e;this.qualityModel.items=t.map(e=>e.displayName);[this.qualityModel.value]=this.qualityModel.items},async formatChange(){const e=this.getFormat();const t=o.get(e);if(t){this.size=t;return}try{this.size="获取大小中";const t=await e.downloadInfo(this.dash);this.size=t.totalSize;o.set(e,this.size)}catch(e){this.size="获取大小失败"}},getFormat(){const e=l.find(e=>e.displayName===this.qualityModel.value);if(!e){console.error(`No format found. model value = ${this.qualityModel.value}`);return null}return e},async exportData(e){if(this.busy===true){return}try{this.busy=true;if(!this.downloadSingle){await this.exportBatchData(e);return}const t=this.getFormat();const s=await t.downloadInfo(this.dash);s.danmakuOption=this.danmakuModel.value;switch(e){case"copyLink":await s.copyUrl();Toast.success("已复制链接到剪贴板.","下载视频",3e3);break;case"showLink":await s.showUrl();break;case"aria2":await s.exportAria2(false);break;case"aria2RPC":await s.exportAria2(true);break;case"copyVLD":await s.exportData(true);Toast.success("已复制VLD数据到剪贴板.","下载视频",3e3);break;case"exportVLD":await s.exportData(false);break;default:break}}catch(e){logError(e)}finally{this.busy=false}},async exportBatchData(e){const a=this.episodeList;if(a.every(e=>e.checked===false)){Toast.info("请至少选择1集或以上的数量!","批量导出",3e3);return}const n=e=>{const t=a.find(t=>t.cid===e.cid);if(t===undefined){return false}return t.checked};const o=this.getFormat();if(this.danmakuModel.value!=="无"){const e=Toast.info("下载弹幕中...","批量导出");const s=new JSZip;try{if(this.danmakuModel.value==="XML"){for(const e of a.filter(n)){const t=new i(e.cid);await t.fetchInfo();s.file(e.title+".xml",t.rawXML)}}else{const{convertToAss:e}=await t.importAsync("download-danmaku");for(const t of a.filter(n)){const a=new i(t.cid);await a.fetchInfo();s.file(t.title+".ass",await e(a.rawXML))}}h.downloadBlob(await s.generateAsync({type:"blob"}),this.cid+".danmakus.zip")}catch(e){logError(`弹幕下载失败`)}finally{e.dismiss()}}const r=Toast.info("获取链接中...","批量导出");this.batchExtractor.itemFilter=n;let l;try{switch(e){case"aria2":l=await this.batchExtractor.collectAria2(o,r);h.downloadBlob(new Blob([l],{type:"text/plain"}),s(false)+".txt");return;case"aria2RPC":await this.batchExtractor.collectAria2(o,r,true);Toast.success(`成功发送了批量请求.`,"aria2 RPC",3e3);return;case"copyVLD":GM.setClipboard(await this.batchExtractor.collectData(o,r),{mimetype:"text/plain"});Toast.success("已复制批量vld数据到剪贴板.","批量导出",3e3);return;case"exportVLD":l=await this.batchExtractor.collectData(o,r);h.downloadBlob(new Blob([l],{type:"text/json"}),s(false)+".json");return;default:return}}catch(e){logError(e)}finally{r.dismiss()}},async checkBatch(){const e=["/www.bilibili.com/bangumi","/www.bilibili.com/video/av"];if(!e.some(e=>document.URL.includes(e))){this.batch=false;this.episodeList=[];return}const{BatchExtractor:s}=await t.importAsync("batch-download");if(await s.test()!==true){this.batch=false;this.episodeList=[];return}this.batchExtractor=new s;this.batch=true;this.episodeList=(await this.batchExtractor.getItemList()).map((e,t)=>{return{aid:e.aid,cid:e.cid,title:e.title,index:t,checked:true}})},cancelDownload(){if(n){n.cancelDownload()}},async startDownload(){const e=this.getFormat();try{this.downloading=true;const t=await e.downloadInfo(this.dash);t.videoSpeed.speedUpdate=(e=>this.speed=e);t.danmakuOption=this.danmakuModel.value;t.progress=(e=>{this.progressPercent=Math.trunc(e*100)});n=t;const s=await t.download();const a=document.getElementById("video-complete");a.setAttribute("href",s.url);a.setAttribute("download",s.filename);a.click();Toast.success(`下载完成: ${s.filename} 再次保存`,"下载视频")}catch(e){if(e!=="canceled"){logError(e)}this.progressPercent=0}finally{this.downloading=false;this.speed=""}},selectAllEpisodes(){this.episodeList.forEach(e=>e.checked=true)},unselectAllEpisodes(){this.episodeList.forEach(e=>e.checked=false)},inverseAllEpisodes(){this.episodeList.forEach(e=>e.checked=!e.checked)},toggleRpcSettings(){this.showRpcSettings=!this.showRpcSettings},saveRpcSettings(){if(this.rpcSettings.host===""){this.rpcSettings.host="127.0.0.1"}if(this.rpcSettings.port===""){this.rpcSettings.port="6800"}e.aria2RpcOption=this.rpcSettings;const t=e.aria2RpcOptionProfiles.find(t=>t.name===e.aria2RpcOptionSelectedProfile);if(t){Object.assign(t,this.rpcSettings);e.aria2RpcOptionProfiles=e.aria2RpcOptionProfiles}this.saveRpcSettingsText="已保存";setTimeout(()=>this.saveRpcSettingsText="保存配置",2e3)},updateProfile(t){e.aria2RpcOption=this.rpcSettings=_.omit(t,"name")}}});Observer.videoChange(async()=>{u.close();u.batch=false;u.downloadSingle=true;const e=dq("#download-video");const t=await p();e.style.display=t?"flex":"none";if(!t){return}u.aid=r.aid;u.cid=r.cid;const s=new a(r.aid);await s.fetchInfo();u.coverUrl=s.coverUrl.replace("http:","https:");l=await d.getAvailableFormats();[c]=l;u.qualityModel={value:c.displayName,items:l.map(e=>e.displayName)};u.formatChange();await u.checkBatch()})}return{widget:{content:`\n`,condition:p,success:f}}}})(); -offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/dpi-img.vue.min.js"] = (()=>{return(t,e)=>{const i=``;return{export:Object.assign({template:i},{props:["size","src","blur"],computed:{srcset(){if(!this.src||!this.size){return null}return getDpiSourceSet(this.src,this.size)},width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); +offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/dpi-img.vue.min.js"] = (()=>{return(t,s)=>{const e=``;return{export:Object.assign({template:e},{props:["size","src","blur","root","rootMargin","threshold"],data(){return{srcset:null,actualSrc:null}},methods:{calcSrc(){if(!this.src||!this.size){return null}const t=this.src.substring(this.src.lastIndexOf(".")+1);this.srcset=getDpiSourceSet(this.src,this.size,t);this.actualSrc=this.src}},mounted(){const t={root:this.root,rootMargin:this.rootMargin||"200px",threshold:this.threshold};console.log(t);const s=new IntersectionObserver(t=>{t.forEach(t=>{if(t.isIntersecting){this.calcSrc();s.disconnect()}})},t);s.observe(this.$el)},computed:{width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/expand-danmaku.min.js"] = (()=>{return(e,a)=>{if(typeof isEmbeddedPlayer!=="undefined"&&isEmbeddedPlayer()){return}Observer.videoChange(async()=>{const e=await SpinQuery.select(".bui-collapse-wrap");if(e&&e.classList.contains("bui-collapse-wrap-folded")){const e=await SpinQuery.select(".bui-collapse-header");e.click()}})}})(); offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/expand-description.min.css"] = `.play-up-info .play-up-self,.video-desc .info{height:auto!important}.play-up-info .play-up-self-btn,.video-desc .btn{display:none!important}`; offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/expand-description.min.js"] = (()=>{return(e,p)=>{p.applyStyle("expandDescriptionStyle")}})(); diff --git a/bilibili-evolved.preview-offline.user.js b/bilibili-evolved.preview-offline.user.js index 65a8a7910..3a2a35cd9 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 466.19 +// @version 466.80 // @description Bilibili Evolved 的预览离线版, 可以抢先体验新功能, 并且所有功能都已内置于脚本中. // @author Grant Howard, Coulomb-G // @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G) @@ -1084,7 +1084,7 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.css"] = `.download-video{--download-video-background:white;--download-video-foreground:black;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) scale(.95);background:var(--download-video-background);color:var(--download-video-foreground);box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;z-index:10001;pointer-events:none;opacity:0;padding:16px;width:300px;display:flex;flex-direction:column;align-items:stretch;justify-content:space-between;max-height:90%}.download-video,.download-video *{transition:.2s ease-out;-webkit-tap-highlight-color:transparent!important}.download-video.opened{pointer-events:initial;opacity:1;transform:translate(-50%,-50%) scale(1)}body.dark .download-video{--download-video-background:#222;--download-video-foreground:#eee}.round-corner .download-video,.round-corner .download-video .episode-list .v-checkbox,.round-corner .download-video .rpc-settings{border-radius:var(--large-corner-radius)}.round-corner .download-video .button,.round-corner .download-video .cover,.round-corner .download-video .direct-download .progress .background,.round-corner .download-video .direct-download .progress .foreground,.round-corner .download-video .rpc-settings input[type=text],.round-corner .download-video .title,.round-corner .download-video button{border-radius:var(--corner-radius)}.download-video .cover{width:240px;min-height:135px;background-color:#8882}.download-video .header{display:flex;justify-content:space-between;align-items:center}.download-video h1{font-size:16pt;font-weight:700;color:var(--download-video-foreground)}.download-video .header .mdi-close{font-size:16pt;color:var(--download-video-foreground);cursor:pointer}.download-video .header .mdi-close:hover{color:var(--theme-color)}.download-video .info{display:flex;flex-direction:column;align-items:center;margin-top:12px}.download-video .title{display:flex;flex-direction:column;justify-content:space-between;align-items:stretch;margin-top:12px}.download-video .title .bold{width:300px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:center}.download-video .title .size{font-size:10pt;color:var(--download-video-foreground);align-self:center;display:flex;align-items:center;height:24px}.download-video .bold{color:var(--download-video-foreground);font-weight:700;font-size:12pt}.download-video .option-item{display:flex;justify-content:space-between;align-items:center;padding-top:12px;font-size:10pt}.download-video .tabs{display:flex;padding-top:12px;font-size:10pt}.download-video .tabs .tab{padding:6px 12px;border-bottom:2px solid transparent;cursor:pointer}.download-video .tabs .tab.active{color:var(--theme-color);border-bottom-color:var(--theme-color)}.download-video .separator{height:1px;background:#8884;width:100%;margin:12px 0;flex-shrink:0}.download-video h2{font-size:12pt;font-weight:700;color:var(--download-video-foreground)}.download-video .direct-download{display:flex;flex-direction:column;align-items:start;justify-content:space-between}.download-video .button,.download-video button{border:none;outline:0!important;padding:6px 16px;font-size:10pt;cursor:pointer;background:#8884;color:var(--download-video-foreground)}.download-video .button:hover,.download-video button:hover{background:#8886}.download-video .primary{background:var(--theme-color);color:var(--foreground-color);align-self:center}.download-video .primary:hover{background:var(--theme-color-90)}.download-video .busy .button,.download-video .busy .primary,.download-video .busy button,.download-video button:disabled{background-color:#0001;color:#8884;cursor:not-allowed}.download-video .busy .button,.download-video .busy button{cursor:wait!important}.download-video .direct-download .progress{align-self:stretch;display:flex;align-items:center;margin-top:8px}.download-video .direct-download .progress .background{flex-grow:1;height:4px;background:#8884;margin-right:4px;position:relative}.download-video .direct-download .progress .background .foreground{position:absolute;top:0;left:0;height:4px;background:linear-gradient(to right,var(--theme-color),var(--theme-color-60))}.download-video .direct-download .progress .percent{width:50px;text-align:right}.download-video .actions{display:flex;flex-wrap:wrap;justify-content:space-between;margin:8px -4px 0}.download-video .actions>*{margin:4px;flex-grow:1;flex-basis:calc(50% - 16px);display:flex;justify-content:center;align-items:center}.download-video i.mdi-alert-circle{font-size:14pt;color:#ff9800}.download-video .size-warning{position:relative;padding:0 8px}.download-video .size-warning-tip{position:absolute;bottom:100%;left:50%;transform:translateX(-50%);background:var(--download-video-background);color:var(--download-video-foreground);border:1px dashed var(--theme-color);z-index:2;font-size:10pt;width:200px;padding:8px;box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;pointer-events:none;opacity:0}.download-video .size-warning:hover .size-warning-tip{opacity:1}.download-video .episode-list .v-checkbox{padding:4px 8px;margin:4px 0;position:relative;background-color:transparent}.download-video .episode-list .v-checkbox.checked{background-color:#8882}.download-video .episode-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}.download-video .episode-list{overflow:auto;max-height:320px}.download-video button.list-tool{padding:4px;line-height:1;font-size:12pt;margin:0 4px}.download-video .episode-header h2{flex-grow:1}.download-video .selected-count{width:64px;text-align:right}.download-video .aria2-rpc .mdi{margin-left:8px;font-size:14pt;line-height:1}.download-video .aria2-rpc{position:relative}.download-video .rpc-settings{position:absolute;display:flex;flex-direction:column;align-items:stretch;color:var(--download-video-foreground);background:#fff;bottom:120%;left:50%;cursor:initial;box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;transform-origin:bottom;transform:translateX(-50%) scale(.9);opacity:0;pointer-events:none;padding:8px;z-index:3;transition:.3s cubic-bezier(.18,.89,.32,1.28);width:120%}body.dark .download-video .rpc-settings{background:#282828}.download-video .rpc-settings>*{margin:8px}.download-video .rpc-settings.show{opacity:1;transform:translateX(-50%) scale(1);pointer-events:initial}.download-video .rpc-settings input[type=text]{background:0 0;color:var(--download-video-foreground);border:1px solid #8884;padding:4px;margin-left:8px}.download-video .rpc-settings input[type=text]:focus{border-color:var(--theme-color)}.download-video .rpc-settings .operations{display:flex;align-items:center;justify-content:space-evenly}.download-video .final-dir{word-break:break-all}.download-video .rpc-settings-item{display:flex;align-items:center;justify-content:space-between;white-space:nowrap}.download-video .rpc-settings-item input[type=text]{flex-grow:1;margin-left:24px}.download-video button.cancel-download,.download-video button.start-download{margin-top:8px}.download-video .direct-download-header{align-self:stretch;display:flex;justify-content:space-between;align-items:center}body.dark .download-video .direct-download .progress .foreground{background:linear-gradient(to right,var(--theme-color-70),var(--theme-color))}`; offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.html"] = `

下载视频

单个视频
批量导出
警告: 过大的视频大小会在直接下载时占用大量内存, 并可能导致浏览器标签页崩溃. 请考虑降低清晰度或使用导出选项.
预计大小: {{displaySize}}
格式
清晰度
弹幕

直接下载

{{speed}}
{{progressPercent}}%

选集

{{selectedEpisodeCount}}/{{episodeList.length}}

导出

{{showRpcSettings ? '取消' : 'aria2 RPC'}}

aria2 RPC

配置

主机
端口
密钥
限速
默认路径
路径
最终路径: {{rpcSettings.baseDir + rpcSettings.dir}}
方法
开始下载
{{saveRpcSettingsText}}
`; offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.js"] = (()=>{return(e,t)=>{const{getFriendlyTitle:s}=t.import("title");const{VideoInfo:a,DanmakuInfo:i}=t.import("video-info");class n{constructor(){this.menuClasses=["quality","action","progress"];[this.currentMenuClass]=this.menuClasses}get menuPanel(){return document.querySelector(".download-video-panel")}addMenuClass(){this.menuPanel.classList.remove(...this.menuClasses);this.menuPanel.classList.add(this.currentMenuClass);return this.currentMenuClass}resetMenuClass(){[this.currentMenuClass]=this.menuClasses;this.addMenuClass()}nextMenuClass(){const e=this.menuClasses.indexOf(this.currentMenuClass)+1;const t=this.menuClasses[e>=this.menuClasses.length?0:e];this.currentMenuClass=t;this.addMenuClass();return t}closeMenu(){this.menuPanel.classList.remove("opened");setTimeout(()=>this.resetMenuClass(),200)}addError(){this.menuPanel.classList.add("error")}removeError(){this.menuPanel.classList.remove("error");this.resetMenuClass()}async getDashUrl(e){throw new Error("video dash is not supported")}async getUrl(e){if(e){return`https://api.bilibili.com/x/player/playurl?avid=${r.aid}&cid=${r.cid}&qn=${e}&otype=json`}else{return`https://api.bilibili.com/x/player/playurl?avid=${r.aid}&cid=${r.cid}&otype=json`}}}class o extends n{async getDashUrl(e){if(e){return`https://api.bilibili.com/pgc/player/web/playurl?avid=56995872&cid=99547543&qn=${e}&otype=json&fourk=1&fnval=16`}else{return`https://api.bilibili.com/pgc/player/web/playurl?avid=56995872&cid=99547543&otype=json&fourk=1&fnval=16`}}async getUrl(e){if(e){return`https://api.bilibili.com/pgc/player/web/playurl?avid=${r.aid}&cid=${r.cid}&qn=${e}&otype=json`}else{return`https://api.bilibili.com/pgc/player/web/playurl?avid=${r.aid}&cid=${r.cid}&qn=&otype=json`}}}const r={entity:new n,aid:"",cid:""};let l=[];let c=null;class d{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async downloadInfo(e=false){const t=new h(this);await t.fetchVideoInfo(e);return t}static parseFormats(e){const t=e.accept_quality;const s=e.accept_format.split(",");const a=e.accept_description;const i=t.map((e,t)=>{return new d(e,s[t],a[t])});return i}static async getAvailableDashFormats(){const e=await r.entity.getDashUrl();const t=await Ajax.getJsonWithCredentials(e);if(t.code!==0){throw new Error("获取清晰度信息失败.")}return d.parseFormats(t.result)}static async getAvailableFormats(){const e=await r.entity.getUrl();const t=await Ajax.getJsonWithCredentials(e);if(t.code!==0){throw new Error("获取清晰度信息失败.")}const s=t.data||t.result||t;return d.parseFormats(s)}}class h{constructor(e,t){this.fragmentSplitFactor=6*2;this.workingXhr=null;this.progressMap=new Map;this.format=e;this.fragments=t||[];this.videoSpeed=new u(this)}get totalSize(){return this.fragments.map(e=>e.size).reduce((e,t)=>e+t)}async fetchVideoInfo(e=false){if(!e){const e=await r.entity.getUrl(this.format.quality);const t=await Ajax.getTextWithCredentials(e);const s=JSON.parse(t.replace(/http:/g,"https:"));const a=s.data||s.result||s;if(a.quality!==this.format.quality){throw new Error("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const i=a.durl;this.fragments=i.map(e=>{return{length:e.length,size:e.size,url:e.url,backupUrls:e.backup_url}})}else{const{dashToFragment:e,getDashInfo:s}=await t.importAsync("video-dash");const a=await s(r.aid,r.cid,this.format.quality);const i=a.videoDashes.sort(descendingSort(e=>e.bandWidth))[0];const n=a.audioDashes.sort(descendingSort(e=>e.bandWidth))[0];this.fragments=[e(i),e(n)]}return this.fragments}updateProgress(){const e=this.progressMap?[...this.progressMap.values()].reduce((e,t)=>e+t,0)/this.totalSize:0;if(e>1||e<0){console.error(`[下载视频] 进度异常: ${e}`,this.progressMap.values())}this.progress&&this.progress(e)}cancelDownload(){this.videoSpeed.stopMeasure();if(this.workingXhr!==null){this.workingXhr.forEach(e=>e.abort())}else{logError("Cancel Download Failed: forEach in this.workingXhr not found.")}}downloadFragment(e){const t=[];this.workingXhr=[];this.progressMap=new Map;this.updateProgress();let s;if(e.size<=96*1024*1024){s=e.size/this.fragmentSplitFactor}else{s=16*1024*1024}let a=0;const i=e=>[...this.progressMap.keys()].indexOf(e)+1;while(a{const a=new XMLHttpRequest;a.open("GET",e.url);a.responseType="arraybuffer";a.withCredentials=false;a.addEventListener("progress",e=>{console.log(`[下载视频] 视频片段${i(a)}下载进度: ${e.loaded}/${r} bytes loaded, ${o}`);this.progressMap.set(a,e.loaded);this.updateProgress()});a.addEventListener("load",()=>{if((""+a.status)[0]==="2"){console.log(`[下载视频] 视频片段${i(a)}下载完成`);t(a.response)}else{s(`视频片段${i(a)}请求失败, response = ${a.status}`)}});a.addEventListener("abort",()=>s("canceled"));a.addEventListener("error",()=>{console.error(`[下载视频] 视频片段${i(a)}下载失败: ${o}`);this.progressMap.set(a,0);this.updateProgress();a.open("GET",e.url);a.setRequestHeader("Range",o);a.send()});a.setRequestHeader("Range",o);this.progressMap.set(a,0);a.send();this.workingXhr.push(a)}));a=Math.round(a+s)+1}return Promise.all(t)}async copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM.setClipboard(e,"text")}async showUrl(){const e=this.fragments.map(e=>`\n${e.url}\n`).reduce((e,t)=>e+"\r\n"+t);Toast.success(e+`复制全部`,"显示链接");const t=await SpinQuery.select("#copy-link");t.addEventListener("click",async()=>{await this.copyUrl()})}static downloadBlob(e,t){const s=document.createElement("a");let a;if(typeof e==="string"){a=e}else{a=URL.createObjectURL(e)}s.setAttribute("href",a);s.setAttribute("download",t);document.body.appendChild(s);s.click();s.remove();URL.revokeObjectURL(a)}async exportData(e=false){const t=JSON.stringify([{fragments:this.fragments,title:s(),totalSize:this.fragments.map(e=>e.size).reduce((e,t)=>e+t),referer:document.URL.replace(window.location.search,"")}]);if(e){GM.setClipboard(t,"text")}else{const e=new Blob([t],{type:"text/json"});const a=await this.downloadDanmaku();if(a!==null){const t=new JSZip;t.file(`${s()}.json`,e);t.file(s()+"."+this.danmakuOption.toLowerCase(),a);h.downloadBlob(await t.generateAsync({type:"blob"}),`${s()}.zip`)}else{h.downloadBlob(e,`${s()}.json`)}}}async exportAria2(a=false){if(a){const a=await this.downloadDanmaku();if(a!==null){h.downloadBlob(new Blob([a]),`${s()}.${this.danmakuOption==="ASS"?"ass":"xml"}`)}const i=e.aria2RpcOption;const n=this.fragments.map((e,t)=>{let a="";if(this.fragments.length>1){a=" - "+(t+1)}const n=[];if(i.secretKey!==""){n.push(`token:${i.secretKey}`)}n.push([e.url]);n.push({referer:document.URL.replace(window.location.search,""),"user-agent":UserAgent,out:`${s()}${a}${this.extension(e)}`,split:this.fragmentSplitFactor,dir:i.baseDir+i.dir||undefined,"max-download-limit":i.maxDownloadLimit||undefined});const o=encodeURIComponent(`${s()}${a}`);return{params:n,id:o}});const{sendRpc:o}=await t.importAsync("aria2-rpc");await o(n)}else{const e=`\n# Generated by Bilibili Evolved Video Export\n# https://github.com/the1812/Bilibili-Evolved/\n${this.fragments.map((e,t)=>{let a="";if(this.fragments.length>1){a=" - "+(t+1)}return`\n${e.url}\n referer=${document.URL.replace(window.location.search,"")}\n user-agent=${UserAgent}\n out=${s()}${a}${this.extension(e)}\n split=${this.fragmentSplitFactor}\n`.trim()}).join("\n")}\n`.trim();const t=new Blob([e],{type:"text/plain"});const a=await this.downloadDanmaku();if(a!==null){const e=new JSZip;e.file(`${s()}.txt`,t);e.file(s()+"."+this.danmakuOption.toLowerCase(),a);h.downloadBlob(await e.generateAsync({type:"blob"}),`${s()}.zip`)}else{h.downloadBlob(t,`${s()}.txt`)}}}extension(e){const t=e||this.fragments[0];const s=[".flv",".mp4",".m4s"].find(e=>t.url.includes(e));if(s){return s}else{console.warn("No extension detected.");return".flv"}}makeBlob(e,t){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=dq("a#video-complete").getAttribute("href");if(e&&!dq(`.link[href="${e}"]`)){URL.revokeObjectURL(e)}dqa(".toast-card-header").filter(e=>e.innerText.includes("下载视频")).forEach(e=>e.querySelector(".toast-card-dismiss").click())}async downloadDanmaku(){if(this.danmakuOption!=="无"){const e=new i(r.cid);await e.fetchInfo();if(this.danmakuOption==="XML"){return e.rawXML}else{const{convertToAss:s}=await t.importAsync("download-danmaku");return s(e.rawXML)}}else{return null}}async downloadSingle(e){const t=await this.downloadDanmaku();const[a]=e;if(t===null){const e=this.makeBlob(a);const t=s()+this.extension();return{blob:e,filename:t}}else{const e=new JSZip;e.file(s()+this.extension(),this.makeBlob(a));e.file(s()+"."+this.danmakuOption.toLowerCase(),t);const i=await e.generateAsync({type:"blob"});const n=s()+".zip";return{blob:i,filename:n}}}async downloadMultiple(e){const t=new JSZip;const a=s();if(e.length>1){e.forEach((e,s)=>{const i=this.fragments[s];t.file(`${a} - ${s+1}${this.extension(i)}`,this.makeBlob(e,i))})}else{const[s]=e;t.file(`${a}${this.extension()}`,this.makeBlob(s))}const i=await this.downloadDanmaku();if(i!==null){t.file(s()+"."+this.danmakuOption.toLowerCase(),i)}const n=await t.generateAsync({type:"blob"});const o=a+".zip";return{blob:n,filename:o}}async download(){const e=[];this.videoSpeed.startMeasure();for(const t of this.fragments){const s=await this.downloadFragment(t);e.push(s)}if(e.length<1){throw new Error("下载失败.")}let{blob:t,filename:s}=await(async()=>{if(e.length===1){return await this.downloadSingle(e)}else{return await this.downloadMultiple(e)}})();this.cleanUpOldBlobUrl();const a=URL.createObjectURL(t);this.progress&&this.progress(0);this.videoSpeed.stopMeasure();return{url:a,filename:s}}}class u{constructor(e){this.lastProgress=0;this.measureInterval=1e3;this.workingDownloader=e}startMeasure(){this.intervalTimer=setInterval(()=>{const e=this.workingDownloader.progressMap?[...this.workingDownloader.progressMap.values()].reduce((e,t)=>e+t,0):0;const t=e-this.lastProgress;if(this.speedUpdate!==undefined){this.speedUpdate(formatFileSize(t)+"/s")}this.lastProgress=e},this.measureInterval)}stopMeasure(){clearInterval(this.intervalTimer)}}async function p(){const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);const t=await SpinQuery.select(()=>(unsafeWindow||window).cid);if(!(e&&t)){return false}r.aid=e;r.cid=t;if(document.URL.indexOf("bangumi")!==-1){r.entity=new o}else{r.entity=new n}try{l=await d.getAvailableFormats()}catch(e){return false}return true}async function f(){c=l[0];t.applyStyle("downloadVideoStyle");dq("#download-video").addEventListener("click",()=>{dq(".download-video").classList.toggle("opened");dq(".gui-settings-mask").click()});dq("#download-video").addEventListener("mouseover",()=>{document.body.insertAdjacentHTML("beforeend",t.import("downloadVideoHtml"));w()},{once:true})}async function w(){let n;const o=new Map;const u=new Vue({el:".download-video",components:{VDropdown:()=>t.importAsync("v-dropdown.vue"),VCheckbox:()=>t.importAsync("v-checkbox.vue"),RpcProfiles:()=>t.importAsync("aria2-rpc-profiles.vue")},data:{downloadSingle:true,coverUrl:EmptyImageUrl,aid:r.aid,cid:r.cid,dashModel:{value:e.downloadVideoFormat,items:["flv","dash"]},qualityModel:{value:c.displayName,items:l.map(e=>e.displayName)},danmakuModel:{value:e.downloadVideoDefaultDanmaku,items:["无","XML","ASS"]},progressPercent:0,size:"获取大小中",blobUrl:"",episodeList:[],downloading:false,speed:"",batch:false,rpcSettings:e.aria2RpcOption,showRpcSettings:false,busy:false,saveRpcSettingsText:"保存配置",enableDash:e.enableDashDownload},computed:{displaySize(){if(typeof this.size==="string"){return this.size}return formatFileSize(this.size)},sizeWarning(){if(typeof this.size==="string"){return false}return this.size>1073741824},selectedEpisodeCount(){return this.episodeList.filter(e=>e.checked).length},dash(){return this.dashModel.value==="dash"}},methods:{close(){this.$el.classList.remove("opened")},danmakuOptionChange(){e.downloadVideoDefaultDanmaku=this.danmakuModel.value},async dashChange(){const e=this.dashModel.value;let t=[];if(e==="flv"){t=await d.getAvailableFormats()}else{t=await d.getAvailableDashFormats()}l=t;[c]=e;this.qualityModel.items=t.map(e=>e.displayName);[this.qualityModel.value]=this.qualityModel.items},async formatChange(){const e=this.getFormat();const t=o.get(e);if(t){this.size=t;return}try{this.size="获取大小中";const t=await e.downloadInfo(this.dash);this.size=t.totalSize;o.set(e,this.size)}catch(e){this.size="获取大小失败"}},getFormat(){const e=l.find(e=>e.displayName===this.qualityModel.value);if(!e){console.error(`No format found. model value = ${this.qualityModel.value}`);return null}return e},async exportData(e){if(this.busy===true){return}try{this.busy=true;if(!this.downloadSingle){await this.exportBatchData(e);return}const t=this.getFormat();const s=await t.downloadInfo(this.dash);s.danmakuOption=this.danmakuModel.value;switch(e){case"copyLink":await s.copyUrl();Toast.success("已复制链接到剪贴板.","下载视频",3e3);break;case"showLink":await s.showUrl();break;case"aria2":await s.exportAria2(false);break;case"aria2RPC":await s.exportAria2(true);break;case"copyVLD":await s.exportData(true);Toast.success("已复制VLD数据到剪贴板.","下载视频",3e3);break;case"exportVLD":await s.exportData(false);break;default:break}}catch(e){logError(e)}finally{this.busy=false}},async exportBatchData(e){const a=this.episodeList;if(a.every(e=>e.checked===false)){Toast.info("请至少选择1集或以上的数量!","批量导出",3e3);return}const n=e=>{const t=a.find(t=>t.cid===e.cid);if(t===undefined){return false}return t.checked};const o=this.getFormat();if(this.danmakuModel.value!=="无"){const e=Toast.info("下载弹幕中...","批量导出");const s=new JSZip;try{if(this.danmakuModel.value==="XML"){for(const e of a.filter(n)){const t=new i(e.cid);await t.fetchInfo();s.file(e.title+".xml",t.rawXML)}}else{const{convertToAss:e}=await t.importAsync("download-danmaku");for(const t of a.filter(n)){const a=new i(t.cid);await a.fetchInfo();s.file(t.title+".ass",await e(a.rawXML))}}h.downloadBlob(await s.generateAsync({type:"blob"}),this.cid+".danmakus.zip")}catch(e){logError(`弹幕下载失败`)}finally{e.dismiss()}}const r=Toast.info("获取链接中...","批量导出");this.batchExtractor.itemFilter=n;let l;try{switch(e){case"aria2":l=await this.batchExtractor.collectAria2(o,r);h.downloadBlob(new Blob([l],{type:"text/plain"}),s(false)+".txt");return;case"aria2RPC":await this.batchExtractor.collectAria2(o,r,true);Toast.success(`成功发送了批量请求.`,"aria2 RPC",3e3);return;case"copyVLD":GM.setClipboard(await this.batchExtractor.collectData(o,r),{mimetype:"text/plain"});Toast.success("已复制批量vld数据到剪贴板.","批量导出",3e3);return;case"exportVLD":l=await this.batchExtractor.collectData(o,r);h.downloadBlob(new Blob([l],{type:"text/json"}),s(false)+".json");return;default:return}}catch(e){logError(e)}finally{r.dismiss()}},async checkBatch(){const e=["/www.bilibili.com/bangumi","/www.bilibili.com/video/av"];if(!e.some(e=>document.URL.includes(e))){this.batch=false;this.episodeList=[];return}const{BatchExtractor:s}=await t.importAsync("batch-download");if(await s.test()!==true){this.batch=false;this.episodeList=[];return}this.batchExtractor=new s;this.batch=true;this.episodeList=(await this.batchExtractor.getItemList()).map((e,t)=>{return{aid:e.aid,cid:e.cid,title:e.title,index:t,checked:true}})},cancelDownload(){if(n){n.cancelDownload()}},async startDownload(){const e=this.getFormat();try{this.downloading=true;const t=await e.downloadInfo(this.dash);t.videoSpeed.speedUpdate=(e=>this.speed=e);t.danmakuOption=this.danmakuModel.value;t.progress=(e=>{this.progressPercent=Math.trunc(e*100)});n=t;const s=await t.download();const a=document.getElementById("video-complete");a.setAttribute("href",s.url);a.setAttribute("download",s.filename);a.click();Toast.success(`下载完成: ${s.filename} 再次保存`,"下载视频")}catch(e){if(e!=="canceled"){logError(e)}this.progressPercent=0}finally{this.downloading=false;this.speed=""}},selectAllEpisodes(){this.episodeList.forEach(e=>e.checked=true)},unselectAllEpisodes(){this.episodeList.forEach(e=>e.checked=false)},inverseAllEpisodes(){this.episodeList.forEach(e=>e.checked=!e.checked)},toggleRpcSettings(){this.showRpcSettings=!this.showRpcSettings},saveRpcSettings(){if(this.rpcSettings.host===""){this.rpcSettings.host="127.0.0.1"}if(this.rpcSettings.port===""){this.rpcSettings.port="6800"}e.aria2RpcOption=this.rpcSettings;const t=e.aria2RpcOptionProfiles.find(t=>t.name===e.aria2RpcOptionSelectedProfile);if(t){Object.assign(t,this.rpcSettings);e.aria2RpcOptionProfiles=e.aria2RpcOptionProfiles}this.saveRpcSettingsText="已保存";setTimeout(()=>this.saveRpcSettingsText="保存配置",2e3)},updateProfile(t){e.aria2RpcOption=this.rpcSettings=_.omit(t,"name")}}});Observer.videoChange(async()=>{u.close();u.batch=false;u.downloadSingle=true;const e=dq("#download-video");const t=await p();e.style.display=t?"flex":"none";if(!t){return}u.aid=r.aid;u.cid=r.cid;const s=new a(r.aid);await s.fetchInfo();u.coverUrl=s.coverUrl.replace("http:","https:");l=await d.getAvailableFormats();[c]=l;u.qualityModel={value:c.displayName,items:l.map(e=>e.displayName)};u.formatChange();await u.checkBatch()})}return{widget:{content:`\n`,condition:p,success:f}}}})(); -offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/dpi-img.vue.min.js"] = (()=>{return(t,e)=>{const i=``;return{export:Object.assign({template:i},{props:["size","src","blur"],computed:{srcset(){if(!this.src||!this.size){return null}return getDpiSourceSet(this.src,this.size)},width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); +offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/dpi-img.vue.min.js"] = (()=>{return(t,s)=>{const e=``;return{export:Object.assign({template:e},{props:["size","src","blur","root","rootMargin","threshold"],data(){return{srcset:null,actualSrc:null}},methods:{calcSrc(){if(!this.src||!this.size){return null}const t=this.src.substring(this.src.lastIndexOf(".")+1);this.srcset=getDpiSourceSet(this.src,this.size,t);this.actualSrc=this.src}},mounted(){const t={root:this.root,rootMargin:this.rootMargin||"200px",threshold:this.threshold};console.log(t);const s=new IntersectionObserver(t=>{t.forEach(t=>{if(t.isIntersecting){this.calcSrc();s.disconnect()}})},t);s.observe(this.$el)},computed:{width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/expand-danmaku.min.js"] = (()=>{return(e,a)=>{if(typeof isEmbeddedPlayer!=="undefined"&&isEmbeddedPlayer()){return}Observer.videoChange(async()=>{const e=await SpinQuery.select(".bui-collapse-wrap");if(e&&e.classList.contains("bui-collapse-wrap-folded")){const e=await SpinQuery.select(".bui-collapse-header");e.click()}})}})(); offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/expand-description.min.css"] = `.play-up-info .play-up-self,.video-desc .info{height:auto!important}.play-up-info .play-up-self-btn,.video-desc .btn{display:none!important}`; offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/expand-description.min.js"] = (()=>{return(e,p)=>{p.applyStyle("expandDescriptionStyle")}})(); diff --git a/bilibili-evolved.preview.user.js b/bilibili-evolved.preview.user.js index f2a4b791c..4b1550c64 100644 --- a/bilibili-evolved.preview.user.js +++ b/bilibili-evolved.preview.user.js @@ -1083,7 +1083,7 @@ onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/preview/m onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/preview/min/download-video.min.css"] = `.download-video{--download-video-background:white;--download-video-foreground:black;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) scale(.95);background:var(--download-video-background);color:var(--download-video-foreground);box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;z-index:10001;pointer-events:none;opacity:0;padding:16px;width:300px;display:flex;flex-direction:column;align-items:stretch;justify-content:space-between;max-height:90%}.download-video,.download-video *{transition:.2s ease-out;-webkit-tap-highlight-color:transparent!important}.download-video.opened{pointer-events:initial;opacity:1;transform:translate(-50%,-50%) scale(1)}body.dark .download-video{--download-video-background:#222;--download-video-foreground:#eee}.round-corner .download-video,.round-corner .download-video .episode-list .v-checkbox,.round-corner .download-video .rpc-settings{border-radius:var(--large-corner-radius)}.round-corner .download-video .button,.round-corner .download-video .cover,.round-corner .download-video .direct-download .progress .background,.round-corner .download-video .direct-download .progress .foreground,.round-corner .download-video .rpc-settings input[type=text],.round-corner .download-video .title,.round-corner .download-video button{border-radius:var(--corner-radius)}.download-video .cover{width:240px;min-height:135px;background-color:#8882}.download-video .header{display:flex;justify-content:space-between;align-items:center}.download-video h1{font-size:16pt;font-weight:700;color:var(--download-video-foreground)}.download-video .header .mdi-close{font-size:16pt;color:var(--download-video-foreground);cursor:pointer}.download-video .header .mdi-close:hover{color:var(--theme-color)}.download-video .info{display:flex;flex-direction:column;align-items:center;margin-top:12px}.download-video .title{display:flex;flex-direction:column;justify-content:space-between;align-items:stretch;margin-top:12px}.download-video .title .bold{width:300px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:center}.download-video .title .size{font-size:10pt;color:var(--download-video-foreground);align-self:center;display:flex;align-items:center;height:24px}.download-video .bold{color:var(--download-video-foreground);font-weight:700;font-size:12pt}.download-video .option-item{display:flex;justify-content:space-between;align-items:center;padding-top:12px;font-size:10pt}.download-video .tabs{display:flex;padding-top:12px;font-size:10pt}.download-video .tabs .tab{padding:6px 12px;border-bottom:2px solid transparent;cursor:pointer}.download-video .tabs .tab.active{color:var(--theme-color);border-bottom-color:var(--theme-color)}.download-video .separator{height:1px;background:#8884;width:100%;margin:12px 0;flex-shrink:0}.download-video h2{font-size:12pt;font-weight:700;color:var(--download-video-foreground)}.download-video .direct-download{display:flex;flex-direction:column;align-items:start;justify-content:space-between}.download-video .button,.download-video button{border:none;outline:0!important;padding:6px 16px;font-size:10pt;cursor:pointer;background:#8884;color:var(--download-video-foreground)}.download-video .button:hover,.download-video button:hover{background:#8886}.download-video .primary{background:var(--theme-color);color:var(--foreground-color);align-self:center}.download-video .primary:hover{background:var(--theme-color-90)}.download-video .busy .button,.download-video .busy .primary,.download-video .busy button,.download-video button:disabled{background-color:#0001;color:#8884;cursor:not-allowed}.download-video .busy .button,.download-video .busy button{cursor:wait!important}.download-video .direct-download .progress{align-self:stretch;display:flex;align-items:center;margin-top:8px}.download-video .direct-download .progress .background{flex-grow:1;height:4px;background:#8884;margin-right:4px;position:relative}.download-video .direct-download .progress .background .foreground{position:absolute;top:0;left:0;height:4px;background:linear-gradient(to right,var(--theme-color),var(--theme-color-60))}.download-video .direct-download .progress .percent{width:50px;text-align:right}.download-video .actions{display:flex;flex-wrap:wrap;justify-content:space-between;margin:8px -4px 0}.download-video .actions>*{margin:4px;flex-grow:1;flex-basis:calc(50% - 16px);display:flex;justify-content:center;align-items:center}.download-video i.mdi-alert-circle{font-size:14pt;color:#ff9800}.download-video .size-warning{position:relative;padding:0 8px}.download-video .size-warning-tip{position:absolute;bottom:100%;left:50%;transform:translateX(-50%);background:var(--download-video-background);color:var(--download-video-foreground);border:1px dashed var(--theme-color);z-index:2;font-size:10pt;width:200px;padding:8px;box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;pointer-events:none;opacity:0}.download-video .size-warning:hover .size-warning-tip{opacity:1}.download-video .episode-list .v-checkbox{padding:4px 8px;margin:4px 0;position:relative;background-color:transparent}.download-video .episode-list .v-checkbox.checked{background-color:#8882}.download-video .episode-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}.download-video .episode-list{overflow:auto;max-height:320px}.download-video button.list-tool{padding:4px;line-height:1;font-size:12pt;margin:0 4px}.download-video .episode-header h2{flex-grow:1}.download-video .selected-count{width:64px;text-align:right}.download-video .aria2-rpc .mdi{margin-left:8px;font-size:14pt;line-height:1}.download-video .aria2-rpc{position:relative}.download-video .rpc-settings{position:absolute;display:flex;flex-direction:column;align-items:stretch;color:var(--download-video-foreground);background:#fff;bottom:120%;left:50%;cursor:initial;box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;transform-origin:bottom;transform:translateX(-50%) scale(.9);opacity:0;pointer-events:none;padding:8px;z-index:3;transition:.3s cubic-bezier(.18,.89,.32,1.28);width:120%}body.dark .download-video .rpc-settings{background:#282828}.download-video .rpc-settings>*{margin:8px}.download-video .rpc-settings.show{opacity:1;transform:translateX(-50%) scale(1);pointer-events:initial}.download-video .rpc-settings input[type=text]{background:0 0;color:var(--download-video-foreground);border:1px solid #8884;padding:4px;margin-left:8px}.download-video .rpc-settings input[type=text]:focus{border-color:var(--theme-color)}.download-video .rpc-settings .operations{display:flex;align-items:center;justify-content:space-evenly}.download-video .final-dir{word-break:break-all}.download-video .rpc-settings-item{display:flex;align-items:center;justify-content:space-between;white-space:nowrap}.download-video .rpc-settings-item input[type=text]{flex-grow:1;margin-left:24px}.download-video button.cancel-download,.download-video button.start-download{margin-top:8px}.download-video .direct-download-header{align-self:stretch;display:flex;justify-content:space-between;align-items:center}body.dark .download-video .direct-download .progress .foreground{background:linear-gradient(to right,var(--theme-color-70),var(--theme-color))}`; onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/preview/min/download-video.min.html"] = `

下载视频

单个视频
批量导出
警告: 过大的视频大小会在直接下载时占用大量内存, 并可能导致浏览器标签页崩溃. 请考虑降低清晰度或使用导出选项.
预计大小: {{displaySize}}
格式
清晰度
弹幕

直接下载

{{speed}}
{{progressPercent}}%

选集

{{selectedEpisodeCount}}/{{episodeList.length}}

导出

{{showRpcSettings ? '取消' : 'aria2 RPC'}}

aria2 RPC

配置

主机
端口
密钥
限速
默认路径
路径
最终路径: {{rpcSettings.baseDir + rpcSettings.dir}}
方法
开始下载
{{saveRpcSettingsText}}
`; onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/preview/min/download-video.min.js"] = (()=>{return(e,t)=>{const{getFriendlyTitle:s}=t.import("title");const{VideoInfo:a,DanmakuInfo:i}=t.import("video-info");class n{constructor(){this.menuClasses=["quality","action","progress"];[this.currentMenuClass]=this.menuClasses}get menuPanel(){return document.querySelector(".download-video-panel")}addMenuClass(){this.menuPanel.classList.remove(...this.menuClasses);this.menuPanel.classList.add(this.currentMenuClass);return this.currentMenuClass}resetMenuClass(){[this.currentMenuClass]=this.menuClasses;this.addMenuClass()}nextMenuClass(){const e=this.menuClasses.indexOf(this.currentMenuClass)+1;const t=this.menuClasses[e>=this.menuClasses.length?0:e];this.currentMenuClass=t;this.addMenuClass();return t}closeMenu(){this.menuPanel.classList.remove("opened");setTimeout(()=>this.resetMenuClass(),200)}addError(){this.menuPanel.classList.add("error")}removeError(){this.menuPanel.classList.remove("error");this.resetMenuClass()}async getDashUrl(e){throw new Error("video dash is not supported")}async getUrl(e){if(e){return`https://api.bilibili.com/x/player/playurl?avid=${r.aid}&cid=${r.cid}&qn=${e}&otype=json`}else{return`https://api.bilibili.com/x/player/playurl?avid=${r.aid}&cid=${r.cid}&otype=json`}}}class o extends n{async getDashUrl(e){if(e){return`https://api.bilibili.com/pgc/player/web/playurl?avid=56995872&cid=99547543&qn=${e}&otype=json&fourk=1&fnval=16`}else{return`https://api.bilibili.com/pgc/player/web/playurl?avid=56995872&cid=99547543&otype=json&fourk=1&fnval=16`}}async getUrl(e){if(e){return`https://api.bilibili.com/pgc/player/web/playurl?avid=${r.aid}&cid=${r.cid}&qn=${e}&otype=json`}else{return`https://api.bilibili.com/pgc/player/web/playurl?avid=${r.aid}&cid=${r.cid}&qn=&otype=json`}}}const r={entity:new n,aid:"",cid:""};let l=[];let c=null;class d{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async downloadInfo(e=false){const t=new h(this);await t.fetchVideoInfo(e);return t}static parseFormats(e){const t=e.accept_quality;const s=e.accept_format.split(",");const a=e.accept_description;const i=t.map((e,t)=>{return new d(e,s[t],a[t])});return i}static async getAvailableDashFormats(){const e=await r.entity.getDashUrl();const t=await Ajax.getJsonWithCredentials(e);if(t.code!==0){throw new Error("获取清晰度信息失败.")}return d.parseFormats(t.result)}static async getAvailableFormats(){const e=await r.entity.getUrl();const t=await Ajax.getJsonWithCredentials(e);if(t.code!==0){throw new Error("获取清晰度信息失败.")}const s=t.data||t.result||t;return d.parseFormats(s)}}class h{constructor(e,t){this.fragmentSplitFactor=6*2;this.workingXhr=null;this.progressMap=new Map;this.format=e;this.fragments=t||[];this.videoSpeed=new u(this)}get totalSize(){return this.fragments.map(e=>e.size).reduce((e,t)=>e+t)}async fetchVideoInfo(e=false){if(!e){const e=await r.entity.getUrl(this.format.quality);const t=await Ajax.getTextWithCredentials(e);const s=JSON.parse(t.replace(/http:/g,"https:"));const a=s.data||s.result||s;if(a.quality!==this.format.quality){throw new Error("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const i=a.durl;this.fragments=i.map(e=>{return{length:e.length,size:e.size,url:e.url,backupUrls:e.backup_url}})}else{const{dashToFragment:e,getDashInfo:s}=await t.importAsync("video-dash");const a=await s(r.aid,r.cid,this.format.quality);const i=a.videoDashes.sort(descendingSort(e=>e.bandWidth))[0];const n=a.audioDashes.sort(descendingSort(e=>e.bandWidth))[0];this.fragments=[e(i),e(n)]}return this.fragments}updateProgress(){const e=this.progressMap?[...this.progressMap.values()].reduce((e,t)=>e+t,0)/this.totalSize:0;if(e>1||e<0){console.error(`[下载视频] 进度异常: ${e}`,this.progressMap.values())}this.progress&&this.progress(e)}cancelDownload(){this.videoSpeed.stopMeasure();if(this.workingXhr!==null){this.workingXhr.forEach(e=>e.abort())}else{logError("Cancel Download Failed: forEach in this.workingXhr not found.")}}downloadFragment(e){const t=[];this.workingXhr=[];this.progressMap=new Map;this.updateProgress();let s;if(e.size<=96*1024*1024){s=e.size/this.fragmentSplitFactor}else{s=16*1024*1024}let a=0;const i=e=>[...this.progressMap.keys()].indexOf(e)+1;while(a{const a=new XMLHttpRequest;a.open("GET",e.url);a.responseType="arraybuffer";a.withCredentials=false;a.addEventListener("progress",e=>{console.log(`[下载视频] 视频片段${i(a)}下载进度: ${e.loaded}/${r} bytes loaded, ${o}`);this.progressMap.set(a,e.loaded);this.updateProgress()});a.addEventListener("load",()=>{if((""+a.status)[0]==="2"){console.log(`[下载视频] 视频片段${i(a)}下载完成`);t(a.response)}else{s(`视频片段${i(a)}请求失败, response = ${a.status}`)}});a.addEventListener("abort",()=>s("canceled"));a.addEventListener("error",()=>{console.error(`[下载视频] 视频片段${i(a)}下载失败: ${o}`);this.progressMap.set(a,0);this.updateProgress();a.open("GET",e.url);a.setRequestHeader("Range",o);a.send()});a.setRequestHeader("Range",o);this.progressMap.set(a,0);a.send();this.workingXhr.push(a)}));a=Math.round(a+s)+1}return Promise.all(t)}async copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM.setClipboard(e,"text")}async showUrl(){const e=this.fragments.map(e=>`\n${e.url}\n`).reduce((e,t)=>e+"\r\n"+t);Toast.success(e+`复制全部`,"显示链接");const t=await SpinQuery.select("#copy-link");t.addEventListener("click",async()=>{await this.copyUrl()})}static downloadBlob(e,t){const s=document.createElement("a");let a;if(typeof e==="string"){a=e}else{a=URL.createObjectURL(e)}s.setAttribute("href",a);s.setAttribute("download",t);document.body.appendChild(s);s.click();s.remove();URL.revokeObjectURL(a)}async exportData(e=false){const t=JSON.stringify([{fragments:this.fragments,title:s(),totalSize:this.fragments.map(e=>e.size).reduce((e,t)=>e+t),referer:document.URL.replace(window.location.search,"")}]);if(e){GM.setClipboard(t,"text")}else{const e=new Blob([t],{type:"text/json"});const a=await this.downloadDanmaku();if(a!==null){const t=new JSZip;t.file(`${s()}.json`,e);t.file(s()+"."+this.danmakuOption.toLowerCase(),a);h.downloadBlob(await t.generateAsync({type:"blob"}),`${s()}.zip`)}else{h.downloadBlob(e,`${s()}.json`)}}}async exportAria2(a=false){if(a){const a=await this.downloadDanmaku();if(a!==null){h.downloadBlob(new Blob([a]),`${s()}.${this.danmakuOption==="ASS"?"ass":"xml"}`)}const i=e.aria2RpcOption;const n=this.fragments.map((e,t)=>{let a="";if(this.fragments.length>1){a=" - "+(t+1)}const n=[];if(i.secretKey!==""){n.push(`token:${i.secretKey}`)}n.push([e.url]);n.push({referer:document.URL.replace(window.location.search,""),"user-agent":UserAgent,out:`${s()}${a}${this.extension(e)}`,split:this.fragmentSplitFactor,dir:i.baseDir+i.dir||undefined,"max-download-limit":i.maxDownloadLimit||undefined});const o=encodeURIComponent(`${s()}${a}`);return{params:n,id:o}});const{sendRpc:o}=await t.importAsync("aria2-rpc");await o(n)}else{const e=`\n# Generated by Bilibili Evolved Video Export\n# https://github.com/the1812/Bilibili-Evolved/\n${this.fragments.map((e,t)=>{let a="";if(this.fragments.length>1){a=" - "+(t+1)}return`\n${e.url}\n referer=${document.URL.replace(window.location.search,"")}\n user-agent=${UserAgent}\n out=${s()}${a}${this.extension(e)}\n split=${this.fragmentSplitFactor}\n`.trim()}).join("\n")}\n`.trim();const t=new Blob([e],{type:"text/plain"});const a=await this.downloadDanmaku();if(a!==null){const e=new JSZip;e.file(`${s()}.txt`,t);e.file(s()+"."+this.danmakuOption.toLowerCase(),a);h.downloadBlob(await e.generateAsync({type:"blob"}),`${s()}.zip`)}else{h.downloadBlob(t,`${s()}.txt`)}}}extension(e){const t=e||this.fragments[0];const s=[".flv",".mp4",".m4s"].find(e=>t.url.includes(e));if(s){return s}else{console.warn("No extension detected.");return".flv"}}makeBlob(e,t){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=dq("a#video-complete").getAttribute("href");if(e&&!dq(`.link[href="${e}"]`)){URL.revokeObjectURL(e)}dqa(".toast-card-header").filter(e=>e.innerText.includes("下载视频")).forEach(e=>e.querySelector(".toast-card-dismiss").click())}async downloadDanmaku(){if(this.danmakuOption!=="无"){const e=new i(r.cid);await e.fetchInfo();if(this.danmakuOption==="XML"){return e.rawXML}else{const{convertToAss:s}=await t.importAsync("download-danmaku");return s(e.rawXML)}}else{return null}}async downloadSingle(e){const t=await this.downloadDanmaku();const[a]=e;if(t===null){const e=this.makeBlob(a);const t=s()+this.extension();return{blob:e,filename:t}}else{const e=new JSZip;e.file(s()+this.extension(),this.makeBlob(a));e.file(s()+"."+this.danmakuOption.toLowerCase(),t);const i=await e.generateAsync({type:"blob"});const n=s()+".zip";return{blob:i,filename:n}}}async downloadMultiple(e){const t=new JSZip;const a=s();if(e.length>1){e.forEach((e,s)=>{const i=this.fragments[s];t.file(`${a} - ${s+1}${this.extension(i)}`,this.makeBlob(e,i))})}else{const[s]=e;t.file(`${a}${this.extension()}`,this.makeBlob(s))}const i=await this.downloadDanmaku();if(i!==null){t.file(s()+"."+this.danmakuOption.toLowerCase(),i)}const n=await t.generateAsync({type:"blob"});const o=a+".zip";return{blob:n,filename:o}}async download(){const e=[];this.videoSpeed.startMeasure();for(const t of this.fragments){const s=await this.downloadFragment(t);e.push(s)}if(e.length<1){throw new Error("下载失败.")}let{blob:t,filename:s}=await(async()=>{if(e.length===1){return await this.downloadSingle(e)}else{return await this.downloadMultiple(e)}})();this.cleanUpOldBlobUrl();const a=URL.createObjectURL(t);this.progress&&this.progress(0);this.videoSpeed.stopMeasure();return{url:a,filename:s}}}class u{constructor(e){this.lastProgress=0;this.measureInterval=1e3;this.workingDownloader=e}startMeasure(){this.intervalTimer=setInterval(()=>{const e=this.workingDownloader.progressMap?[...this.workingDownloader.progressMap.values()].reduce((e,t)=>e+t,0):0;const t=e-this.lastProgress;if(this.speedUpdate!==undefined){this.speedUpdate(formatFileSize(t)+"/s")}this.lastProgress=e},this.measureInterval)}stopMeasure(){clearInterval(this.intervalTimer)}}async function p(){const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);const t=await SpinQuery.select(()=>(unsafeWindow||window).cid);if(!(e&&t)){return false}r.aid=e;r.cid=t;if(document.URL.indexOf("bangumi")!==-1){r.entity=new o}else{r.entity=new n}try{l=await d.getAvailableFormats()}catch(e){return false}return true}async function f(){c=l[0];t.applyStyle("downloadVideoStyle");dq("#download-video").addEventListener("click",()=>{dq(".download-video").classList.toggle("opened");dq(".gui-settings-mask").click()});dq("#download-video").addEventListener("mouseover",()=>{document.body.insertAdjacentHTML("beforeend",t.import("downloadVideoHtml"));w()},{once:true})}async function w(){let n;const o=new Map;const u=new Vue({el:".download-video",components:{VDropdown:()=>t.importAsync("v-dropdown.vue"),VCheckbox:()=>t.importAsync("v-checkbox.vue"),RpcProfiles:()=>t.importAsync("aria2-rpc-profiles.vue")},data:{downloadSingle:true,coverUrl:EmptyImageUrl,aid:r.aid,cid:r.cid,dashModel:{value:e.downloadVideoFormat,items:["flv","dash"]},qualityModel:{value:c.displayName,items:l.map(e=>e.displayName)},danmakuModel:{value:e.downloadVideoDefaultDanmaku,items:["无","XML","ASS"]},progressPercent:0,size:"获取大小中",blobUrl:"",episodeList:[],downloading:false,speed:"",batch:false,rpcSettings:e.aria2RpcOption,showRpcSettings:false,busy:false,saveRpcSettingsText:"保存配置",enableDash:e.enableDashDownload},computed:{displaySize(){if(typeof this.size==="string"){return this.size}return formatFileSize(this.size)},sizeWarning(){if(typeof this.size==="string"){return false}return this.size>1073741824},selectedEpisodeCount(){return this.episodeList.filter(e=>e.checked).length},dash(){return this.dashModel.value==="dash"}},methods:{close(){this.$el.classList.remove("opened")},danmakuOptionChange(){e.downloadVideoDefaultDanmaku=this.danmakuModel.value},async dashChange(){const e=this.dashModel.value;let t=[];if(e==="flv"){t=await d.getAvailableFormats()}else{t=await d.getAvailableDashFormats()}l=t;[c]=e;this.qualityModel.items=t.map(e=>e.displayName);[this.qualityModel.value]=this.qualityModel.items},async formatChange(){const e=this.getFormat();const t=o.get(e);if(t){this.size=t;return}try{this.size="获取大小中";const t=await e.downloadInfo(this.dash);this.size=t.totalSize;o.set(e,this.size)}catch(e){this.size="获取大小失败"}},getFormat(){const e=l.find(e=>e.displayName===this.qualityModel.value);if(!e){console.error(`No format found. model value = ${this.qualityModel.value}`);return null}return e},async exportData(e){if(this.busy===true){return}try{this.busy=true;if(!this.downloadSingle){await this.exportBatchData(e);return}const t=this.getFormat();const s=await t.downloadInfo(this.dash);s.danmakuOption=this.danmakuModel.value;switch(e){case"copyLink":await s.copyUrl();Toast.success("已复制链接到剪贴板.","下载视频",3e3);break;case"showLink":await s.showUrl();break;case"aria2":await s.exportAria2(false);break;case"aria2RPC":await s.exportAria2(true);break;case"copyVLD":await s.exportData(true);Toast.success("已复制VLD数据到剪贴板.","下载视频",3e3);break;case"exportVLD":await s.exportData(false);break;default:break}}catch(e){logError(e)}finally{this.busy=false}},async exportBatchData(e){const a=this.episodeList;if(a.every(e=>e.checked===false)){Toast.info("请至少选择1集或以上的数量!","批量导出",3e3);return}const n=e=>{const t=a.find(t=>t.cid===e.cid);if(t===undefined){return false}return t.checked};const o=this.getFormat();if(this.danmakuModel.value!=="无"){const e=Toast.info("下载弹幕中...","批量导出");const s=new JSZip;try{if(this.danmakuModel.value==="XML"){for(const e of a.filter(n)){const t=new i(e.cid);await t.fetchInfo();s.file(e.title+".xml",t.rawXML)}}else{const{convertToAss:e}=await t.importAsync("download-danmaku");for(const t of a.filter(n)){const a=new i(t.cid);await a.fetchInfo();s.file(t.title+".ass",await e(a.rawXML))}}h.downloadBlob(await s.generateAsync({type:"blob"}),this.cid+".danmakus.zip")}catch(e){logError(`弹幕下载失败`)}finally{e.dismiss()}}const r=Toast.info("获取链接中...","批量导出");this.batchExtractor.itemFilter=n;let l;try{switch(e){case"aria2":l=await this.batchExtractor.collectAria2(o,r);h.downloadBlob(new Blob([l],{type:"text/plain"}),s(false)+".txt");return;case"aria2RPC":await this.batchExtractor.collectAria2(o,r,true);Toast.success(`成功发送了批量请求.`,"aria2 RPC",3e3);return;case"copyVLD":GM.setClipboard(await this.batchExtractor.collectData(o,r),{mimetype:"text/plain"});Toast.success("已复制批量vld数据到剪贴板.","批量导出",3e3);return;case"exportVLD":l=await this.batchExtractor.collectData(o,r);h.downloadBlob(new Blob([l],{type:"text/json"}),s(false)+".json");return;default:return}}catch(e){logError(e)}finally{r.dismiss()}},async checkBatch(){const e=["/www.bilibili.com/bangumi","/www.bilibili.com/video/av"];if(!e.some(e=>document.URL.includes(e))){this.batch=false;this.episodeList=[];return}const{BatchExtractor:s}=await t.importAsync("batch-download");if(await s.test()!==true){this.batch=false;this.episodeList=[];return}this.batchExtractor=new s;this.batch=true;this.episodeList=(await this.batchExtractor.getItemList()).map((e,t)=>{return{aid:e.aid,cid:e.cid,title:e.title,index:t,checked:true}})},cancelDownload(){if(n){n.cancelDownload()}},async startDownload(){const e=this.getFormat();try{this.downloading=true;const t=await e.downloadInfo(this.dash);t.videoSpeed.speedUpdate=(e=>this.speed=e);t.danmakuOption=this.danmakuModel.value;t.progress=(e=>{this.progressPercent=Math.trunc(e*100)});n=t;const s=await t.download();const a=document.getElementById("video-complete");a.setAttribute("href",s.url);a.setAttribute("download",s.filename);a.click();Toast.success(`下载完成: ${s.filename} 再次保存`,"下载视频")}catch(e){if(e!=="canceled"){logError(e)}this.progressPercent=0}finally{this.downloading=false;this.speed=""}},selectAllEpisodes(){this.episodeList.forEach(e=>e.checked=true)},unselectAllEpisodes(){this.episodeList.forEach(e=>e.checked=false)},inverseAllEpisodes(){this.episodeList.forEach(e=>e.checked=!e.checked)},toggleRpcSettings(){this.showRpcSettings=!this.showRpcSettings},saveRpcSettings(){if(this.rpcSettings.host===""){this.rpcSettings.host="127.0.0.1"}if(this.rpcSettings.port===""){this.rpcSettings.port="6800"}e.aria2RpcOption=this.rpcSettings;const t=e.aria2RpcOptionProfiles.find(t=>t.name===e.aria2RpcOptionSelectedProfile);if(t){Object.assign(t,this.rpcSettings);e.aria2RpcOptionProfiles=e.aria2RpcOptionProfiles}this.saveRpcSettingsText="已保存";setTimeout(()=>this.saveRpcSettingsText="保存配置",2e3)},updateProfile(t){e.aria2RpcOption=this.rpcSettings=_.omit(t,"name")}}});Observer.videoChange(async()=>{u.close();u.batch=false;u.downloadSingle=true;const e=dq("#download-video");const t=await p();e.style.display=t?"flex":"none";if(!t){return}u.aid=r.aid;u.cid=r.cid;const s=new a(r.aid);await s.fetchInfo();u.coverUrl=s.coverUrl.replace("http:","https:");l=await d.getAvailableFormats();[c]=l;u.qualityModel={value:c.displayName,items:l.map(e=>e.displayName)};u.formatChange();await u.checkBatch()})}return{widget:{content:`\n`,condition:p,success:f}}}})(); -onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/preview/min/dpi-img.vue.min.js"] = (()=>{return(t,e)=>{const i=``;return{export:Object.assign({template:i},{props:["size","src","blur"],computed:{srcset(){if(!this.src||!this.size){return null}return getDpiSourceSet(this.src,this.size)},width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); +onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/preview/min/dpi-img.vue.min.js"] = (()=>{return(t,s)=>{const e=``;return{export:Object.assign({template:e},{props:["size","src","blur","root","rootMargin","threshold"],data(){return{srcset:null,actualSrc:null}},methods:{calcSrc(){if(!this.src||!this.size){return null}const t=this.src.substring(this.src.lastIndexOf(".")+1);this.srcset=getDpiSourceSet(this.src,this.size,t);this.actualSrc=this.src}},mounted(){const t={root:this.root,rootMargin:this.rootMargin||"200px",threshold:this.threshold};console.log(t);const s=new IntersectionObserver(t=>{t.forEach(t=>{if(t.isIntersecting){this.calcSrc();s.disconnect()}})},t);s.observe(this.$el)},computed:{width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/preview/min/expand-danmaku.min.js"] = (()=>{return(e,a)=>{if(typeof isEmbeddedPlayer!=="undefined"&&isEmbeddedPlayer()){return}Observer.videoChange(async()=>{const e=await SpinQuery.select(".bui-collapse-wrap");if(e&&e.classList.contains("bui-collapse-wrap-folded")){const e=await SpinQuery.select(".bui-collapse-header");e.click()}})}})(); onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/preview/min/expand-description.min.css"] = `.play-up-info .play-up-self,.video-desc .info{height:auto!important}.play-up-info .play-up-self-btn,.video-desc .btn{display:none!important}`; onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/preview/min/expand-description.min.js"] = (()=>{return(e,p)=>{p.applyStyle("expandDescriptionStyle")}})(); diff --git a/bilibili-evolved.user.js b/bilibili-evolved.user.js index 0bbdc6633..595ae91ca 100644 --- a/bilibili-evolved.user.js +++ b/bilibili-evolved.user.js @@ -1083,7 +1083,7 @@ onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/mi onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.css"] = `.download-video{--download-video-background:white;--download-video-foreground:black;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) scale(.95);background:var(--download-video-background);color:var(--download-video-foreground);box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;z-index:10001;pointer-events:none;opacity:0;padding:16px;width:300px;display:flex;flex-direction:column;align-items:stretch;justify-content:space-between;max-height:90%}.download-video,.download-video *{transition:.2s ease-out;-webkit-tap-highlight-color:transparent!important}.download-video.opened{pointer-events:initial;opacity:1;transform:translate(-50%,-50%) scale(1)}body.dark .download-video{--download-video-background:#222;--download-video-foreground:#eee}.round-corner .download-video,.round-corner .download-video .episode-list .v-checkbox,.round-corner .download-video .rpc-settings{border-radius:var(--large-corner-radius)}.round-corner .download-video .button,.round-corner .download-video .cover,.round-corner .download-video .direct-download .progress .background,.round-corner .download-video .direct-download .progress .foreground,.round-corner .download-video .rpc-settings input[type=text],.round-corner .download-video .title,.round-corner .download-video button{border-radius:var(--corner-radius)}.download-video .cover{width:240px;min-height:135px;background-color:#8882}.download-video .header{display:flex;justify-content:space-between;align-items:center}.download-video h1{font-size:16pt;font-weight:700;color:var(--download-video-foreground)}.download-video .header .mdi-close{font-size:16pt;color:var(--download-video-foreground);cursor:pointer}.download-video .header .mdi-close:hover{color:var(--theme-color)}.download-video .info{display:flex;flex-direction:column;align-items:center;margin-top:12px}.download-video .title{display:flex;flex-direction:column;justify-content:space-between;align-items:stretch;margin-top:12px}.download-video .title .bold{width:300px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:center}.download-video .title .size{font-size:10pt;color:var(--download-video-foreground);align-self:center;display:flex;align-items:center;height:24px}.download-video .bold{color:var(--download-video-foreground);font-weight:700;font-size:12pt}.download-video .option-item{display:flex;justify-content:space-between;align-items:center;padding-top:12px;font-size:10pt}.download-video .tabs{display:flex;padding-top:12px;font-size:10pt}.download-video .tabs .tab{padding:6px 12px;border-bottom:2px solid transparent;cursor:pointer}.download-video .tabs .tab.active{color:var(--theme-color);border-bottom-color:var(--theme-color)}.download-video .separator{height:1px;background:#8884;width:100%;margin:12px 0;flex-shrink:0}.download-video h2{font-size:12pt;font-weight:700;color:var(--download-video-foreground)}.download-video .direct-download{display:flex;flex-direction:column;align-items:start;justify-content:space-between}.download-video .button,.download-video button{border:none;outline:0!important;padding:6px 16px;font-size:10pt;cursor:pointer;background:#8884;color:var(--download-video-foreground)}.download-video .button:hover,.download-video button:hover{background:#8886}.download-video .primary{background:var(--theme-color);color:var(--foreground-color);align-self:center}.download-video .primary:hover{background:var(--theme-color-90)}.download-video .busy .button,.download-video .busy .primary,.download-video .busy button,.download-video button:disabled{background-color:#0001;color:#8884;cursor:not-allowed}.download-video .busy .button,.download-video .busy button{cursor:wait!important}.download-video .direct-download .progress{align-self:stretch;display:flex;align-items:center;margin-top:8px}.download-video .direct-download .progress .background{flex-grow:1;height:4px;background:#8884;margin-right:4px;position:relative}.download-video .direct-download .progress .background .foreground{position:absolute;top:0;left:0;height:4px;background:linear-gradient(to right,var(--theme-color),var(--theme-color-60))}.download-video .direct-download .progress .percent{width:50px;text-align:right}.download-video .actions{display:flex;flex-wrap:wrap;justify-content:space-between;margin:8px -4px 0}.download-video .actions>*{margin:4px;flex-grow:1;flex-basis:calc(50% - 16px);display:flex;justify-content:center;align-items:center}.download-video i.mdi-alert-circle{font-size:14pt;color:#ff9800}.download-video .size-warning{position:relative;padding:0 8px}.download-video .size-warning-tip{position:absolute;bottom:100%;left:50%;transform:translateX(-50%);background:var(--download-video-background);color:var(--download-video-foreground);border:1px dashed var(--theme-color);z-index:2;font-size:10pt;width:200px;padding:8px;box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;pointer-events:none;opacity:0}.download-video .size-warning:hover .size-warning-tip{opacity:1}.download-video .episode-list .v-checkbox{padding:4px 8px;margin:4px 0;position:relative;background-color:transparent}.download-video .episode-list .v-checkbox.checked{background-color:#8882}.download-video .episode-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}.download-video .episode-list{overflow:auto;max-height:320px}.download-video button.list-tool{padding:4px;line-height:1;font-size:12pt;margin:0 4px}.download-video .episode-header h2{flex-grow:1}.download-video .selected-count{width:64px;text-align:right}.download-video .aria2-rpc .mdi{margin-left:8px;font-size:14pt;line-height:1}.download-video .aria2-rpc{position:relative}.download-video .rpc-settings{position:absolute;display:flex;flex-direction:column;align-items:stretch;color:var(--download-video-foreground);background:#fff;bottom:120%;left:50%;cursor:initial;box-shadow:rgba(0,0,0,.2) 0 4px 8px 0;transform-origin:bottom;transform:translateX(-50%) scale(.9);opacity:0;pointer-events:none;padding:8px;z-index:3;transition:.3s cubic-bezier(.18,.89,.32,1.28);width:120%}body.dark .download-video .rpc-settings{background:#282828}.download-video .rpc-settings>*{margin:8px}.download-video .rpc-settings.show{opacity:1;transform:translateX(-50%) scale(1);pointer-events:initial}.download-video .rpc-settings input[type=text]{background:0 0;color:var(--download-video-foreground);border:1px solid #8884;padding:4px;margin-left:8px}.download-video .rpc-settings input[type=text]:focus{border-color:var(--theme-color)}.download-video .rpc-settings .operations{display:flex;align-items:center;justify-content:space-evenly}.download-video .final-dir{word-break:break-all}.download-video .rpc-settings-item{display:flex;align-items:center;justify-content:space-between;white-space:nowrap}.download-video .rpc-settings-item input[type=text]{flex-grow:1;margin-left:24px}.download-video button.cancel-download,.download-video button.start-download{margin-top:8px}.download-video .direct-download-header{align-self:stretch;display:flex;justify-content:space-between;align-items:center}body.dark .download-video .direct-download .progress .foreground{background:linear-gradient(to right,var(--theme-color-70),var(--theme-color))}`; onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.html"] = `

下载视频

单个视频
批量导出
警告: 过大的视频大小会在直接下载时占用大量内存, 并可能导致浏览器标签页崩溃. 请考虑降低清晰度或使用导出选项.
预计大小: {{displaySize}}
格式
清晰度
弹幕

直接下载

{{speed}}
{{progressPercent}}%

选集

{{selectedEpisodeCount}}/{{episodeList.length}}

导出

{{showRpcSettings ? '取消' : 'aria2 RPC'}}

aria2 RPC

配置

主机
端口
密钥
限速
默认路径
路径
最终路径: {{rpcSettings.baseDir + rpcSettings.dir}}
方法
开始下载
{{saveRpcSettingsText}}
`; onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/download-video.min.js"] = (()=>{return(e,t)=>{const{getFriendlyTitle:s}=t.import("title");const{VideoInfo:a,DanmakuInfo:i}=t.import("video-info");class n{constructor(){this.menuClasses=["quality","action","progress"];[this.currentMenuClass]=this.menuClasses}get menuPanel(){return document.querySelector(".download-video-panel")}addMenuClass(){this.menuPanel.classList.remove(...this.menuClasses);this.menuPanel.classList.add(this.currentMenuClass);return this.currentMenuClass}resetMenuClass(){[this.currentMenuClass]=this.menuClasses;this.addMenuClass()}nextMenuClass(){const e=this.menuClasses.indexOf(this.currentMenuClass)+1;const t=this.menuClasses[e>=this.menuClasses.length?0:e];this.currentMenuClass=t;this.addMenuClass();return t}closeMenu(){this.menuPanel.classList.remove("opened");setTimeout(()=>this.resetMenuClass(),200)}addError(){this.menuPanel.classList.add("error")}removeError(){this.menuPanel.classList.remove("error");this.resetMenuClass()}async getDashUrl(e){throw new Error("video dash is not supported")}async getUrl(e){if(e){return`https://api.bilibili.com/x/player/playurl?avid=${r.aid}&cid=${r.cid}&qn=${e}&otype=json`}else{return`https://api.bilibili.com/x/player/playurl?avid=${r.aid}&cid=${r.cid}&otype=json`}}}class o extends n{async getDashUrl(e){if(e){return`https://api.bilibili.com/pgc/player/web/playurl?avid=56995872&cid=99547543&qn=${e}&otype=json&fourk=1&fnval=16`}else{return`https://api.bilibili.com/pgc/player/web/playurl?avid=56995872&cid=99547543&otype=json&fourk=1&fnval=16`}}async getUrl(e){if(e){return`https://api.bilibili.com/pgc/player/web/playurl?avid=${r.aid}&cid=${r.cid}&qn=${e}&otype=json`}else{return`https://api.bilibili.com/pgc/player/web/playurl?avid=${r.aid}&cid=${r.cid}&qn=&otype=json`}}}const r={entity:new n,aid:"",cid:""};let l=[];let c=null;class d{constructor(e,t,s){this.quality=e;this.internalName=t;this.displayName=s}async downloadInfo(e=false){const t=new h(this);await t.fetchVideoInfo(e);return t}static parseFormats(e){const t=e.accept_quality;const s=e.accept_format.split(",");const a=e.accept_description;const i=t.map((e,t)=>{return new d(e,s[t],a[t])});return i}static async getAvailableDashFormats(){const e=await r.entity.getDashUrl();const t=await Ajax.getJsonWithCredentials(e);if(t.code!==0){throw new Error("获取清晰度信息失败.")}return d.parseFormats(t.result)}static async getAvailableFormats(){const e=await r.entity.getUrl();const t=await Ajax.getJsonWithCredentials(e);if(t.code!==0){throw new Error("获取清晰度信息失败.")}const s=t.data||t.result||t;return d.parseFormats(s)}}class h{constructor(e,t){this.fragmentSplitFactor=6*2;this.workingXhr=null;this.progressMap=new Map;this.format=e;this.fragments=t||[];this.videoSpeed=new u(this)}get totalSize(){return this.fragments.map(e=>e.size).reduce((e,t)=>e+t)}async fetchVideoInfo(e=false){if(!e){const e=await r.entity.getUrl(this.format.quality);const t=await Ajax.getTextWithCredentials(e);const s=JSON.parse(t.replace(/http:/g,"https:"));const a=s.data||s.result||s;if(a.quality!==this.format.quality){throw new Error("获取下载链接失败, 请确认当前账号有下载权限后重试.")}const i=a.durl;this.fragments=i.map(e=>{return{length:e.length,size:e.size,url:e.url,backupUrls:e.backup_url}})}else{const{dashToFragment:e,getDashInfo:s}=await t.importAsync("video-dash");const a=await s(r.aid,r.cid,this.format.quality);const i=a.videoDashes.sort(descendingSort(e=>e.bandWidth))[0];const n=a.audioDashes.sort(descendingSort(e=>e.bandWidth))[0];this.fragments=[e(i),e(n)]}return this.fragments}updateProgress(){const e=this.progressMap?[...this.progressMap.values()].reduce((e,t)=>e+t,0)/this.totalSize:0;if(e>1||e<0){console.error(`[下载视频] 进度异常: ${e}`,this.progressMap.values())}this.progress&&this.progress(e)}cancelDownload(){this.videoSpeed.stopMeasure();if(this.workingXhr!==null){this.workingXhr.forEach(e=>e.abort())}else{logError("Cancel Download Failed: forEach in this.workingXhr not found.")}}downloadFragment(e){const t=[];this.workingXhr=[];this.progressMap=new Map;this.updateProgress();let s;if(e.size<=96*1024*1024){s=e.size/this.fragmentSplitFactor}else{s=16*1024*1024}let a=0;const i=e=>[...this.progressMap.keys()].indexOf(e)+1;while(a{const a=new XMLHttpRequest;a.open("GET",e.url);a.responseType="arraybuffer";a.withCredentials=false;a.addEventListener("progress",e=>{console.log(`[下载视频] 视频片段${i(a)}下载进度: ${e.loaded}/${r} bytes loaded, ${o}`);this.progressMap.set(a,e.loaded);this.updateProgress()});a.addEventListener("load",()=>{if((""+a.status)[0]==="2"){console.log(`[下载视频] 视频片段${i(a)}下载完成`);t(a.response)}else{s(`视频片段${i(a)}请求失败, response = ${a.status}`)}});a.addEventListener("abort",()=>s("canceled"));a.addEventListener("error",()=>{console.error(`[下载视频] 视频片段${i(a)}下载失败: ${o}`);this.progressMap.set(a,0);this.updateProgress();a.open("GET",e.url);a.setRequestHeader("Range",o);a.send()});a.setRequestHeader("Range",o);this.progressMap.set(a,0);a.send();this.workingXhr.push(a)}));a=Math.round(a+s)+1}return Promise.all(t)}async copyUrl(){const e=this.fragments.map(e=>e.url).reduce((e,t)=>e+"\r\n"+t);GM.setClipboard(e,"text")}async showUrl(){const e=this.fragments.map(e=>`\n${e.url}\n`).reduce((e,t)=>e+"\r\n"+t);Toast.success(e+`复制全部`,"显示链接");const t=await SpinQuery.select("#copy-link");t.addEventListener("click",async()=>{await this.copyUrl()})}static downloadBlob(e,t){const s=document.createElement("a");let a;if(typeof e==="string"){a=e}else{a=URL.createObjectURL(e)}s.setAttribute("href",a);s.setAttribute("download",t);document.body.appendChild(s);s.click();s.remove();URL.revokeObjectURL(a)}async exportData(e=false){const t=JSON.stringify([{fragments:this.fragments,title:s(),totalSize:this.fragments.map(e=>e.size).reduce((e,t)=>e+t),referer:document.URL.replace(window.location.search,"")}]);if(e){GM.setClipboard(t,"text")}else{const e=new Blob([t],{type:"text/json"});const a=await this.downloadDanmaku();if(a!==null){const t=new JSZip;t.file(`${s()}.json`,e);t.file(s()+"."+this.danmakuOption.toLowerCase(),a);h.downloadBlob(await t.generateAsync({type:"blob"}),`${s()}.zip`)}else{h.downloadBlob(e,`${s()}.json`)}}}async exportAria2(a=false){if(a){const a=await this.downloadDanmaku();if(a!==null){h.downloadBlob(new Blob([a]),`${s()}.${this.danmakuOption==="ASS"?"ass":"xml"}`)}const i=e.aria2RpcOption;const n=this.fragments.map((e,t)=>{let a="";if(this.fragments.length>1){a=" - "+(t+1)}const n=[];if(i.secretKey!==""){n.push(`token:${i.secretKey}`)}n.push([e.url]);n.push({referer:document.URL.replace(window.location.search,""),"user-agent":UserAgent,out:`${s()}${a}${this.extension(e)}`,split:this.fragmentSplitFactor,dir:i.baseDir+i.dir||undefined,"max-download-limit":i.maxDownloadLimit||undefined});const o=encodeURIComponent(`${s()}${a}`);return{params:n,id:o}});const{sendRpc:o}=await t.importAsync("aria2-rpc");await o(n)}else{const e=`\n# Generated by Bilibili Evolved Video Export\n# https://github.com/the1812/Bilibili-Evolved/\n${this.fragments.map((e,t)=>{let a="";if(this.fragments.length>1){a=" - "+(t+1)}return`\n${e.url}\n referer=${document.URL.replace(window.location.search,"")}\n user-agent=${UserAgent}\n out=${s()}${a}${this.extension(e)}\n split=${this.fragmentSplitFactor}\n`.trim()}).join("\n")}\n`.trim();const t=new Blob([e],{type:"text/plain"});const a=await this.downloadDanmaku();if(a!==null){const e=new JSZip;e.file(`${s()}.txt`,t);e.file(s()+"."+this.danmakuOption.toLowerCase(),a);h.downloadBlob(await e.generateAsync({type:"blob"}),`${s()}.zip`)}else{h.downloadBlob(t,`${s()}.txt`)}}}extension(e){const t=e||this.fragments[0];const s=[".flv",".mp4",".m4s"].find(e=>t.url.includes(e));if(s){return s}else{console.warn("No extension detected.");return".flv"}}makeBlob(e,t){return new Blob(Array.isArray(e)?e:[e],{type:this.extension(t)===".flv"?"video/x-flv":"video/mp4"})}cleanUpOldBlobUrl(){const e=dq("a#video-complete").getAttribute("href");if(e&&!dq(`.link[href="${e}"]`)){URL.revokeObjectURL(e)}dqa(".toast-card-header").filter(e=>e.innerText.includes("下载视频")).forEach(e=>e.querySelector(".toast-card-dismiss").click())}async downloadDanmaku(){if(this.danmakuOption!=="无"){const e=new i(r.cid);await e.fetchInfo();if(this.danmakuOption==="XML"){return e.rawXML}else{const{convertToAss:s}=await t.importAsync("download-danmaku");return s(e.rawXML)}}else{return null}}async downloadSingle(e){const t=await this.downloadDanmaku();const[a]=e;if(t===null){const e=this.makeBlob(a);const t=s()+this.extension();return{blob:e,filename:t}}else{const e=new JSZip;e.file(s()+this.extension(),this.makeBlob(a));e.file(s()+"."+this.danmakuOption.toLowerCase(),t);const i=await e.generateAsync({type:"blob"});const n=s()+".zip";return{blob:i,filename:n}}}async downloadMultiple(e){const t=new JSZip;const a=s();if(e.length>1){e.forEach((e,s)=>{const i=this.fragments[s];t.file(`${a} - ${s+1}${this.extension(i)}`,this.makeBlob(e,i))})}else{const[s]=e;t.file(`${a}${this.extension()}`,this.makeBlob(s))}const i=await this.downloadDanmaku();if(i!==null){t.file(s()+"."+this.danmakuOption.toLowerCase(),i)}const n=await t.generateAsync({type:"blob"});const o=a+".zip";return{blob:n,filename:o}}async download(){const e=[];this.videoSpeed.startMeasure();for(const t of this.fragments){const s=await this.downloadFragment(t);e.push(s)}if(e.length<1){throw new Error("下载失败.")}let{blob:t,filename:s}=await(async()=>{if(e.length===1){return await this.downloadSingle(e)}else{return await this.downloadMultiple(e)}})();this.cleanUpOldBlobUrl();const a=URL.createObjectURL(t);this.progress&&this.progress(0);this.videoSpeed.stopMeasure();return{url:a,filename:s}}}class u{constructor(e){this.lastProgress=0;this.measureInterval=1e3;this.workingDownloader=e}startMeasure(){this.intervalTimer=setInterval(()=>{const e=this.workingDownloader.progressMap?[...this.workingDownloader.progressMap.values()].reduce((e,t)=>e+t,0):0;const t=e-this.lastProgress;if(this.speedUpdate!==undefined){this.speedUpdate(formatFileSize(t)+"/s")}this.lastProgress=e},this.measureInterval)}stopMeasure(){clearInterval(this.intervalTimer)}}async function p(){const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);const t=await SpinQuery.select(()=>(unsafeWindow||window).cid);if(!(e&&t)){return false}r.aid=e;r.cid=t;if(document.URL.indexOf("bangumi")!==-1){r.entity=new o}else{r.entity=new n}try{l=await d.getAvailableFormats()}catch(e){return false}return true}async function f(){c=l[0];t.applyStyle("downloadVideoStyle");dq("#download-video").addEventListener("click",()=>{dq(".download-video").classList.toggle("opened");dq(".gui-settings-mask").click()});dq("#download-video").addEventListener("mouseover",()=>{document.body.insertAdjacentHTML("beforeend",t.import("downloadVideoHtml"));w()},{once:true})}async function w(){let n;const o=new Map;const u=new Vue({el:".download-video",components:{VDropdown:()=>t.importAsync("v-dropdown.vue"),VCheckbox:()=>t.importAsync("v-checkbox.vue"),RpcProfiles:()=>t.importAsync("aria2-rpc-profiles.vue")},data:{downloadSingle:true,coverUrl:EmptyImageUrl,aid:r.aid,cid:r.cid,dashModel:{value:e.downloadVideoFormat,items:["flv","dash"]},qualityModel:{value:c.displayName,items:l.map(e=>e.displayName)},danmakuModel:{value:e.downloadVideoDefaultDanmaku,items:["无","XML","ASS"]},progressPercent:0,size:"获取大小中",blobUrl:"",episodeList:[],downloading:false,speed:"",batch:false,rpcSettings:e.aria2RpcOption,showRpcSettings:false,busy:false,saveRpcSettingsText:"保存配置",enableDash:e.enableDashDownload},computed:{displaySize(){if(typeof this.size==="string"){return this.size}return formatFileSize(this.size)},sizeWarning(){if(typeof this.size==="string"){return false}return this.size>1073741824},selectedEpisodeCount(){return this.episodeList.filter(e=>e.checked).length},dash(){return this.dashModel.value==="dash"}},methods:{close(){this.$el.classList.remove("opened")},danmakuOptionChange(){e.downloadVideoDefaultDanmaku=this.danmakuModel.value},async dashChange(){const e=this.dashModel.value;let t=[];if(e==="flv"){t=await d.getAvailableFormats()}else{t=await d.getAvailableDashFormats()}l=t;[c]=e;this.qualityModel.items=t.map(e=>e.displayName);[this.qualityModel.value]=this.qualityModel.items},async formatChange(){const e=this.getFormat();const t=o.get(e);if(t){this.size=t;return}try{this.size="获取大小中";const t=await e.downloadInfo(this.dash);this.size=t.totalSize;o.set(e,this.size)}catch(e){this.size="获取大小失败"}},getFormat(){const e=l.find(e=>e.displayName===this.qualityModel.value);if(!e){console.error(`No format found. model value = ${this.qualityModel.value}`);return null}return e},async exportData(e){if(this.busy===true){return}try{this.busy=true;if(!this.downloadSingle){await this.exportBatchData(e);return}const t=this.getFormat();const s=await t.downloadInfo(this.dash);s.danmakuOption=this.danmakuModel.value;switch(e){case"copyLink":await s.copyUrl();Toast.success("已复制链接到剪贴板.","下载视频",3e3);break;case"showLink":await s.showUrl();break;case"aria2":await s.exportAria2(false);break;case"aria2RPC":await s.exportAria2(true);break;case"copyVLD":await s.exportData(true);Toast.success("已复制VLD数据到剪贴板.","下载视频",3e3);break;case"exportVLD":await s.exportData(false);break;default:break}}catch(e){logError(e)}finally{this.busy=false}},async exportBatchData(e){const a=this.episodeList;if(a.every(e=>e.checked===false)){Toast.info("请至少选择1集或以上的数量!","批量导出",3e3);return}const n=e=>{const t=a.find(t=>t.cid===e.cid);if(t===undefined){return false}return t.checked};const o=this.getFormat();if(this.danmakuModel.value!=="无"){const e=Toast.info("下载弹幕中...","批量导出");const s=new JSZip;try{if(this.danmakuModel.value==="XML"){for(const e of a.filter(n)){const t=new i(e.cid);await t.fetchInfo();s.file(e.title+".xml",t.rawXML)}}else{const{convertToAss:e}=await t.importAsync("download-danmaku");for(const t of a.filter(n)){const a=new i(t.cid);await a.fetchInfo();s.file(t.title+".ass",await e(a.rawXML))}}h.downloadBlob(await s.generateAsync({type:"blob"}),this.cid+".danmakus.zip")}catch(e){logError(`弹幕下载失败`)}finally{e.dismiss()}}const r=Toast.info("获取链接中...","批量导出");this.batchExtractor.itemFilter=n;let l;try{switch(e){case"aria2":l=await this.batchExtractor.collectAria2(o,r);h.downloadBlob(new Blob([l],{type:"text/plain"}),s(false)+".txt");return;case"aria2RPC":await this.batchExtractor.collectAria2(o,r,true);Toast.success(`成功发送了批量请求.`,"aria2 RPC",3e3);return;case"copyVLD":GM.setClipboard(await this.batchExtractor.collectData(o,r),{mimetype:"text/plain"});Toast.success("已复制批量vld数据到剪贴板.","批量导出",3e3);return;case"exportVLD":l=await this.batchExtractor.collectData(o,r);h.downloadBlob(new Blob([l],{type:"text/json"}),s(false)+".json");return;default:return}}catch(e){logError(e)}finally{r.dismiss()}},async checkBatch(){const e=["/www.bilibili.com/bangumi","/www.bilibili.com/video/av"];if(!e.some(e=>document.URL.includes(e))){this.batch=false;this.episodeList=[];return}const{BatchExtractor:s}=await t.importAsync("batch-download");if(await s.test()!==true){this.batch=false;this.episodeList=[];return}this.batchExtractor=new s;this.batch=true;this.episodeList=(await this.batchExtractor.getItemList()).map((e,t)=>{return{aid:e.aid,cid:e.cid,title:e.title,index:t,checked:true}})},cancelDownload(){if(n){n.cancelDownload()}},async startDownload(){const e=this.getFormat();try{this.downloading=true;const t=await e.downloadInfo(this.dash);t.videoSpeed.speedUpdate=(e=>this.speed=e);t.danmakuOption=this.danmakuModel.value;t.progress=(e=>{this.progressPercent=Math.trunc(e*100)});n=t;const s=await t.download();const a=document.getElementById("video-complete");a.setAttribute("href",s.url);a.setAttribute("download",s.filename);a.click();Toast.success(`下载完成: ${s.filename} 再次保存`,"下载视频")}catch(e){if(e!=="canceled"){logError(e)}this.progressPercent=0}finally{this.downloading=false;this.speed=""}},selectAllEpisodes(){this.episodeList.forEach(e=>e.checked=true)},unselectAllEpisodes(){this.episodeList.forEach(e=>e.checked=false)},inverseAllEpisodes(){this.episodeList.forEach(e=>e.checked=!e.checked)},toggleRpcSettings(){this.showRpcSettings=!this.showRpcSettings},saveRpcSettings(){if(this.rpcSettings.host===""){this.rpcSettings.host="127.0.0.1"}if(this.rpcSettings.port===""){this.rpcSettings.port="6800"}e.aria2RpcOption=this.rpcSettings;const t=e.aria2RpcOptionProfiles.find(t=>t.name===e.aria2RpcOptionSelectedProfile);if(t){Object.assign(t,this.rpcSettings);e.aria2RpcOptionProfiles=e.aria2RpcOptionProfiles}this.saveRpcSettingsText="已保存";setTimeout(()=>this.saveRpcSettingsText="保存配置",2e3)},updateProfile(t){e.aria2RpcOption=this.rpcSettings=_.omit(t,"name")}}});Observer.videoChange(async()=>{u.close();u.batch=false;u.downloadSingle=true;const e=dq("#download-video");const t=await p();e.style.display=t?"flex":"none";if(!t){return}u.aid=r.aid;u.cid=r.cid;const s=new a(r.aid);await s.fetchInfo();u.coverUrl=s.coverUrl.replace("http:","https:");l=await d.getAvailableFormats();[c]=l;u.qualityModel={value:c.displayName,items:l.map(e=>e.displayName)};u.formatChange();await u.checkBatch()})}return{widget:{content:`\n`,condition:p,success:f}}}})(); -onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/dpi-img.vue.min.js"] = (()=>{return(t,e)=>{const i=``;return{export:Object.assign({template:i},{props:["size","src","blur"],computed:{srcset(){if(!this.src||!this.size){return null}return getDpiSourceSet(this.src,this.size)},width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); +onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/dpi-img.vue.min.js"] = (()=>{return(t,s)=>{const e=``;return{export:Object.assign({template:e},{props:["size","src","blur","root","rootMargin","threshold"],data(){return{srcset:null,actualSrc:null}},methods:{calcSrc(){if(!this.src||!this.size){return null}const t=this.src.substring(this.src.lastIndexOf(".")+1);this.srcset=getDpiSourceSet(this.src,this.size,t);this.actualSrc=this.src}},mounted(){const t={root:this.root,rootMargin:this.rootMargin||"200px",threshold:this.threshold};console.log(t);const s=new IntersectionObserver(t=>{t.forEach(t=>{if(t.isIntersecting){this.calcSrc();s.disconnect()}})},t);s.observe(this.$el)},computed:{width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/expand-danmaku.min.js"] = (()=>{return(e,a)=>{if(typeof isEmbeddedPlayer!=="undefined"&&isEmbeddedPlayer()){return}Observer.videoChange(async()=>{const e=await SpinQuery.select(".bui-collapse-wrap");if(e&&e.classList.contains("bui-collapse-wrap-folded")){const e=await SpinQuery.select(".bui-collapse-header");e.click()}})}})(); onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/expand-description.min.css"] = `.play-up-info .play-up-self,.video-desc .info{height:auto!important}.play-up-info .play-up-self-btn,.video-desc .btn{display:none!important}`; onlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/min/expand-description.min.js"] = (()=>{return(e,p)=>{p.applyStyle("expandDescriptionStyle")}})(); diff --git a/min/bundle.json b/min/bundle.json index eff057ef4..e83851e87 100644 --- a/min/bundle.json +++ b/min/bundle.json @@ -47,7 +47,7 @@ "download-video.min.css": "1183440AB062DD7C26E68440F4FE4187395E9CFBA671497C362282F0CFC6090A", "download-video.min.html": "4311ABAF2886EB02B1003EA864DD605B113CDB05FF04C3A6882AD931F320D216", "download-video.min.js": "3413706B68FF52C6BC592187D39BFC1046178AE62D56D41E533D30A4780BC49F", - "dpi-img.vue.min.js": "D4833A242EBDD84834B11DB4CEB68B8807BDFC9693C3E1AAE73071986FE26F78", + "dpi-img.vue.min.js": "4C6526A23D9D19C2731722313FB933336D888A9CF2C08259B051DA0CD03A7975", "expand-danmaku.min.js": "B21658C40085AEA8DC49652AE62EB8610BB2EBEAF7A9C9AF69EF3B11E08EEC8D", "expand-description.min.css": "58C7710A50521B80F7D872BDC4C652610D84C4FABC6874BA66DA37B4F8759224", "expand-description.min.js": "A56857AD6B1C9F431B233D188E857D30DD5A2EB644986DE32A21280B1B7BC7A7", diff --git a/min/bundle.zip b/min/bundle.zip index f944bb788c4370e219cc3fd41d966817c6b3573f..74fbe6840255a4e843f3eb8ea8ed61b5f5bff5a4 100644 GIT binary patch delta 2334 zcmZ8h3s4mI89#OrTn-Pt+dqd;FXWPp962sRJ4u8=LB(oPgN{?o*ic#a7Vg45%5!)tlY@1BlsGTuGw4K_t(}qsf^xHdwrZ@B5 zx8M8u|E^!Fc=dY4#!U&ExHtLhJYT+Q^_Fp-CrBiiLXbp|OfdEMI4@+sU?Pq3SI_64 ze}gv|-r&KigxRU8qj+9e4hB>$Tfvel;i+Uv*6JnSN^GnWJP8VJR0*>xo%T>LsM+Ia znG~w^28hr+Aw~5BeQtZD(=BOIjw2jWwE9pWtcGM&(Fz0gKA-cRzmOawBN3-x(L6!7 zS{RlkpS&_8BSR7#i{d$G#hS;fy2#$8)>o@q$Q!85nPmASRa+WxD-Go}Id+%b@p!(Y z=sO|BE5;H@uy1f`_qdahC!OligY^MTaZ|3}MGWh;6~_GNUrzlmUgLdcoNjEi7tEQn zw!!Y4EIqC=Nk)p~4b;q_PjUHzl)0lQ9z`tyl@)#di8#63#@D{%$5TpsD_bsHl?8*+uvQ8nzlHq(J*~{fl_+?xl`ZBIYXn5xLM9&C$#S`H4W8Y}%7m33 z!BC?pZWZ&ISO(;Ef|zQU{M}iPOFP*T?%i$3+QsJc-|P^ucDrChV<$_+mR;ojcWpSd ziEZi&fRQ2_jMPJ?Pd&5Mp+uf-tV~`jq0+6+?l?(jMH)&PMLhW6t>qX zgM^=9jgFNU5PhBfn449J8#?X&IdVJLJU)F*3R){u(lIwm#q8*yV!mF3kq&ZIQ-xa{ zHjKsimwDR`-x3_l@?`(Yh!gB5cZ>rk|Z@NYiGF9=Uvy~t?r z=08oNh%ynE_b^+sy)wqau^q%o?WBN7UN}3+D8rAsPF5rwYak7MPvce}kPct_juF@1 zHfG>}EDo z^JSyKFV%YGyxNf0jf5sQoS6NhVDhVE`^!mlgvMK?8J;CW>CP~TR0 zA@#6lxD_wzcor`9Q1g3znCPKVz8OLBUQ#~20UP&HLDzqYQ#y_|;qG3xkndepE z@G)*isYLfBIQyuXwV#@C?f2$Pyw*p~?tC7jtoUsobMl+7m~r<{W-F#PQRWZz(?mYI zYQ~By6z%zbmTPkT*=$hdkfH?W0&DS9_mkSR)wdoHbTrW@N}8##@qU(>GR|3aqoB_R zSCm=t7H1K~$#-WcPb9G-g=7z2>Ljr=KqW1hf>#D;8~>GTK_JOu!$cRGj(-lYOzvF) zY5Um%{?jxImYXay;oncYve$|;2WZg4``MG+n$kFNbH0W4We?Soc7UAbZI83x*=m`F z@&jabqebUf<1e>Q*ZF*>&RNLKIU3hJF-k6C?Z`h!;&WeO#X-6f1Gmskm>>L)1rJYH zthjTK+}$z5afmjfNQCbY^?YeMMh~$?{NkA+PFclFqzzKf&pr~Ptf=T`W+;PH(;gRI z8Dxt%=My@%;>sX%CY_lh8dM)H9iY?l*buV`4RyrOUiK;R##a%KyS)_~hv>y)n~pP4 z+sjP2yjy(mwE5dH<1i~pOXv{|nn&>~d2-Mf48`^jwSA&!x<8GC0nq@do$ll4VRHY> z5qxx*&7C@MoJ@m~8XIld$?ut5Jw+xb^k-6igf`}@b0Va(qKF9Hn%H_boD-)%aA{2! z@WB!4PW?YHWtcYfbUGFf(?FYNGJI=gS;*T&6N~N7Ry&*iz^Y_F$_%lmbMI#SZJ1Kb zo(|r#HvRt8cIWw&Dx|JZJ zBUJ49QOf+^6%4_j(gV6n8vF&Bp|qM-YTg))_O1snj?p7;(J(YdUPJ5g*DuI5Uf|KmL0zXvLV7uk5CZBQN@qER2!74DQcf}AtQHB~tr8);ff}2{-zD#m7MSStN5srCc4d!QL9pOOt?}+18}pF0=*Iw)T%Un zR!)XKG~1wGihGTu!w_&whvy+0G*!r*k0MZncxZtd`3u!rT;9q#e^y+w5)r?d{pVUp zi`O@EgK-O$mq_8Og|KessrD|y1w}^b@mv)*Iy)JORjh9^p}va3g%{J&t;pf05m?P~ z&m<&PQ&_*%^W9aZQDGT4SHPj|)toFj6=xL}^AdP%p$UTLN=)BEH!N_!=57>^g>`8uq(!4##UK+)e6nS1n61IU+}v@@h85$=)8Sr{AS% z$luCY_coFj&d-%~&)9~|QEU^Po?y*ZZv5g_9`deK#Me@QG6gS;s^wDK)0CH3;ZZtj zYPmG;JY28k@ef!nt1^r$amqseh^nJNkH~y}$qY@_XJi=B)yNdETe+fjb>uJpl`rGV zPvrjCS4S@izph1Z9mkydDPFDTJ?|+(ZauftQYx!5m!=@z!u6c1=j?yi;a)v6`SBMr z;t$Ban7NH9Q?kEL>+e`!<2H6oKZ38fQIt6SxD3y4Wj_=b@@7LD*tGa0;u@5tpOTS( zMkdEK*cH>EGdSD8b3Sq&@^&sH;W84oQ?zjXN7QZS6_37(o7=hRjoldDNN);z?jWs^ z_ZH=ZW|rzUL95C(>az@K(A&rlE=?3D){0sza?$$YjVA6j-W6$0+$;6Nt|kuong$P= zIK@Mz{|-K{eGyvZP1FWDsv2w2>O7xrPqksA7H?U!109X_E%-sP_SpqbF2cZO4mW0# zBK?rpOd+DBLyI^&$2`%@6$JI*elx`gPwpV1g{AW!*wDh2B>2GF=3u-R?zZqaAS*AC z9!)x(D%-Sd`BKy3T$Hx(eO)W$P3GD7DjNLIZR4A?+bC2R9Hc1G!tWs%+RAc$D3-MH zyaHZYk2%uvrnAGw#!P*-*+H11o!r8c-DuxQVa^i{=u}vwP`RX)OINp( zzZ88`@z3F9ttsThQ`^};{TNc)IpMjxu(dNu1~6@}`0^lQ%a}i!4tBZWhY=k#MV%K! zD)UOC(VXqbSH?z7-cVAl2sNY`4NH^l=(9ZTD$vACis?AGJK&^7ql* NMK8F%`!Vq({sD%%Ug7`% diff --git a/min/dpi-img.vue.min.js b/min/dpi-img.vue.min.js index f86fa3fae..0d2bd1a6f 100644 --- a/min/dpi-img.vue.min.js +++ b/min/dpi-img.vue.min.js @@ -1 +1 @@ -(()=>{return(t,e)=>{const i=``;return{export:Object.assign({template:i},{props:["size","src","blur"],computed:{srcset(){if(!this.src||!this.size){return null}return getDpiSourceSet(this.src,this.size)},width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); \ No newline at end of file +(()=>{return(t,s)=>{const e=``;return{export:Object.assign({template:e},{props:["size","src","blur","root","rootMargin","threshold"],data(){return{srcset:null,actualSrc:null}},methods:{calcSrc(){if(!this.src||!this.size){return null}const t=this.src.substring(this.src.lastIndexOf(".")+1);this.srcset=getDpiSourceSet(this.src,this.size,t);this.actualSrc=this.src}},mounted(){const t={root:this.root,rootMargin:this.rootMargin||"200px",threshold:this.threshold};console.log(t);const s=new IntersectionObserver(t=>{t.forEach(t=>{if(t.isIntersecting){this.calcSrc();s.disconnect()}})},t);s.observe(this.$el)},computed:{width(){if(typeof this.size==="object"&&"width"in this.size){return this.size.width}return null},height(){if(typeof this.size==="object"&&"height"in this.size){return this.size.height}return null}}})}}})(); \ No newline at end of file diff --git a/src/style/dpi-img.vue b/src/style/dpi-img.vue index 159ce816a..8e426ea9e 100644 --- a/src/style/dpi-img.vue +++ b/src/style/dpi-img.vue @@ -1,17 +1,44 @@