mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Fix ass transforming
This commit is contained in:
parent
65edb6fe85
commit
b2f76627c9
2
.babelrc
2
.babelrc
@ -10,6 +10,8 @@
|
||||
],
|
||||
"plugins": [
|
||||
"@babel/plugin-proposal-class-properties",
|
||||
"@babel/plugin-proposal-optional-chaining",
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator",
|
||||
"./builder/node/@babel/plugin-top-level-return"
|
||||
]
|
||||
}
|
||||
2
min/download-danmaku.min.js
vendored
2
min/download-danmaku.min.js
vendored
@ -1 +1 @@
|
||||
(()=>(n,t)=>{const{getFriendlyTitle:e}=t.import("title");const{DanmakuConverter:a,XmlDanmaku:o}=t.import("danmaku-converter");const s=async()=>{const n=e();const t={font:"微软雅黑",alpha:.4,duration:n=>{switch(n.type){case 4:case 5:return 4;default:return 6}},blockTypes:[7,8],resolution:{x:1920,y:1080},bottomMarginPercent:.15,bold:false};let a={...t,title:n};try{await loadDanmakuSettingsPanel();const n=localStorage.getItem("bilibili_player_settings");if(n){const t=JSON.parse(n);const e=(n,e)=>_.get(t,`setting_config.${n}`,e);a.blockTypes=(()=>{const n=[];const e={scroll:[1,2,3],top:[5],bottom:[4],color:["color"]};for(const[a,o]of Object.entries(e)){if(_.get(t,`block.type_${a}`,true)===false){n.push(...o)}}return n.concat(7,8)})();a.bold=e("bold",false);a.alpha=_.clamp(1-parseFloat(e("opacity","0.4")),0,1);const o=1.4-.4*e("fontsize",1);a.resolution={x:Math.round(1920*o),y:Math.round(1080*o)};a.duration=(()=>{const n=18-3*e("speedplus",0);return t=>{switch(t.type){case 4:case 5:return 4;default:return n}}})();const s=e("danmakuArea",0);a.bottomMarginPercent=s>=100?0:s/100;if(a.bottomMarginPercent===0&&e("preventshade",false)){a.bottomMarginPercent=.15}const c=_.get(t,"block.list",[]);a.blockFilter=n=>{for(const t of c){if(!t.s){continue}switch(t.t){case"keyword":{if(n.content.includes(t.v)){return false}break}case"regexp":{if(new RegExp(t.v).test(n.content)){return false}break}case"user":{if(n.userHash===t.v){return false}break}}}return true}}else{console.warn("[弹幕转换] 未找到播放器设置");a={...a,...t}}a.font=dq(".bilibili-player-video-danmaku-setting-right-font .bui-select-result").innerText}catch(n){logError(n);a={...a,...t}}for(const[n,e]of Object.entries(a)){if(e===undefined||e===null){console.warn("danmaku config invalid for key",n,", value =",e);a[n]=t[e]}}console.log(a);return a};async function c(n){const t=new a(await s());const e=t.xmlStringToAssDocument(n);return e.generateAss()}async function i(n){const c=e();let i;const r=(unsafeWindow||window).aid;const l=parseInt((unsafeWindow||window).cid);const{DanmakuInfo:u,VideoInfo:d}=await t.importAsync("video-info");switch(n){case"xml":{const n=new u(l);await n.fetchInfo();i=new Blob([n.rawXML],{type:"text/xml"});break}case"json":{const n=await new d(r).fetchInfo();const t=(await n.fetchDanmaku()).danmaku;i=new Blob([JSON.stringify(t.jsonDanmakus)],{type:"text/json"});break}case"ass":{const n=await new d(r).fetchInfo();const t=(await n.fetchDanmaku()).danmaku;const e=new a(await s());const c=e.xmlDanmakuToAssDocument(t.xmlDanmakus.map((n=>new o(n))));i=new Blob([c.generateAss()],{type:"text/ass"});break}}const f=URL.createObjectURL(i);const m=dq("#danmaku-link");const b=m.getAttribute("href");if(b){URL.revokeObjectURL(b)}m.setAttribute("download",`${c}.${n}`);m.setAttribute("href",f);m.click()}return{export:{downloadDanmaku:i,convertToAss:c,getUserDanmakuConfig:s},widget:{content:`\n<a id="danmaku-link" style="display:none"></a>\n<button\n class="gui-settings-flat-button"\n id="download-danmaku-xml">\n<i class="icon-danmaku"></i>\n<span>下载弹幕<span>(XML)</span></span>\n</button>\n<button\n class="gui-settings-flat-button"\n id="download-danmaku-json">\n<i class="icon-danmaku"></i>\n<span>下载弹幕<span>(JSON)</span></span>\n</button>\n<button\n class="gui-settings-flat-button"\n id="download-danmaku-ass">\n<i class="icon-danmaku"></i>\n<span>下载弹幕<span>(ASS)</span></span>\n</button>\n`,condition:async()=>{let n=await SpinQuery.select((()=>(unsafeWindow||window).cid));return Boolean(n)},success:()=>{const n=["xml","json","ass"];const t=n.map((n=>dq(`#download-danmaku-${n}`)));const e=(n,e)=>{n.addEventListener("click",(async()=>{try{t.forEach((n=>n.disabled=true));await i(e)}catch(n){logError(n)}finally{t.forEach((n=>n.disabled=false))}}))};n.forEach(((n,a)=>{e(t[a],n)}))}}}})();
|
||||
(()=>(n,t)=>{const{getFriendlyTitle:e}=t.import("title");const{DanmakuConverter:a,XmlDanmaku:o}=t.import("danmaku-converter");const s=async()=>{const n=e();const t={font:"微软雅黑",alpha:.4,duration:n=>{switch(n.type){case 4:case 5:return 4;default:return 6}},blockTypes:[7,8],resolution:{x:1920,y:1080},bottomMarginPercent:.15,bold:false};let a={...t,title:n};try{await loadDanmakuSettingsPanel();const n=localStorage.getItem("bilibili_player_settings");if(n){const t=JSON.parse(n);const e=(n,e)=>_.get(t,`setting_config.${n}`,e);a.blockTypes=(()=>{const n=[];const e={scroll:[1,2,3],top:[5],bottom:[4],color:["color"]};for(const[a,o]of Object.entries(e)){if(_.get(t,`block.type_${a}`,true)===false){n.push(...o)}}return n.concat(7,8)})();a.bold=e("bold",false);a.alpha=_.clamp(1-parseFloat(e("opacity","0.4")),0,1);const o=1.4-.4*e("fontsize",1);a.resolution={x:Math.round(1920*o),y:Math.round(1080*o)};a.duration=(()=>{const n=18-3*e("speedplus",0);return t=>{switch(t.type){case 4:case 5:return 4;default:return n}}})();const s=e("danmakuArea",0);a.bottomMarginPercent=s>=100?0:s/100;if(a.bottomMarginPercent===0&&e("preventshade",false)){a.bottomMarginPercent=.15}const c=_.get(t,"block.list",[]);a.blockFilter=n=>{for(const t of c){if(!t.s){continue}switch(t.t){case"keyword":{if(n.content.includes(t.v)){return false}break}case"regexp":{if(new RegExp(t.v).test(n.content)){return false}break}case"user":{if(n.userHash===t.v){return false}break}}}return true}}else{console.warn("[弹幕转换] 未找到播放器设置");a={...a,...t}}a.font=dq(".bilibili-player-video-danmaku-setting-right-font .bui-select-result").innerText}catch(n){logError(n);a={...a,...t}}for(const[n,e]of Object.entries(a)){if(e===undefined||e===null){console.warn("danmaku config invalid for key",n,", value =",e);a[n]=t[e]}}console.log(a);return a};async function c(n){const t=new a(await s());const e=t.xmlStringToAssDocument(n);return e.generateAss()}async function i(n){const c=e();let i;const r=(unsafeWindow||window).aid;const l=parseInt((unsafeWindow||window).cid);const{DanmakuInfo:u,JsonDanmaku:d}=await t.importAsync("video-info");switch(n){case"xml":{const n=new u(l);await n.fetchInfo();i=new Blob([n.rawXML],{type:"text/xml"});break}case"json":{const n=await new d(r,l).fetchInfo();i=new Blob([JSON.stringify(n.jsonDanmakus)],{type:"text/json"});break}case"ass":{const n=await new d(r,l).fetchInfo();const t=new a(await s());const e=t.xmlDanmakuToAssDocument(n.xmlDanmakus.map((n=>new o(n))));i=new Blob([e.generateAss()],{type:"text/ass"});break}}const f=URL.createObjectURL(i);const b=dq("#danmaku-link");const m=b.getAttribute("href");if(m){URL.revokeObjectURL(m)}b.setAttribute("download",`${c}.${n}`);b.setAttribute("href",f);b.click()}return{export:{downloadDanmaku:i,convertToAss:c,getUserDanmakuConfig:s},widget:{content:`\n<a id="danmaku-link" style="display:none"></a>\n<button\n class="gui-settings-flat-button"\n id="download-danmaku-xml">\n<i class="icon-danmaku"></i>\n<span>下载弹幕<span>(XML)</span></span>\n</button>\n<button\n class="gui-settings-flat-button"\n id="download-danmaku-json">\n<i class="icon-danmaku"></i>\n<span>下载弹幕<span>(JSON)</span></span>\n</button>\n<button\n class="gui-settings-flat-button"\n id="download-danmaku-ass">\n<i class="icon-danmaku"></i>\n<span>下载弹幕<span>(ASS)</span></span>\n</button>\n`,condition:async()=>{let n=await SpinQuery.select((()=>(unsafeWindow||window).cid));return Boolean(n)},success:()=>{const n=["xml","json","ass"];const t=n.map((n=>dq(`#download-danmaku-${n}`)));const e=(n,e)=>{n.addEventListener("click",(async()=>{try{t.forEach((n=>n.disabled=true));await i(e)}catch(n){logError(n)}finally{t.forEach((n=>n.disabled=false))}}))};n.forEach(((n,a)=>{e(t[a],n)}))}}}})();
|
||||
2
min/video-info.min.js
vendored
2
min/video-info.min.js
vendored
@ -1 +1 @@
|
||||
(()=>(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}}})();
|
||||
(()=>(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,a,o,n,d,r,c,h,l,u,v,p;return{content:i.content,time:(t=(e=i.progress)===null||e===void 0?void 0:e.toString())!==null&&t!==void 0?t:"0",type:(s=(a=i.mode)===null||a===void 0?void 0:a.toString())!==null&&s!==void 0?s:"1",fontSize:(o=(n=i.fontsize)===null||n===void 0?void 0:n.toString())!==null&&o!==void 0?o:"25",color:(d=(r=i.color)===null||r===void 0?void 0:r.toString())!==null&&d!==void 0?d:"16777215",timeStamp:(c=(h=i.ctime)===null||h===void 0?void 0:h.toString())!==null&&c!==void 0?c:"0",pool:(l=(u=i.pool)===null||u===void 0?void 0:u.toString())!==null&&l!==void 0?l:"0",userHash:(v=i.midHash)!==null&&v!==void 0?v:"0",rowId:(p=i.idStr)!==null&&p!==void 0?p:"0"}}))}async fetchInfo(){const{decodeDanmakuSegment:i,decodeDanmakuView:e}=await t.importAsync("danmaku-segment");const s=await e(await Ajax.getBlob(`https://api.bilibili.com/x/v2/dm/web/view?type=1&oid=${this.cid}&pid=${this.aid}`));const{total:a}=s.dmSge;if(a===undefined){throw new Error(`获取弹幕分页数失败: ${JSON.stringify(_.omit(s,"flag"))}`)}const o=await Promise.all(new Array(a).fill(0).map((async(t,e)=>{const s=await Ajax.getBlob(`https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid=${this.cid}&pid=${this.aid}&segment_index=${e+1}`);const a=await i(s);return a.elems})));this.jsonDanmakus=o.flat().sort(ascendingSort((i=>i.progress)));return this}}class a{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 o{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}}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 a(i.aid).fetchInfo()})));return this}}return{export:{VideoInfo:a,BangumiInfo:d,Danmaku:o,DanmakuInfo:n,JsonDanmaku:s}}})();
|
||||
@ -7,6 +7,8 @@
|
||||
"@babel/cli": "^7.12.1",
|
||||
"@babel/core": "^7.12.3",
|
||||
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
|
||||
"@babel/plugin-proposal-optional-chaining": "^7.12.1",
|
||||
"@babel/preset-typescript": "^7.12.1",
|
||||
"clean-css-cli": "^4.3.0",
|
||||
"html-minifier": "^4.0.0",
|
||||
|
||||
@ -301,6 +301,7 @@ export default {
|
||||
decodeDanmakuSegment,
|
||||
decodeDanmakuView,
|
||||
test: async (i: number) => {
|
||||
// const url = `https://api.bilibili.com/x/v2/dm/web/view?type=1&oid=157340456`
|
||||
const url = `https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid=157340456&pid=92150659&segment_index=${i}`
|
||||
const blob = await Ajax.getBlob(url)
|
||||
const result = await decodeDanmakuSegment(blob)
|
||||
|
||||
@ -163,7 +163,7 @@ export async function downloadDanmaku(type: DanmakuDownloadType) {
|
||||
let blob: Blob
|
||||
const aid = (unsafeWindow || window).aid!
|
||||
const cid = parseInt((unsafeWindow || window).cid!)
|
||||
const { DanmakuInfo, VideoInfo } = await import('./video-info')
|
||||
const { DanmakuInfo, JsonDanmaku } = await import('./video-info')
|
||||
switch (type) {
|
||||
case 'xml': {
|
||||
const danmaku = new DanmakuInfo(cid)
|
||||
@ -174,16 +174,14 @@ export async function downloadDanmaku(type: DanmakuDownloadType) {
|
||||
break
|
||||
}
|
||||
case 'json': {
|
||||
const video = await new VideoInfo(aid).fetchInfo()
|
||||
const danmaku = (await video.fetchDanmaku()).danmaku
|
||||
const danmaku = await new JsonDanmaku(aid, cid).fetchInfo()
|
||||
blob = new Blob([JSON.stringify(danmaku.jsonDanmakus)], {
|
||||
type: 'text/json'
|
||||
})
|
||||
break
|
||||
}
|
||||
case 'ass': {
|
||||
const video = await new VideoInfo(aid).fetchInfo()
|
||||
const danmaku = (await video.fetchDanmaku()).danmaku
|
||||
const danmaku = await new JsonDanmaku(aid, cid).fetchInfo()
|
||||
const converter = new DanmakuConverter(await getUserDanmakuConfig())
|
||||
const assDocument = converter.xmlDanmakuToAssDocument(danmaku.xmlDanmakus.map(x => new XmlDanmaku(x)))
|
||||
blob = new Blob([assDocument.generateAss()], {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
export class JsonDanmaku {
|
||||
static SegmentSize = 6 * 60
|
||||
// static SegmentSize = 6 * 60
|
||||
public jsonDanmakus: {
|
||||
id: number
|
||||
idStr: string
|
||||
@ -16,36 +16,43 @@ export class JsonDanmaku {
|
||||
attr: number
|
||||
}[] = []
|
||||
constructor(
|
||||
public duration: number,
|
||||
public cid: number,
|
||||
public aid: number | string,
|
||||
public cid: number | string,
|
||||
) { }
|
||||
get segmentCount() {
|
||||
return Math.ceil(this.duration / JsonDanmaku.SegmentSize)
|
||||
}
|
||||
// get segmentCount() {
|
||||
// return Math.ceil(this.duration / JsonDanmaku.SegmentSize)
|
||||
// }
|
||||
get xmlDanmakus() {
|
||||
return this.jsonDanmakus.map(json => {
|
||||
return {
|
||||
content: json.content,
|
||||
time: json.progress.toString(),
|
||||
type: json.attr.toString(),
|
||||
fontSize: json.fontsize.toString(),
|
||||
color: json.color.toString(),
|
||||
timeStamp: json.ctime.toString(),
|
||||
pool: json.pool.toString(),
|
||||
userHash: json.midHash,
|
||||
rowId: json.idStr,
|
||||
time: json.progress?.toString() ?? '0',
|
||||
type: json.mode?.toString() ?? '1',
|
||||
fontSize: json.fontsize?.toString() ?? '25',
|
||||
color: json.color?.toString() ?? '16777215',
|
||||
timeStamp: json.ctime?.toString() ?? '0',
|
||||
pool: json.pool?.toString() ??'0',
|
||||
userHash: json.midHash ?? '0',
|
||||
rowId: json.idStr ?? '0',
|
||||
}
|
||||
})
|
||||
}
|
||||
async fetchInfo() {
|
||||
const { decodeDanmakuSegment } = await import('./danmaku-converter/danmaku-segment')
|
||||
const count = this.segmentCount
|
||||
const segments = await Promise.all(new Array(count).fill(0).map(async (_, index) => {
|
||||
const blob = await Ajax.getBlob(`https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid=${this.cid}&segment_index=${index + 1}`)
|
||||
const { decodeDanmakuSegment, decodeDanmakuView } = await import('./danmaku-converter/danmaku-segment')
|
||||
const view = await decodeDanmakuView(
|
||||
await Ajax.getBlob(`https://api.bilibili.com/x/v2/dm/web/view?type=1&oid=${this.cid}&pid=${this.aid}`)
|
||||
)
|
||||
const { total } = view.dmSge
|
||||
if (total === undefined) {
|
||||
throw new Error(`获取弹幕分页数失败: ${JSON.stringify(_.omit(view, 'flag'))}`)
|
||||
}
|
||||
const segments = await Promise.all(new Array(total).fill(0).map(async (_, index) => {
|
||||
const blob = await Ajax.getBlob(`https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid=${this.cid}&pid=${this.aid}&segment_index=${index + 1}`)
|
||||
const result = await decodeDanmakuSegment(blob)
|
||||
return result.elems
|
||||
}))
|
||||
this.jsonDanmakus = segments.flat().sort(ascendingSort(it => it.progress))
|
||||
return this
|
||||
}
|
||||
}
|
||||
export class VideoInfo {
|
||||
@ -129,7 +136,7 @@ export class VideoInfo {
|
||||
return this
|
||||
}
|
||||
async fetchDanmaku() {
|
||||
this.danmaku = new JsonDanmaku(this.duration, this.cid)
|
||||
this.danmaku = new JsonDanmaku(this.aid, this.cid)
|
||||
await this.danmaku.fetchInfo()
|
||||
return this
|
||||
}
|
||||
|
||||
40
yarn.lock
40
yarn.lock
@ -120,7 +120,7 @@
|
||||
dependencies:
|
||||
"@babel/types" "^7.10.4"
|
||||
|
||||
"@babel/helper-plugin-utils@^7.10.4":
|
||||
"@babel/helper-plugin-utils@^7.10.4", "@babel/helper-plugin-utils@^7.8.0":
|
||||
version "7.10.4"
|
||||
resolved "https://registry.npm.taobao.org/@babel/helper-plugin-utils/download/@babel/helper-plugin-utils-7.10.4.tgz?cache=0&sync_timestamp=1593521089859&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40babel%2Fhelper-plugin-utils%2Fdownload%2F%40babel%2Fhelper-plugin-utils-7.10.4.tgz#2f75a831269d4f677de49986dff59927533cf375"
|
||||
integrity sha1-L3WoMSadT2d95JmG3/WZJ1M883U=
|
||||
@ -142,6 +142,13 @@
|
||||
dependencies:
|
||||
"@babel/types" "^7.12.1"
|
||||
|
||||
"@babel/helper-skip-transparent-expression-wrappers@^7.12.1":
|
||||
version "7.12.1"
|
||||
resolved "https://registry.npm.taobao.org/@babel/helper-skip-transparent-expression-wrappers/download/@babel/helper-skip-transparent-expression-wrappers-7.12.1.tgz?cache=0&sync_timestamp=1602802635520&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40babel%2Fhelper-skip-transparent-expression-wrappers%2Fdownload%2F%40babel%2Fhelper-skip-transparent-expression-wrappers-7.12.1.tgz#462dc63a7e435ade8468385c63d2b84cce4b3cbf"
|
||||
integrity sha1-Ri3GOn5DWt6EaDhcY9K4TM5LPL8=
|
||||
dependencies:
|
||||
"@babel/types" "^7.12.1"
|
||||
|
||||
"@babel/helper-split-export-declaration@^7.10.4", "@babel/helper-split-export-declaration@^7.11.0":
|
||||
version "7.11.0"
|
||||
resolved "https://registry.npm.taobao.org/@babel/helper-split-export-declaration/download/@babel/helper-split-export-declaration-7.11.0.tgz?cache=0&sync_timestamp=1596142786225&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40babel%2Fhelper-split-export-declaration%2Fdownload%2F%40babel%2Fhelper-split-export-declaration-7.11.0.tgz#f8a491244acf6a676158ac42072911ba83ad099f"
|
||||
@ -185,6 +192,37 @@
|
||||
"@babel/helper-create-class-features-plugin" "^7.12.1"
|
||||
"@babel/helper-plugin-utils" "^7.10.4"
|
||||
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator@^7.12.1":
|
||||
version "7.12.1"
|
||||
resolved "https://registry.npm.taobao.org/@babel/plugin-proposal-nullish-coalescing-operator/download/@babel/plugin-proposal-nullish-coalescing-operator-7.12.1.tgz?cache=0&sync_timestamp=1602802623075&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40babel%2Fplugin-proposal-nullish-coalescing-operator%2Fdownload%2F%40babel%2Fplugin-proposal-nullish-coalescing-operator-7.12.1.tgz#3ed4fff31c015e7f3f1467f190dbe545cd7b046c"
|
||||
integrity sha1-PtT/8xwBXn8/FGfxkNvlRc17BGw=
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.10.4"
|
||||
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.8.0"
|
||||
|
||||
"@babel/plugin-proposal-optional-chaining@^7.12.1":
|
||||
version "7.12.1"
|
||||
resolved "https://registry.npm.taobao.org/@babel/plugin-proposal-optional-chaining/download/@babel/plugin-proposal-optional-chaining-7.12.1.tgz?cache=0&sync_timestamp=1602802638922&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40babel%2Fplugin-proposal-optional-chaining%2Fdownload%2F%40babel%2Fplugin-proposal-optional-chaining-7.12.1.tgz#cce122203fc8a32794296fc377c6dedaf4363797"
|
||||
integrity sha1-zOEiID/IoyeUKW/Dd8be2vQ2N5c=
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.10.4"
|
||||
"@babel/helper-skip-transparent-expression-wrappers" "^7.12.1"
|
||||
"@babel/plugin-syntax-optional-chaining" "^7.8.0"
|
||||
|
||||
"@babel/plugin-syntax-nullish-coalescing-operator@^7.8.0":
|
||||
version "7.8.3"
|
||||
resolved "https://registry.npm.taobao.org/@babel/plugin-syntax-nullish-coalescing-operator/download/@babel/plugin-syntax-nullish-coalescing-operator-7.8.3.tgz#167ed70368886081f74b5c36c65a88c03b66d1a9"
|
||||
integrity sha1-Fn7XA2iIYIH3S1w2xlqIwDtm0ak=
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.8.0"
|
||||
|
||||
"@babel/plugin-syntax-optional-chaining@^7.8.0":
|
||||
version "7.8.3"
|
||||
resolved "https://registry.npm.taobao.org/@babel/plugin-syntax-optional-chaining/download/@babel/plugin-syntax-optional-chaining-7.8.3.tgz#4f69c2ab95167e0180cd5336613f8c5788f7d48a"
|
||||
integrity sha1-T2nCq5UWfgGAzVM2YT+MV4j31Io=
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.8.0"
|
||||
|
||||
"@babel/plugin-syntax-typescript@^7.12.1":
|
||||
version "7.12.1"
|
||||
resolved "https://registry.npm.taobao.org/@babel/plugin-syntax-typescript/download/@babel/plugin-syntax-typescript-7.12.1.tgz?cache=0&sync_timestamp=1602802626813&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40babel%2Fplugin-syntax-typescript%2Fdownload%2F%40babel%2Fplugin-syntax-typescript-7.12.1.tgz#460ba9d77077653803c3dd2e673f76d66b4029e5"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user