// 脚本引用 https://raw.githubusercontent.com/kokoryh/Sparkle/master/dist/bilibili.protobuf.request.js // Built at: 2025/9/21 11:20:58 function de(n){return typeof n!="object"||n===null?String(n):n instanceof Date?n.toISOString():n instanceof RegExp?n.toString():Array.isArray(n)?JSON.stringify(n):typeof n.toString=="function"&&n.toString!==Object.prototype.toString?n.toString():JSON.stringify(n)}var B=class n{static getInstance(e){let t="Surge";if(typeof $loon<"u")t="Loon";else if(typeof $task<"u")throw new Error("QuantumultX is not supported");return n.instances[t]||(n.instances[t]=n.classNames[t](e,t)),n.instances[t]}static classNames={Surge:(e,t)=>new C(e,t),Loon:(e,t)=>new te(e,t)};static instances={};className;name;logLevels={debug:1,info:2,warn:3,error:4,off:5};logLevel=this.logLevels.error;request;response;argument;_url;get url(){return this._url||(this._url=new URL(this.request.url)),this._url}constructor(e,t){this.className=t??"",this.name=e??"",this.init()}createProxy(e){return new Proxy(e,{get:this.getFn,set:this.setFn})}getFn(e,t,r){return Reflect.get(e,t,r)}setFn(e,t,r,i){return Reflect.set(e,t,r,i),!0}setName(e){this.name=e}getJSON(e){let t=this.getVal(e);return t?JSON.parse(t):null}setJSON(e,t){this.setVal(JSON.stringify(e),t)}logWithPrefix(e,t){console.log(`${e}${t.map(r=>de(r)).join(" | ")}`)}log(...e){this.logWithPrefix("",e)}debug(...e){this.logLevel>this.logLevels.debug||this.logWithPrefix("[DEBUG]",e)}info(...e){this.logLevel>this.logLevels.info||this.logWithPrefix("[INFO]",e)}warn(...e){this.logLevel>this.logLevels.warn||this.logWithPrefix("[WARN]",e)}error(...e){this.logLevel>this.logLevels.error||this.logWithPrefix("[ERROR]",e)}exit(){$done({})}},C=class n extends B{static propertyMap={bodyBytes:"body"};getFn(e,t,r){let i=n.propertyMap[t]||t;return super.getFn(e,i,r)}setFn(e,t,r,i){let s=n.propertyMap[t]||t;return super.setFn(e,s,r,i)}init(){typeof $request=="object"&&(this.request=this.createProxy($request)),typeof $response=="object"&&(this.response=this.createProxy($response)),typeof $argument=="string"&&(this.argument=JSON.parse($argument),"logLevel"in this.argument&&(this.logLevel=this.logLevels[this.argument.logLevel]??this.logLevels.error))}getVal(e){return $persistentStore.read(e)}setVal(e,t){return $persistentStore.write(e,t)}fetch(e){let{method:t,body:r,timeout:i=5,...s}=e;return new Promise((o,a)=>{$httpClient[t]({...s,body:r,"binary-mode":r instanceof Uint8Array,timeout:i},(c,u,p)=>{if(c)return a(c);let g=p instanceof Uint8Array?"bodyBytes":"body";o({status:u.status,headers:u.headers,[g]:p})})})}notify(e=this.name,t="",r="",i={}){let{openUrl:s,clipboard:o,mediaUrl:a,dismiss:c,sound:u=!0}=i,p={url:s,text:o,"media-url":a,"auto-dismiss":c,sound:u};s?p.action="open-url":o&&(p.action="clipboard"),$notification.post(e,t,r,p)}ungzip(e){return $utils.ungzip(e)}done(e){$done(e)}abort(){$done({abort:!0})}},te=class extends C{init(){super.init(),typeof $argument=="object"&&(this.argument=$argument,"logLevel"in this.argument&&(this.logLevel=this.logLevels[this.argument.logLevel]??this.logLevels.error))}fetch(e){return e.timeout=(e.timeout??5)*1e3,super.fetch(e)}notify(e=this.name,t="",r="",i={}){let{openUrl:s,mediaUrl:o,clipboard:a,delay:c}=i,u={openUrl:s,mediaUrl:o,clipboard:a};$notification.post(e,t,r,u,c)}abort(){$done()}};var w=B.getInstance();function P(n){let e=typeof n;if(e=="object"){if(Array.isArray(n))return"array";if(n===null)return"null"}return e}function he(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}var E="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),$=[];for(let n=0;n>4,o=s,i=2;break;case 2:t[r++]=(o&15)<<4|(s&60)>>2,o=s,i=3;break;case 3:t[r++]=(o&3)<<6|s,i=0;break}}if(i==1)throw Error("invalid base64 string.");return t.subarray(0,r)}function be(n){let e="",t=0,r,i=0;for(let s=0;s>2],i=(r&3)<<4,t=1;break;case 1:e+=E[i|r>>4],i=(r&15)<<2,t=2;break;case 2:e+=E[i|r>>6],e+=E[r&63],t=0;break}return t&&(e+=E[i],e+="=",t==1&&(e+="=")),e}var N;(function(n){n.symbol=Symbol.for("protobuf-ts/unknown"),n.onRead=(t,r,i,s,o)=>{(e(r)?r[n.symbol]:r[n.symbol]=[]).push({no:i,wireType:s,data:o})},n.onWrite=(t,r,i)=>{for(let{no:s,wireType:o,data:a}of n.list(r))i.tag(s,o).raw(a)},n.list=(t,r)=>{if(e(t)){let i=t[n.symbol];return r?i.filter(s=>s.no==r):i}return[]},n.last=(t,r)=>n.list(t,r).slice(-1)[0];let e=t=>t&&Array.isArray(t[n.symbol])})(N||(N={}));var l;(function(n){n[n.Varint=0]="Varint",n[n.Bit64=1]="Bit64",n[n.LengthDelimited=2]="LengthDelimited",n[n.StartGroup=3]="StartGroup",n[n.EndGroup=4]="EndGroup",n[n.Bit32=5]="Bit32"})(l||(l={}));function ye(){let n=0,e=0;for(let r=0;r<28;r+=7){let i=this.buf[this.pos++];if(n|=(i&127)<>4,(t&128)==0)return this.assertBounds(),[n,e];for(let r=3;r<=31;r+=7){let i=this.buf[this.pos++];if(e|=(i&127)<>>s,a=!(!(o>>>7)&&e==0),c=(a?o|128:o)&255;if(t.push(c),!a)return}let r=n>>>28&15|(e&7)<<4,i=e>>3!=0;if(t.push((i?r|128:r)&255),!!i){for(let s=3;s<31;s=s+7){let o=e>>>s,a=!!(o>>>7),c=(a?o|128:o)&255;if(t.push(c),!a)return}t.push(e>>>31&1)}}var M=65536*65536;function re(n){let e=n[0]=="-";e&&(n=n.slice(1));let t=1e6,r=0,i=0;function s(o,a){let c=Number(n.slice(o,a));i*=t,r=r*t+c,r>=M&&(i=i+(r/M|0),r=r%M)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),[e,r,i]}function j(n,e){if(e>>>0<=2097151)return""+(M*e+(n>>>0));let t=n&16777215,r=(n>>>24|e<<8)>>>0&16777215,i=e>>16&65535,s=t+r*6777216+i*6710656,o=r+i*8147497,a=i*2,c=1e7;s>=c&&(o+=Math.floor(s/c),s%=c),o>=c&&(a+=Math.floor(o/c),o%=c);function u(p,g){let d=p?String(p):"";return g?"0000000".slice(d.length)+d:d}return u(a,0)+u(o,a)+u(s,1)}function ne(n,e){if(n>=0){for(;n>127;)e.push(n&127|128),n=n>>>7;e.push(n)}else{for(let t=0;t<9;t++)e.push(n&127|128),n=n>>7;e.push(1)}}function we(){let n=this.buf[this.pos++],e=n&127;if((n&128)==0)return this.assertBounds(),e;if(n=this.buf[this.pos++],e|=(n&127)<<7,(n&128)==0)return this.assertBounds(),e;if(n=this.buf[this.pos++],e|=(n&127)<<14,(n&128)==0)return this.assertBounds(),e;if(n=this.buf[this.pos++],e|=(n&127)<<21,(n&128)==0)return this.assertBounds(),e;n=this.buf[this.pos++],e|=(n&15)<<28;for(let t=5;(n&128)!==0&&t<10;t++)n=this.buf[this.pos++];if((n&128)!=0)throw new Error("invalid varint");return this.assertBounds(),e>>>0}var h;function Xe(){let n=new DataView(new ArrayBuffer(8));h=globalThis.BigInt!==void 0&&typeof n.getBigInt64=="function"&&typeof n.getBigUint64=="function"&&typeof n.setBigInt64=="function"&&typeof n.setBigUint64=="function"?{MIN:BigInt("-9223372036854775808"),MAX:BigInt("9223372036854775807"),UMIN:BigInt("0"),UMAX:BigInt("18446744073709551615"),C:BigInt,V:n}:void 0}Xe();function xe(n){if(!n)throw new Error("BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support")}var Ne=/^-?[0-9]+$/,q=4294967296,_=2147483648,W=class{constructor(e,t){this.lo=e|0,this.hi=t|0}isZero(){return this.lo==0&&this.hi==0}toNumber(){let e=this.hi*q+(this.lo>>>0);if(!Number.isSafeInteger(e))throw new Error("cannot convert to safe number");return e}},y=class n extends W{static from(e){if(h)switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=="")throw new Error("string is no integer");e=h.C(e);case"number":if(e===0)return this.ZERO;e=h.C(e);case"bigint":if(!e)return this.ZERO;if(eh.UMAX)throw new Error("ulong too large");return h.V.setBigUint64(0,e,!0),new n(h.V.getInt32(0,!0),h.V.getInt32(4,!0))}else switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=e.trim(),!Ne.test(e))throw new Error("string is no integer");let[t,r,i]=re(e);if(t)throw new Error("signed value for ulong");return new n(r,i);case"number":if(e==0)return this.ZERO;if(!Number.isSafeInteger(e))throw new Error("number is no integer");if(e<0)throw new Error("signed value for ulong");return new n(e,e/q)}throw new Error("unknown value "+typeof e)}toString(){return h?this.toBigInt().toString():j(this.lo,this.hi)}toBigInt(){return xe(h),h.V.setInt32(0,this.lo,!0),h.V.setInt32(4,this.hi,!0),h.V.getBigUint64(0,!0)}};y.ZERO=new y(0,0);var b=class n extends W{static from(e){if(h)switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=="")throw new Error("string is no integer");e=h.C(e);case"number":if(e===0)return this.ZERO;e=h.C(e);case"bigint":if(!e)return this.ZERO;if(eh.MAX)throw new Error("signed long too large");return h.V.setBigInt64(0,e,!0),new n(h.V.getInt32(0,!0),h.V.getInt32(4,!0))}else switch(typeof e){case"string":if(e=="0")return this.ZERO;if(e=e.trim(),!Ne.test(e))throw new Error("string is no integer");let[t,r,i]=re(e);if(t){if(i>_||i==_&&r!=0)throw new Error("signed long too small")}else if(i>=_)throw new Error("signed long too large");let s=new n(r,i);return t?s.negate():s;case"number":if(e==0)return this.ZERO;if(!Number.isSafeInteger(e))throw new Error("number is no integer");return e>0?new n(e,e/q):new n(-e,-e/q).negate()}throw new Error("unknown value "+typeof e)}isNegative(){return(this.hi&_)!==0}negate(){let e=~this.hi,t=this.lo;return t?t=~t+1:e+=1,new n(t,e)}toString(){if(h)return this.toBigInt().toString();if(this.isNegative()){let e=this.negate();return"-"+j(e.lo,e.hi)}return j(this.lo,this.hi)}toBigInt(){return xe(h),h.V.setInt32(0,this.lo,!0),h.V.setInt32(4,this.hi,!0),h.V.getBigInt64(0,!0)}};b.ZERO=new b(0,0);var ke={readUnknownField:!0,readerFactory:n=>new ie(n)};function Ie(n){return n?Object.assign(Object.assign({},ke),n):ke}var ie=class{constructor(e,t){this.varint64=ye,this.uint32=we,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=t??new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0})}tag(){let e=this.uint32(),t=e>>>3,r=e&7;if(t<=0||r<0||r>5)throw new Error("illegal tag: field no "+t+" wire type "+r);return[t,r]}skip(e){let t=this.pos;switch(e){case l.Varint:for(;this.buf[this.pos++]&128;);break;case l.Bit64:this.pos+=4;case l.Bit32:this.pos+=4;break;case l.LengthDelimited:let r=this.uint32();this.pos+=r;break;case l.StartGroup:let i;for(;(i=this.tag()[1])!==l.EndGroup;)this.skip(i);break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(t,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return new b(...this.varint64())}uint64(){return new y(...this.varint64())}sint64(){let[e,t]=this.varint64(),r=-(e&1);return e=(e>>>1|(t&1)<<31)^r,t=t>>>1^r,new b(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return new y(this.sfixed32(),this.sfixed32())}sfixed64(){return new b(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}};function m(n,e){if(!n)throw new Error(e)}var Je=34028234663852886e22,Ge=-34028234663852886e22,He=4294967295,Ze=2147483647,Ye=-2147483648;function S(n){if(typeof n!="number")throw new Error("invalid int 32: "+typeof n);if(!Number.isInteger(n)||n>Ze||nHe||n<0)throw new Error("invalid uint 32: "+n)}function F(n){if(typeof n!="number")throw new Error("invalid float 32: "+typeof n);if(Number.isFinite(n)&&(n>Je||nnew se};function Ee(n){return n?Object.assign(Object.assign({},Te),n):Te}var se=class{constructor(e){this.stack=[],this.textEncoder=e??new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let i=0;i>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(R(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return S(e),ne(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){F(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){R(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){S(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return S(e),e=(e<<1^e>>31)>>>0,ne(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),r=new DataView(t.buffer),i=b.from(e);return r.setInt32(0,i.lo,!0),r.setInt32(4,i.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),r=new DataView(t.buffer),i=y.from(e);return r.setInt32(0,i.lo,!0),r.setInt32(4,i.hi,!0),this.raw(t)}int64(e){let t=b.from(e);return v(t.lo,t.hi,this.buf),this}sint64(e){let t=b.from(e),r=t.hi>>31,i=t.lo<<1^r,s=(t.hi<<1|t.lo>>>31)^r;return v(i,s,this.buf),this}uint64(e){let t=y.from(e);return v(t.lo,t.hi,this.buf),this}};var Oe={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0},Se={ignoreUnknownFields:!1};function Re(n){return n?Object.assign(Object.assign({},Se),n):Se}function Ae(n){return n?Object.assign(Object.assign({},Oe),n):Oe}var K=Symbol.for("protobuf-ts/message-type");function oe(n){let e=!1,t=[];for(let r=0;r!i.includes(o))||!r&&i.some(o=>!s.known.includes(o)))return!1;if(t<1)return!0;for(let o of s.oneofs){let a=e[o];if(!Fe(a))return!1;if(a.oneofKind===void 0)continue;let c=this.fields.find(u=>u.localName===a.oneofKind);if(!c||!this.field(a[a.oneofKind],c,r,t))return!1}for(let o of this.fields)if(o.oneof===void 0&&!this.field(e[o.localName],o,r,t))return!1;return!0}field(e,t,r,i){let s=t.repeat;switch(t.kind){case"scalar":return e===void 0?t.opt:s?this.scalars(e,t.T,i,t.L):this.scalar(e,t.T,t.L);case"enum":return e===void 0?t.opt:s?this.scalars(e,f.INT32,i):this.scalar(e,f.INT32);case"message":return e===void 0?!0:s?this.messages(e,t.T(),r,i):this.message(e,t.T(),r,i);case"map":if(typeof e!="object"||e===null)return!1;if(i<2)return!0;if(!this.mapKeys(e,t.K,i))return!1;switch(t.V.kind){case"scalar":return this.scalars(Object.values(e),t.V.T,i,t.V.L);case"enum":return this.scalars(Object.values(e),f.INT32,i);case"message":return this.messages(Object.values(e),t.V.T(),r,i)}break}return!0}message(e,t,r,i){return r?t.isAssignable(e,i):t.is(e,i)}messages(e,t,r,i){if(!Array.isArray(e))return!1;if(i<2)return!0;if(r){for(let s=0;sparseInt(s)),t,r);case f.BOOL:return this.scalars(i.slice(0,r).map(s=>s=="true"?!0:s=="false"?!1:s),t,r);default:return this.scalars(i,t,r,x.STRING)}}};function k(n,e){switch(e){case x.BIGINT:return n.toBigInt();case x.NUMBER:return n.toNumber();default:return n.toString()}}var J=class{constructor(e){this.info=e}prepare(){var e;if(this.fMap===void 0){this.fMap={};let t=(e=this.info.fields)!==null&&e!==void 0?e:[];for(let r of t)this.fMap[r.name]=r,this.fMap[r.jsonName]=r,this.fMap[r.localName]=r}}assert(e,t,r){if(!e){let i=P(r);throw(i=="number"||i=="boolean")&&(i=r.toString()),new Error(`Cannot parse JSON ${i} for ${this.info.typeName}#${t}`)}}read(e,t,r){this.prepare();let i=[];for(let[s,o]of Object.entries(e)){let a=this.fMap[s];if(!a){if(!r.ignoreUnknownFields)throw new Error(`Found unknown field while reading ${this.info.typeName} from JSON format. JSON key: ${s}`);continue}let c=a.localName,u;if(a.oneof){if(o===null&&(a.kind!=="enum"||a.T()[0]!=="google.protobuf.NullValue"))continue;if(i.includes(a.oneof))throw new Error(`Multiple members of the oneof group "${a.oneof}" of ${this.info.typeName} are present in JSON.`);i.push(a.oneof),u=t[a.oneof]={oneofKind:c}}else u=t;if(a.kind=="map"){if(o===null)continue;this.assert(he(o),a.name,o);let p=u[c];for(let[g,d]of Object.entries(o)){this.assert(d!==null,a.name+" map value",null);let I;switch(a.V.kind){case"message":I=a.V.T().internalJsonRead(d,r);break;case"enum":if(I=this.enum(a.V.T(),d,a.name,r.ignoreUnknownFields),I===!1)continue;break;case"scalar":I=this.scalar(d,a.V.T,a.V.L,a.name);break}this.assert(I!==void 0,a.name+" map value",d);let T=g;a.K==f.BOOL&&(T=T=="true"?!0:T=="false"?!1:T),T=this.scalar(T,a.K,x.STRING,a.name).toString(),p[T]=I}}else if(a.repeat){if(o===null)continue;this.assert(Array.isArray(o),a.name,o);let p=u[c];for(let g of o){this.assert(g!==null,a.name,null);let d;switch(a.kind){case"message":d=a.T().internalJsonRead(g,r);break;case"enum":if(d=this.enum(a.T(),g,a.name,r.ignoreUnknownFields),d===!1)continue;break;case"scalar":d=this.scalar(g,a.T,a.L,a.name);break}this.assert(d!==void 0,a.name,o),p.push(d)}}else switch(a.kind){case"message":if(o===null&&a.T().typeName!="google.protobuf.Value"){this.assert(a.oneof===void 0,a.name+" (oneof member)",null);continue}u[c]=a.T().internalJsonRead(o,r,u[c]);break;case"enum":if(o===null)continue;let p=this.enum(a.T(),o,a.name,r.ignoreUnknownFields);if(p===!1)continue;u[c]=p;break;case"scalar":if(o===null)continue;u[c]=this.scalar(o,a.T,a.L,a.name);break}}}enum(e,t,r,i){if(e[0]=="google.protobuf.NullValue"&&m(t===null||t==="NULL_VALUE",`Unable to parse field ${this.info.typeName}#${r}, enum ${e[0]} only accepts null.`),t===null)return 0;switch(typeof t){case"number":return m(Number.isInteger(t),`Unable to parse field ${this.info.typeName}#${r}, enum can only be integral number, got ${t}.`),t;case"string":let s=t;e[2]&&t.substring(0,e[2].length)===e[2]&&(s=t.substring(e[2].length));let o=e[1][s];return typeof o>"u"&&i?!1:(m(typeof o=="number",`Unable to parse field ${this.info.typeName}#${r}, enum ${e[0]} has no value for "${t}".`),o)}m(!1,`Unable to parse field ${this.info.typeName}#${r}, cannot parse enum value from ${typeof t}".`)}scalar(e,t,r,i){let s;try{switch(t){case f.DOUBLE:case f.FLOAT:if(e===null)return 0;if(e==="NaN")return Number.NaN;if(e==="Infinity")return Number.POSITIVE_INFINITY;if(e==="-Infinity")return Number.NEGATIVE_INFINITY;if(e===""){s="empty string";break}if(typeof e=="string"&&e.trim().length!==e.length){s="extra whitespace";break}if(typeof e!="string"&&typeof e!="number")break;let o=Number(e);if(Number.isNaN(o)){s="not a number";break}if(!Number.isFinite(o)){s="too large or small";break}return t==f.FLOAT&&F(o),o;case f.INT32:case f.FIXED32:case f.SFIXED32:case f.SINT32:case f.UINT32:if(e===null)return 0;let a;if(typeof e=="number"?a=e:e===""?s="empty string":typeof e=="string"&&(e.trim().length!==e.length?s="extra whitespace":a=Number(e)),a===void 0)break;return t==f.UINT32?R(a):S(a),a;case f.INT64:case f.SFIXED64:case f.SINT64:if(e===null)return k(b.ZERO,r);if(typeof e!="number"&&typeof e!="string")break;return k(b.from(e),r);case f.FIXED64:case f.UINT64:if(e===null)return k(y.ZERO,r);if(typeof e!="number"&&typeof e!="string")break;return k(y.from(e),r);case f.BOOL:if(e===null)return!1;if(typeof e!="boolean")break;return e;case f.STRING:if(e===null)return"";if(typeof e!="string"){s="extra whitespace";break}try{encodeURIComponent(e)}catch(c){c="invalid UTF8";break}return e;case f.BYTES:if(e===null||e==="")return new Uint8Array(0);if(typeof e!="string")break;return ge(e)}}catch(o){s=o.message}this.assert(!1,i+(s?" - "+s:""),e)}};var G=class{constructor(e){var t;this.fields=(t=e.fields)!==null&&t!==void 0?t:[]}write(e,t){let r={},i=e;for(let s of this.fields){if(!s.oneof){let u=this.field(s,i[s.localName],t);u!==void 0&&(r[t.useProtoFieldName?s.name:s.jsonName]=u);continue}let o=i[s.oneof];if(o.oneofKind!==s.localName)continue;let a=s.kind=="scalar"||s.kind=="enum"?Object.assign(Object.assign({},t),{emitDefaultValues:!0}):t,c=this.field(s,o[s.localName],a);m(c!==void 0),r[t.useProtoFieldName?s.name:s.jsonName]=c}return r}field(e,t,r){let i;if(e.kind=="map"){m(typeof t=="object"&&t!==null);let s={};switch(e.V.kind){case"scalar":for(let[c,u]of Object.entries(t)){let p=this.scalar(e.V.T,u,e.name,!1,!0);m(p!==void 0),s[c.toString()]=p}break;case"message":let o=e.V.T();for(let[c,u]of Object.entries(t)){let p=this.message(o,u,e.name,r);m(p!==void 0),s[c.toString()]=p}break;case"enum":let a=e.V.T();for(let[c,u]of Object.entries(t)){m(u===void 0||typeof u=="number");let p=this.enum(a,u,e.name,!1,!0,r.enumAsInteger);m(p!==void 0),s[c.toString()]=p}break}(r.emitDefaultValues||Object.keys(s).length>0)&&(i=s)}else if(e.repeat){m(Array.isArray(t));let s=[];switch(e.kind){case"scalar":for(let c=0;c0||r.emitDefaultValues)&&(i=s)}else switch(e.kind){case"scalar":i=this.scalar(e.T,t,e.name,e.opt,r.emitDefaultValues);break;case"enum":i=this.enum(e.T(),t,e.name,e.opt,r.emitDefaultValues,r.enumAsInteger);break;case"message":i=this.message(e.T(),t,e.name,r);break}return i}enum(e,t,r,i,s,o){if(e[0]=="google.protobuf.NullValue")return!s&&!i?void 0:null;if(t===void 0){m(i);return}if(!(t===0&&!s&&!i))return m(typeof t=="number"),m(Number.isInteger(t)),o||!e[1].hasOwnProperty(t)?t:e[2]?e[2]+e[1][t]:e[1][t]}message(e,t,r,i){return t===void 0?i.emitDefaultValues?null:void 0:e.internalJsonWrite(t,i)}scalar(e,t,r,i,s){if(t===void 0){m(i);return}let o=s||i;switch(e){case f.INT32:case f.SFIXED32:case f.SINT32:return t===0?o?0:void 0:(S(t),t);case f.FIXED32:case f.UINT32:return t===0?o?0:void 0:(R(t),t);case f.FLOAT:F(t);case f.DOUBLE:return t===0?o?0:void 0:(m(typeof t=="number"),Number.isNaN(t)?"NaN":t===Number.POSITIVE_INFINITY?"Infinity":t===Number.NEGATIVE_INFINITY?"-Infinity":t);case f.STRING:return t===""?o?"":void 0:(m(typeof t=="string"),t);case f.BOOL:return t===!1?o?!1:void 0:(m(typeof t=="boolean"),t);case f.UINT64:case f.FIXED64:m(typeof t=="number"||typeof t=="string"||typeof t=="bigint");let a=y.from(t);return a.isZero()&&!o?void 0:a.toString();case f.INT64:case f.SFIXED64:case f.SINT64:m(typeof t=="number"||typeof t=="string"||typeof t=="bigint");let c=b.from(t);return c.isZero()&&!o?void 0:c.toString();case f.BYTES:return m(t instanceof Uint8Array),t.byteLength?be(t):o?"":void 0}}};function U(n,e=x.STRING){switch(n){case f.BOOL:return!1;case f.UINT64:case f.FIXED64:return k(y.ZERO,e);case f.INT64:case f.SFIXED64:case f.SINT64:return k(b.ZERO,e);case f.DOUBLE:case f.FLOAT:return 0;case f.BYTES:return new Uint8Array(0);case f.STRING:return"";default:return 0}}var H=class{constructor(e){this.info=e}prepare(){var e;if(!this.fieldNoToField){let t=(e=this.info.fields)!==null&&e!==void 0?e:[];this.fieldNoToField=new Map(t.map(r=>[r.no,r]))}}read(e,t,r,i){this.prepare();let s=i===void 0?e.len:e.pos+i;for(;e.post.no-r.no)}}write(e,t,r){this.prepare();for(let s of this.fields){let o,a,c=s.repeat,u=s.localName;if(s.oneof){let p=e[s.oneof];if(p.oneofKind!==u)continue;o=p[u],a=!0}else o=e[u],a=!1;switch(s.kind){case"scalar":case"enum":let p=s.kind=="enum"?f.INT32:s.T;if(c)if(m(Array.isArray(o)),c==D.PACKED)this.packed(t,p,s.no,o);else for(let g of o)this.scalar(t,p,s.no,g,!0);else o===void 0?m(s.opt):this.scalar(t,p,s.no,o,a||s.opt);break;case"message":if(c){m(Array.isArray(o));for(let g of o)this.message(t,r,s.T(),s.no,g)}else this.message(t,r,s.T(),s.no,o);break;case"map":m(typeof o=="object"&&o!==null);for(let[g,d]of Object.entries(o))this.mapEntry(t,r,s,g,d);break}}let i=r.writeUnknownFields;i!==!1&&(i===!0?N.onWrite:i)(this.info.typeName,e,t)}mapEntry(e,t,r,i,s){e.tag(r.no,l.LengthDelimited),e.fork();let o=i;switch(r.K){case f.INT32:case f.FIXED32:case f.UINT32:case f.SFIXED32:case f.SINT32:o=Number.parseInt(i);break;case f.BOOL:m(i=="true"||i=="false"),o=i=="true";break}switch(this.scalar(e,r.K,1,o,!0),r.V.kind){case"scalar":this.scalar(e,r.V.T,2,s,!0);break;case"enum":this.scalar(e,f.INT32,2,s,!0);break;case"message":this.message(e,t,r.V.T(),2,s);break}e.join()}message(e,t,r,i,s){s!==void 0&&(r.internalBinaryWrite(s,e.tag(i,l.LengthDelimited).fork(),t),e.join())}scalar(e,t,r,i,s){let[o,a,c]=this.scalarInfo(t,i);(!c||s)&&(e.tag(r,o),e[a](i))}packed(e,t,r,i){if(!i.length)return;m(t!==f.BYTES&&t!==f.STRING),e.tag(r,l.LengthDelimited),e.fork();let[,s]=this.scalarInfo(t);for(let o=0;o(t[t.NONE_TYPE=0]="NONE_TYPE",t[t.VIP_GRADUAL_COLOR=60001]="VIP_GRADUAL_COLOR",t))(le||{});var fe=class extends A{constructor(){super("bilibili.community.service.dm.v1.DmSegMobileReq",[{no:1,name:"pid",kind:"scalar",T:3},{no:2,name:"oid",kind:"scalar",T:3},{no:3,name:"type",kind:"scalar",T:5},{no:4,name:"segment_index",kind:"scalar",T:3},{no:6,name:"ps",kind:"scalar",T:3},{no:7,name:"pe",kind:"scalar",T:3}])}create(e){let t=globalThis.Object.create(this.messagePrototype);return t.pid="0",t.oid="0",t.type=0,t.segmentIndex="0",t.ps="0",t.pe="0",e!==void 0&&O(this,t,e),t}internalBinaryRead(e,t,r,i){let s=i??this.create(),o=e.pos+t;for(;e.posae}])}create(e){let t=globalThis.Object.create(this.messagePrototype);return t.elems=[],e!==void 0&&O(this,t,e),t}internalBinaryRead(e,t,r,i){let s=i??this.create(),o=e.pos+t;for(;e.pos["bilibili.community.service.dm.v1.DmColorfulType",le]},{no:25,name:"type",kind:"scalar",T:5},{no:26,name:"oid",kind:"scalar",T:3},{no:27,name:"dm_from",kind:"scalar",T:5}])}create(e){let t=globalThis.Object.create(this.messagePrototype);return t.id="0",t.progress=0,t.mode=0,t.fontsize=0,t.color=0,t.midHash="",t.content="",t.ctime="0",t.weight=0,t.action="",t.pool=0,t.idStr="",t.attr=0,t.animation="",t.extra="",t.colorful=0,t.type=0,t.oid="0",t.dmFrom=0,e!==void 0&&O(this,t,e),t}internalBinaryRead(e,t,r,i){let s=i??this.create(),o=e.pos+t;for(;e.pos0;)e[t]=tt[Number(r%BigInt(je))],r=r/je,t-=1;return[e[3],e[9]]=[e[9],e[3]],[e[4],e[7]]=[e[7],e[4]],e.join("")}var z=class{type;message;constructor(e,t){this.type=e,this.message=this.fromBinary(t)}fromBinary(e){return this.type.fromBinary(e)}toBinary(){return this.type.toBinary(this.message)}};var L=class extends z{constructor(e,t){super(e,t)}fromBinary(e){let t=e[0]?w.ungzip(e.subarray(5)):e.subarray(5);return super.fromBinary(t)}toBinary(){let e=super.toBinary(),t=e.length,r=new Uint8Array(5+t);return r[0]=0,r[1]=t>>>24,r[2]=t>>>16&255,r[3]=t>>>8&255,r[4]=t&255,r.set(e,5),r}};var pe=class extends L{headers;body;constructor(e){super(e,w.request.bodyBytes),w.debug(this.message)}done(){w.done({response:{headers:this.headers,body:this.body}})}async process(){return await this._process(this.message),this}fetchAll(e,t=""){return Promise.all([this.fetchBilibili(),this.fetchSponsorBlock(e,t)])}fetchBilibili(){let{url:e,headers:t,bodyBytes:r}=w.request;return w.fetch({method:"post",url:e,headers:t,body:r,timeout:3})}async fetchSponsorBlock(e,t){try{let{status:r,body:i}=await ve(e,t);return w.debug(e,r,i),r!==200||!i||i==="[]"?[]:JSON.parse(i).reduce((s,{actionType:o,segment:a})=>(o==="skip"&&a[1]-a[0]>=8&&s.push(a),s),[])}catch(r){return w.error("[fetchSponsorBlock]",r),[]}}},Q=class extends pe{constructor(){super($e)}async _process(e){e.type!==1&&w.exit();let{pid:t,oid:r}=e,i=_e(t);try{let[{status:s,headers:o,bodyBytes:a},c]=await this.fetchAll(i,r);if(s!==200)throw new Error(`Response status code is ${s}`);if(!a)throw new Error("Response body is empty");this.headers=o,this.body=c.length?new me(a,c).process().done():a}catch(s){w.error("[processDmSegMobileReq]",s),w.exit()}}},me=class extends L{segments;constructor(e,t){super(Me,e),this.segments=t}done(){return this.toBinary()}process(){return this._process(this.message),this}_process(e){e.elems.push(...this.getAirBorneDms())}getAirBorneDms(){return this.segments.map((t,r)=>{let i=(r+1).toString(),s=Math.floor(t[0]*1e3)+2e3,o=Math.floor(t[1]*1e3);return{id:i,progress:s,mode:5,fontsize:50,color:16777215,midHash:"1948dd5d",content:"\u7A7A\u6307\u90E8\u5DF2\u5C31\u4F4D",ctime:"1735660800",weight:11,action:`airborne:${o}`,pool:0,idStr:i,attr:1310724,animation:"",extra:"",colorful:0,type:1,oid:"212364987",dmFrom:1}})}};(async()=>{try{(await new Q().process()).done()}catch(n){w.error(n,w.request.url)}finally{w.exit()}})();