mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
3.5 KiB
JavaScript
1 line
3.5 KiB
JavaScript
(()=>(t,i)=>{function e(t,i,e){if(i in t){Object.defineProperty(t,i,{value:e,enumerable:true,configurable:true,writable:true})}else{t[i]=e}return t}class s{constructor(t,i){this.duration=t;this.cid=i;e(this,"jsonDanmakus",[])}get segmentCount(){return Math.ceil(this.duration/s.SegmentSize)}get xmlDanmakus(){return this.jsonDanmakus.map((t=>({content:t.content,time:t.progress.toString(),type:t.attr.toString(),fontSize:t.fontsize.toString(),color:t.color.toString(),timeStamp:t.ctime.toString(),pool:t.pool.toString(),userHash:t.midHash,rowId:t.idStr})))}async fetchInfo(){const{decodeDanmakuSegment:t}=await i.importAsync("danmaku-segment");const e=this.segmentCount;const s=await Promise.all(new Array(e).fill(0).map((async(i,e)=>{const s=await Ajax.getBlob(`https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid=${this.cid}&segment_index=${e+1}`);const a=await t(s);return a.elems})));this.jsonDanmakus=s.flat().sort(ascendingSort((t=>t.progress)))}}e(s,"SegmentSize",6*60);class a{constructor(t){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=t}async fetchInfo(){let t;if(this.cid){t=`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}&cid=${this.cid}`}else{t=`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}`}const i=JSON.parse(await Ajax.getText(t));if(i.code!==0){throw new Error(`${i.message}: aid = ${this.aid}, cid = ${this.cid}, url = ${document.URL}`)}const e=i.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((t=>({cid:t.cid,title:t.part,pageNumber:t.page})));this.subtitles=e.subtitle.list.map((t=>({id:t.id,languageCode:t.lan,language:t.lan_doc,url:t.subtitle_url.replace("http:","https:")})));return this}async fetchDanmaku(){this.danmaku=new s(this.duration,this.cid);await this.danmaku.fetchInfo();return this}}class o{constructor(t,i){e(this,"text",void 0);e(this,"p",void 0);this.text=t;this.p=i}}class n{constructor(t){this.cid=t;e(this,"rawXML",void 0)}async fetchInfo(){console.warn("Deprecated warning: DanmakuInfo is deprecated, use JsonDanmaku instead.");const t=await Ajax.getText(`https://api.bilibili.com/x/v1/dm/list.so?oid=${this.cid}`);this.rawXML=t}}class d{constructor(t){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=t;this.videos=[]}async fetchInfo(){const t=await Ajax.getText(`https://www.bilibili.com/bangumi/play/ep${this.ep}/`);const i=JSON.parse(t.match(/window\.__INITIAL_STATE__=(.*);\(function\(\){/)[1]);this.title=i.mediaInfo.title;this.cover=i.mediaInfo.cover;this.squareCover=i.mediaInfo.square_cover;this.aid=i.epInfo.aid;this.cid=i.epInfo.cid;this.videos=i.epList.map((async t=>({title:t.index_title,aid:t.aid,cid:t.cid,info:await new a(t.aid).fetchInfo()})));return this}}return{export:{VideoInfo:a,BangumiInfo:d,Danmaku:o,DanmakuInfo:n,JsonDanmaku:s}}})(); |