Bilibili-Evolved/min/video-info.min.js
2021-10-26 13:22:15 +08:00

1 line
4.3 KiB
JavaScript

(()=>(i,t)=>{function e(i,t,e){if(t in i){Object.defineProperty(i,t,{value:e,enumerable:true,configurable:true,writable:true})}else{i[t]=e}return i}class s{constructor(i,t){this.aid=i;this.cid=t;e(this,"jsonDanmakus",[])}get xmlDanmakus(){return this.jsonDanmakus.map((i=>{var t,e,s,o,a,n,d,r,c,h,l,u;return{content:i.content,time:i.progress?(i.progress/1e3).toString():"0",type:(t=(e=i.mode)===null||e===void 0?void 0:e.toString())!==null&&t!==void 0?t:"1",fontSize:(s=(o=i.fontsize)===null||o===void 0?void 0:o.toString())!==null&&s!==void 0?s:"25",color:(a=(n=i.color)===null||n===void 0?void 0:n.toString())!==null&&a!==void 0?a:"16777215",timeStamp:(d=(r=i.ctime)===null||r===void 0?void 0:r.toString())!==null&&d!==void 0?d:"0",pool:(c=(h=i.pool)===null||h===void 0?void 0:h.toString())!==null&&c!==void 0?c:"0",userHash:(l=i.midHash)!==null&&l!==void 0?l:"0",rowId:(u=i.idStr)!==null&&u!==void 0?u:"0"}}))}async fetchInfo(){const{decodeDanmakuSegment:i,decodeDanmakuView:e}=await t.importAsync("danmaku-segment");const s=async i=>{const t=await fetch(i);return t.blob()};const o=await s(`https://api.bilibili.com/x/v2/dm/web/view?type=1&oid=${this.cid}&pid=${this.aid}`);if(!o){throw new Error(`获取弹幕信息失败`)}const a=await e(o);const{total:n}=a.dmSge;if(n===undefined){throw new Error(`获取弹幕分页数失败: ${JSON.stringify(_.omit(a,"flag"))}`)}console.log("segment count =",n);const d=await Promise.all(new Array(n).fill(0).map((async(t,e)=>{var o;const a=await s(`https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid=${this.cid}&pid=${this.aid}&segment_index=${e+1}`);if(!a){logError(new Error(`弹幕片段${e+1}下载失败`));return[]}console.log(`received blob for segment ${e+1}`,a);const n=await i(a);return(o=n.elems)!==null&&o!==void 0?o:[]})));this.jsonDanmakus=d.flat().sort(ascendingSort((i=>i.progress)));return this}}class o{constructor(i){e(this,"aid",void 0);e(this,"bvid",void 0);e(this,"cid",void 0);e(this,"pageCount",void 0);e(this,"duration",void 0);e(this,"coverUrl",void 0);e(this,"tagId",void 0);e(this,"tagName",void 0);e(this,"title",void 0);e(this,"description",void 0);e(this,"createTime",void 0);e(this,"publishTime",void 0);e(this,"up",void 0);e(this,"pages",void 0);e(this,"danmaku",void 0);e(this,"subtitles",void 0);this.aid=i}async fetchInfo(){let i;if(this.cid){i=`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}&cid=${this.cid}`}else{i=`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}`}const t=JSON.parse(await Ajax.getText(i));if(t.code!==0){throw new Error(`${t.message}: aid = ${this.aid}, cid = ${this.cid}, url = ${document.URL}`)}const e=t.data;this.cid=e.cid;this.bvid=e.bvid;this.pageCount=e.videos;this.duration=e.duration;this.createTime=e.ctime*1e3;this.publishTime=e.pubtime*1e3;this.coverUrl=e.pic.replace("http:","https:");this.tagId=e.tid;this.tagName=e.tname;this.title=e.title;this.description=e.desc;this.up={uid:e.owner.mid,name:e.owner.name,faceUrl:e.owner.face.replace("http:","https:")};this.pages=e.pages.map((i=>({cid:i.cid,title:i.part,pageNumber:i.page})));this.subtitles=e.subtitle.list.map((i=>({id:i.id,languageCode:i.lan,language:i.lan_doc,url:i.subtitle_url.replace("http:","https:")})));return this}async fetchDanmaku(){this.danmaku=new s(this.aid,this.cid);await this.danmaku.fetchInfo();return this}}class a{constructor(i,t){e(this,"text",void 0);e(this,"p",void 0);this.text=i;this.p=t}}class n{constructor(i){this.cid=i;e(this,"rawXML",void 0)}async fetchInfo(){console.warn("Deprecated warning: DanmakuInfo is deprecated, use JsonDanmaku instead.");const i=await Ajax.getText(`https://api.bilibili.com/x/v1/dm/list.so?oid=${this.cid}`);this.rawXML=i;return this}}class d{constructor(i){e(this,"ep",void 0);e(this,"videos",void 0);e(this,"title",void 0);e(this,"cover",void 0);e(this,"squareCover",void 0);e(this,"aid",void 0);e(this,"cid",void 0);this.ep=i;this.videos=[]}async fetchInfo(){const i=await Ajax.getText(`https://www.bilibili.com/bangumi/play/ep${this.ep}/`);const t=JSON.parse(i.match(/window\.__INITIAL_STATE__=(.*);\(function\(\){/)[1]);this.title=t.mediaInfo.title;this.cover=t.mediaInfo.cover;this.squareCover=t.mediaInfo.square_cover;this.aid=t.epInfo.aid;this.cid=t.epInfo.cid;this.videos=t.epList.map((async i=>({title:i.index_title,aid:i.aid,cid:i.cid,info:await new o(i.aid).fetchInfo()})));return this}}return{export:{VideoInfo:o,BangumiInfo:d,Danmaku:a,DanmakuInfo:n,JsonDanmaku:s}}})();