Bilibili-Evolved/min/video-dash.min.js

1 line
1.7 KiB
JavaScript

(()=>{return(t,e)=>{const a=t=>{return{url:t.downloadUrl,backupUrls:t.backupUrls,length:t.duration,size:Math.trunc(t.bandWidth*t.duration/8)}};const r=e=>{console.log(e.videoDashes);const r=(()=>{const a=e=>e.videoCodec===t.downloadVideoDashCodec;if(e.videoDashes.some(a)){return e.videoDashes.filter(a).sort(ascendingSort(t=>t.bandWidth))[0]}else{return e.videoDashes.sort(ascendingSort(t=>t.bandWidth))[0]}})();const o=e.audioDashes.sort(descendingSort(t=>t.bandWidth))[0];return[a(r),a(o)]};const o=async(t,a)=>{const r=await Ajax.getJsonWithCredentials(t);const o=r.data||r.result||r;if(r.code!==0||!o.dash){throw new Error("DASH api failed")}const d=o.accept_quality;if(!d.includes(a)){throw new Error("没有找到请求的清晰度")}if(o.quality!==a){const{throwQualityError:t}=await e.importAsync("quality-errors");t(a)}const s=o.accept_description;const c=s[d.indexOf(a)];const n=o.dash.duration;const i=o.dash.video.filter(t=>t.id===a).map(t=>{const e=(()=>{switch(t.codecid){case 12:return"HEVC/H.265";default:case 7:return"AVC/H.264"}})();const r={quality:a,qualityText:c,width:t.width,height:t.height,codecs:t.codecs,codecId:t.codecid,bandWidth:t.bandwidth,frameRate:t.frameRate,backupUrls:(t.backupUrl||t.backup_url||[]).forEach(t=>t.replace("http:","https:")),downloadUrl:(t.baseUrl||t.base_url||"").replace("http:","https:"),duration:n,videoCodec:e};return r});const h=o.dash.audio.map(t=>{return{bandWidth:t.bandwidth,codecs:t.codecs,codecId:t.codecid,backupUrls:(t.backupUrl||t.backup_url||[]).forEach(t=>t.replace("http:","https:")),downloadUrl:(t.baseUrl||t.base_url||"").replace("http:","https:"),duration:n}});return{videoDashes:i,audioDashes:h}};return{export:{getDashInfo:o,dashToFragments:r}}}})();