Files
WeChat-Channels-Video-File-…/wechat_files/worker_release.js
Evil0ctal da298fbde7 Add Files
2025-10-15 05:44:59 -07:00

2 lines
34 KiB
JavaScript

/*! For license information please see worker_release.js.LICENSE.txt */
(()=>{function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function r(t){for(var r=1;r<arguments.length;r++){var a=null!=arguments[r]?arguments[r]:{};r%2?e(Object(a),!0).forEach((function(e){n(t,e,a[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):e(Object(a)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))}))}return t}function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,a,i=[],o=!0,u=!1;try{for(r=r.call(t);!(o=(n=r.next()).done)&&(i.push(n.value),!e||i.length!==e);o=!0);}catch(t){u=!0,a=t}finally{try{o||null==r.return||r.return()}finally{if(u)throw a}}return i}}(t,e)||function(t,e){if(t){if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(){"use strict";o=function(){return e};var e={},r=Object.prototype,n=r.hasOwnProperty,a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var a=e&&e.prototype instanceof h?e:h,i=Object.create(a.prototype),o=new S(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(a,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw i;return{value:void 0,done:!0}}for(r.method=a,r.arg=i;;){var o=r.delegate;if(o){var u=x(o,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=l(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===p)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(t,r,o),i}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var p={};function h(){}function d(){}function m(){}var w={};c(w,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(E([])));g&&g!==r&&n.call(g,i)&&(w=g);var b=m.prototype=h.prototype=Object.create(w);function v(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function k(e,r){function a(i,o,u,s){var c=l(e[i],e,o);if("throw"!==c.type){var f=c.arg,p=f.value;return p&&"object"==t(p)&&n.call(p,"__await")?r.resolve(p.__await).then((function(t){a("next",t,u,s)}),(function(t){a("throw",t,u,s)})):r.resolve(p).then((function(t){f.value=t,u(f)}),(function(t){return a("throw",t,u,s)}))}s(c.arg)}var i;this._invoke=function(t,e){function n(){return new r((function(r,n){a(t,e,r,n)}))}return i=i?i.then(n,n):n()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=l(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var a=n.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function B(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function E(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,a=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return a.next=a}}return{next:C}}function C(){return{value:void 0,done:!0}}return d.prototype=m,c(b,"constructor",m),c(m,"constructor",d),d.displayName=c(m,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,c(t,s,"GeneratorFunction")),t.prototype=Object.create(b),t},e.awrap=function(t){return{__await:t}},v(k.prototype),c(k.prototype,u,(function(){return this})),e.AsyncIterator=k,e.async=function(t,r,n,a,i){void 0===i&&(i=Promise);var o=new k(f(t,r,n,a),i);return e.isGeneratorFunction(r)?o:o.next().then((function(t){return t.done?t.value:o.next()}))},v(b),c(b,s,"Generator"),c(b,i,(function(){return this})),c(b,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=E,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(B),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return o.type="throw",o.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],o=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=t,o.arg=e,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),B(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var a=n.arg;B(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}function u(t,e,r,n,a,i,o){try{var u=t[i](o),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,a)}function s(t){return function(){var e=this,r=arguments;return new Promise((function(n,a){var i=t.apply(e,r);function o(t){u(i,n,a,o,s,"next",t)}function s(t){u(i,n,a,o,s,"throw",t)}o(void 0)}))}}function c(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function f(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function l(t,e,r){return e&&f(t.prototype,e),r&&f(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}var p;p="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:window;var h="FFMPEG_ERROR",d="NETWORK_REQUEST_ERROR",m="WASM_ERROR",w=function(){function t(e){c(this,t),this.maxSize=e,this.cacheMap={},this.currentByteLen=0,this.allHitCount=0,this.allGetCount=0}return l(t,[{key:"updateLruMaxSize",value:function(t){"number"==typeof t&&t>0&&(this.maxSize=t)}},{key:"dispose",value:function(){this.cacheMap={},this.currentByteLen=0,this.allHitCount=0,this.allGetCount=0}},{key:"setData",value:function(t,e,r){var n=this.genKey(t,e);y.log("[lruCache]setData: ",n,", byteLen:",r.byteLength),this.cacheMap[n]={buffer:r,hitCount:0},this.currentByteLen=this.currentByteLen+r.byteLength}},{key:"genKey",value:function(t,e){return"".concat(t,"-").concat(e)}},{key:"getBuffer",value:function(t,e){var r=this.get(t,e);return r?r.buffer:null}},{key:"getHitRate",value:function(){return(this.allHitCount/this.allGetCount).toFixed(2)}},{key:"get",value:function(t,e){var r=this.genKey(t,e),n=this.cacheMap[r];return this.allGetCount=this.allGetCount+1,n?(n.hitCount=n.hitCount+1,this.allHitCount=this.allHitCount+1,y.log("[lruCache]getBufferSuccess: ",r," hitCount: ",n.hitCount," hitRate: ".concat(100*this.getHitRate(),"%")),n):null}},{key:"delItem",value:function(t){for(var e=1/0,r=null,n=Object.keys(this.cacheMap),a=0;a<n.length;a++){var i=n[a];if(this.cacheMap[i]){var o=this.cacheMap[i].hitCount;o<e&&(e=o,r=i)}}if(r){var u=this.cacheMap[r].buffer.byteLength;y.log("[lruCache]remove: ",u,r),delete this.cacheMap[r],this.currentByteLen=this.currentByteLen-u;var s=t-u;s>0&&(y.log("[lruCache]continue Remove: ",s),this.delItem(s))}}},{key:"set",value:function(t,e,r){var n=r.byteLength;if(this.currentByteLen+n>this.maxSize){var a=this.currentByteLen+n-this.maxSize;this.delItem(a)}this.setData(t,e,r)}}]),t}(),y=new(function(){function t(){c(this,t),this.TAG="[Decrypt Worker]"}return l(t,[{key:"time",value:function(t){p.taskInfo.debugTimeLog&&console.time(t)}},{key:"timeEnd",value:function(t){p.taskInfo.debugTimeLog&&console.timeEnd(t)}},{key:"log",value:function(){if(p.taskInfo&&p.taskInfo.debug){for(var t,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];(t=console).log.apply(t,[this.TAG].concat(r))}}},{key:"error",value:function(){for(var t,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];(t=console).error.apply(t,[this.TAG].concat(r))}},{key:"warn",value:function(){for(var t,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];(t=console).warn.apply(t,[this.TAG].concat(r))}}]),t}());function g(){p.outputBuffer=null}function b(t){"number"==typeof t&&t>0||(t=4*p.winLargeSize),p.lruCache=new w(t)}function v(){p.lruCache&&(p.lruCache.dispose(),p.lruCache=null)}function k(){p.files={},p.fetchBuffer=void 0,p.fetchBufferSize=5242880,p.lastBytesRead=0,p.taskInfo=p.TEST_TASK_INFO||{url:"",size:0,seed:"",disableDecrypt:!1,debug:!1,debugTimeLog:!1},p.decryptor=null,p.fmp4ReadyCallBack=null,p.firstWinBufferOkCb=null,p.winBufStart=-1,p.winBufEnd=-1,p.winSize=524288,p.winBuf=null,p.winBufContentLength=0,p.winRawBuf=null,p.firstWinBuf=null,p.winLargeSize=1048576,p.winSmallSize=1048576,p.winPreservePastSize=1048576,p.lruCache&&p.lruCache.dispose(),p.segmentDuration=.5,p.segmentSmallDuration=.5,p.segmentSeekDuration=1,p.segmentSmallCount=0,p.segmentLargeDuration=5,p.fetchControllerList=[],p.ffmpeg_errno=0,p.ffmpeg_errmsg="OK",p.io_errmsg="OK",p.last_ss=-1,p.fmp4Index=0,p.info_file={next_ss:"0",next_dts_v:"0",next_dts_a:"0"},p.cutFmp4Idle=!0,p.seekTaskCb=null,p.pauseProcess=!1,p.disposingProcess=!1,p.downloading=!1,p.networkTimeout=6e3,p.networkRetryTimes=5}function x(t){p.winSize=t}function _(t){p.segmentDuration=t}function B(t){p.winRawBuf=t}function S(t){p.taskInfo.size=t}function E(t){p.downloading=t}function C(t){return L.apply(this,arguments)}function L(){return(L=s(o().mark((function t(e){var r,n,a,i;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.url,t.prev=1,!(p.winBufStart<0&&p.winBufEnd<0)&&p.winBuf&&p.firstWinBuf){t.next=26;break}return E(!0),t.next=6,this.getContentLen(r);case 6:if(n=t.sent,a=0,!p.winRawBuf){t.next=13;break}i=Math.min(n,p.winRawBuf.byteLength-1),p.taskInfo.disableDecrypt?p.winBuf=new Uint8Array(p.winRawBuf):p.winBuf=M(p.winRawBuf,0),t.next=17;break;case 13:return i=Math.min(n,p.winSize-1),t.next=16,F({url:r,start:a,end:i});case 16:p.winBuf=t.sent;case 17:if(p.winBufContentLength=p.winBuf.byteLength,E(!1),p.winBuf){t.next=21;break}return t.abrupt("return",!1);case 21:return p.winBufStart=a,p.winBufEnd=i,p.firstWinBuf=p.winBuf.slice(0),p.firstWinBufferOkCb&&p.firstWinBufferOkCb(),t.abrupt("return",!0);case 26:return t.abrupt("return",!1);case 29:throw t.prev=29,t.t0=t.catch(1),E(!1),t.t0;case 33:case"end":return t.stop()}}),t,this,[[1,29]])})))).apply(this,arguments)}function O(t){return I.apply(this,arguments)}function I(){return(I=s(o().mark((function t(e){var r,n,a,i,u,s,c,f,l,h,d,m,w,g,b,v;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.url,n=e.start,a=e.end,i=e.stream_id,t.next=3,this.getContentLen(r);case 3:return u=t.sent,t.next=6,C(e);case 6:if(d=!1,m=p.winBufStart,w=p.winBufEnd,!(n>=0&&a<p.firstWinBuf.byteLength)){t.next=12;break}return h=p.firstWinBuf.subarray(n,a+1),t.abrupt("return",h);case 12:if(!(n<p.winBufStart)){t.next=20;break}s=n,(g=Math.min(Math.max(a,s+p.winSize-1),u-1))<p.winBufStart||g>p.winBufEnd?(y.log("@@@ case1.1 for ".concat(i," | start: ").concat(n,", end: ").concat(a,", offsetStart: ").concat(n-p.winBufStart,", offsetEnd: ").concat(a-p.winBufStart,", winBufStart: ").concat(p.winBufStart,", winBufEnd: ").concat(p.winBufEnd)),c=g):(y.log("@@@ case1.2 for ".concat(i," | start: ").concat(n,", end: ").concat(a,", offsetStart: ").concat(n-p.winBufStart,", offsetEnd: ").concat(a-p.winBufStart,", winBufStart: ").concat(p.winBufStart,", winBufEnd: ").concat(p.winBufEnd)),c=p.winBufStart-1,l=p.winBuf.subarray(0,g-p.winBufStart+1),d=!1),m=n,w=g,t.next=50;break;case 20:if(!(n>=p.winBufStart&&a<=p.winBufEnd)){t.next=29;break}return y.log("@@@ case2 for ".concat(i," | start: ").concat(n,", end: ").concat(a,", offsetStart: ").concat(n-p.winBufStart,", offsetEnd: ").concat(a-p.winBufStart,", winBufStart: ").concat(p.winBufStart,", winBufEnd: ").concat(p.winBufEnd,", byteLen: ").concat(p.winBufContentLength)),h=p.winBuf.subarray(n-p.winBufStart,a-p.winBufStart+1),l=null,m=p.winBufStart,w=p.winBufEnd,t.abrupt("return",h);case 29:if(!(n>=p.winBufStart&&n<=p.winBufEnd&&a>p.winBufEnd)){t.next=40;break}y.log("@@@ case3 for ".concat(i," | start: ").concat(n,", end: ").concat(a,", offsetStart: ").concat(n-p.winBufStart,", offsetEnd: ").concat(a-p.winBufStart,", winBufStart: ").concat(p.winBufStart,", winBufEnd: ").concat(p.winBufEnd)),b=Math.max(a,p.winBufEnd+p.winSize),d=!0,m=Math.max(n-p.winPreservePastSize,p.winBufStart),l=p.winBuf.subarray(m-p.winBufStart,p.winBufContentLength),s=p.winBufEnd+1,c=Math.min(b,u-1),w=c,t.next=50;break;case 40:if(!(n>p.winBufEnd)){t.next=49;break}y.log("@@@ case4 for ".concat(i," | start: ").concat(n,", end: ").concat(a,", offsetStart: ").concat(n-p.winBufStart,", offsetEnd: ").concat(a-p.winBufStart,", winBufStart: ").concat(p.winBufStart,", winBufEnd: ").concat(p.winBufEnd)),s=n,c=Math.min(Math.max(a,n+p.winSize-1),u-1),l=null,m=s,w=c,t.next=50;break;case 49:throw new Error("getBufferFromWindow error, start: ".concat(n,", end: ").concat(a,", winBufStart: ").concat(p.winBufStart,", winBufEnd: ").concat(p.winBufEnd));case 50:return t.next=52,F({url:r,start:s,end:c});case 52:if(f=t.sent){t.next=55;break}return t.abrupt("return",null);case 55:return l?(p.winBufContentLength=l.byteLength+f.byteLength,p.winBuf.byteLength<p.winBufContentLength&&(p.winBuf=new Uint8Array(p.winBufContentLength)),d?(p.winBuf.set(l),p.winBuf.set(f,l.byteLength)):(p.winBuf.set(l,f.byteLength),p.winBuf.set(f))):(f.byteLength>p.winBuf.byteLength?p.winBuf=f:p.winBuf.set(f),p.winBufContentLength=f.byteLength),p.winBufStart=m,p.winBufEnd=w,v=p.winBuf.subarray(n-p.winBufStart,a-p.winBufStart+1),t.abrupt("return",v);case 60:case"end":return t.stop()}}),t,this)})))).apply(this,arguments)}function T(t){return"string"==typeof t?t:err?t instanceof Error?t.toString():JSON.stringify(t):""}function R(t,e,r,n){n=n||{},r&&y.error(t,e,r),stack=r&&r.stack?r.stack:"",e="[WorkerError][".concat(t,"]").concat(e," ").concat(p.taskInfo.url),0!==p.ffmpeg_errno&&y.error("[FFMPEG INTERNAL] ".concat(p.ffmpeg_errno," (").concat(p.ffmpeg_errmsg,")"));var a={__status__:"__WORKER_ERROR__",errType:t,errMsg:e,stack};return Object.assign(a,n),self.postMessage(a),a}function P(t){return A.apply(this,arguments)}function A(){return A=s(o().mark((function t(e){var r,n,a=arguments;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=a.length>1&&void 0!==a[1]?a[1]:3,t.prev=1,t.next=4,fetch(e,{method:"HEAD"});case 4:return n=t.sent,t.abrupt("return",n.headers);case 8:if(t.prev=8,t.t0=t.catch(1),!((r-=1)>0)){t.next=17;break}return t.next=14,P(e,r);case 14:return t.abrupt("return",t.sent);case 17:return R(d,"getHeaders error: "+T(t.t0),t.t0),t.abrupt("return",null);case 19:case"end":return t.stop()}}),t,null,[[1,8]])}))),A.apply(this,arguments)}function M(t,e){for(var r=new Uint8Array(t),n=0;n<t.byteLength&&e+n<p.decryptor_array.length;n++)r[n]^=p.decryptor_array[n];return r}function z(t){return U.apply(this,arguments)}function U(){return(U=s(o().mark((function t(e){var r,n,a,i;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p.disposingProcess=!0,r=e.disposeOptions||{},n=r.terminateWorker,t.prev=3,!p.fetchControllerList){t.next=18;break}a=0;case 6:if(!(a<p.fetchControllerList.length)){t.next=18;break}t.prev=7,(i=p.fetchControllerList[a])&&i.abort(),t.next=15;break;case 12:return t.prev=12,t.t0=t.catch(7),t.abrupt("continue",15);case 15:a++,t.next=6;break;case 18:e=e||{};case 19:if(t.prev=19,n){t.next=23;break}return t.next=23,H();case 23:return k(),v(),p.disposingProcess=!1,V({},Z(e)),n&&(g(),p.close&&p.close()),t.finish(19);case 29:case"end":return t.stop()}}),t,null,[[3,,19,29],[7,12]])})))).apply(this,arguments)}function D(t){if(t&&p.fetchControllerList&&p.fetchControllerList.length){for(var e=[],r=0;r<p.fetchControllerList.length;r++){var n=p.fetchControllerList[r];if(n.__mid__!==t.__mid__)e.push(n);else try{n&&n.abort()}catch(t){continue}}p.fetchControllerList=e}}function F(t,e,r){return new Promise((function(n,a){var i=t.url,u=t.start,c=t.end;void 0===e&&(e=p.networkRetryTimes);var f,l=r?p.networkRetryTimeout:p.networkTimeout,h=Math.abs(c-u)+1,m=c?"bytes=".concat(u,"-").concat(c):"bytes=".concat(u,"-"),w=Date.now();try{var g=new XMLHttpRequest;(f=g)&&(p.fetchControllerList=p.fetchControllerList||[],f.__mid__=Date.now(),p.fetchControllerList.push(f)),g.open("GET",i),g.setRequestHeader("range",m),g.timeout=l,g.responseType="arraybuffer",g.onreadystatechange=function(t){if(p.disposingProcess)return D(g),void a("abort");if(4===g.readyState){if(g.status>=200&&g.status<300){var e=new Uint8Array(g.response),o=Date.now()-w;if(f=(f={url:i,startIdx:u,size:e.byteLength,cost:o,timeout:l,startTs:w,isRetry:!!r})||{},V(Object.assign(f,{cmd:"ON_REQUEST_SUCCESS"})),p.taskInfo.disableDecrypt)n(e);else{var s=M(e,u);n(s)}}else if(g.status>=400){var c="[NetWork Error]url: ".concat(i,", status: ").concat(g.status);R("NETWORK_STATUS_CODE_ERROR",c,{},{networkInfo:{status:g.status},size:h,timeout:l,startTs:w,startIdx:u}),a(c)}D(g)}var f},g.ontimeout=s(o().mark((function r(){var s,c,f;return o().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(s="[worker xhr ontimeout]".concat(i),c="[NetWork Error]".concat(s),D(g),!p.disposingProcess){r.next=6;break}return a(c),r.abrupt("return");case 6:if(!(e<=0)){r.next=11;break}R("NETWORK_TIMEOUT_ERROR",s,{},{startTs:w,size:h,startIdx:u,timeout:l}),a(c),r.next=27;break;case 11:return e--,r.prev=12,R("NETWORK_TIMEOUT_RETRY",s,{},{startTs:w,size:h,startIdx:u,timeout:l}),y.log("@@@start retry xhr timeout: ",e),r.next=17,F(t,e,!0);case 17:f=r.sent,n(f),r.next=24;break;case 21:r.prev=21,r.t0=r.catch(12),a(r.t0);case 24:return r.prev=24,y.log("@@@end retry xhr timeout: ",e),r.finish(24);case 27:case"end":return r.stop()}}),r,null,[[12,21,24,27]])}))),g.addEventListener("error",function(){var r=s(o().mark((function r(s){var c,f,m;return o().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(c="[worker xhr onerror]".concat(s.type,": ").concat(s.loaded,", ").concat(i),f="[NetWork Error]".concat(c),D(g),!p.disposingProcess){r.next=6;break}return a(f),r.abrupt("return");case 6:if(!(e<=0)){r.next=11;break}R(d,c,{},{startTs:w,size:h,startIdx:u,timeout:l}),a(f),r.next=22;break;case 11:return e--,r.prev=12,r.next=15,F(t,e);case 15:m=r.sent,n(m),r.next=22;break;case 19:r.prev=19,r.t0=r.catch(12),a(r.t0);case 22:case"end":return r.stop()}}),r,null,[[12,19]])})));return function(t){return r.apply(this,arguments)}}()),g.send()}catch(t){R(d,"".concat(T(t),", ").concat(i),t,{startTs:w,size:h,timeout:l,startIdx:u}),a(t)}}))}function j(){var t=p.info_file.next_ss;return-1===Number(t)||p.disposingProcess}function W(){V({cmd:"CUT_ENDED"})}function N(t){return G.apply(this,arguments)}function G(){return(G=s(o().mark((function t(e){var r,n,a,i,u,s,c,f,l,d,w,g;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p.cutFmp4Idle=!1,t.prev=2,p.fmp4Index++,r=p.fmp4Index,x(p.winLargeSize),n=e&&"number"==typeof e.timestampOffset,a=n?1e3*Math.ceil(e.timestampOffset)*1e3:void 0,i=!(1!==r&&(!n||0!=a)),(n||1===r)&&(p.segmentSmallCount=3),p.segmentSmallCount>0?(_(p.segmentSmallDuration),p.segmentSmallCount--):_(p.segmentLargeDuration),n&&0===a&&(p.info_file.next_ss="0",p.info_file.next_dts_v="0",p.info_file.next_dts_a="0"),u="wasm:outputStream_".concat(r),s=n&&a>0?"".concat(a):p.info_file.next_ss,c=n&&a>0?"null":p.info_file.next_dts_v,f=n&&a>0?"null":p.info_file.next_dts_a,y.log("###[worker] next_ss=".concat(s," timestamp=").concat(a)),j()&&!n){t.next=52;break}return p.last_ss=s,y.time("@@@wxTransSingleFmp4EncryptJs"),t.next=22,Module.wxTransSingleFmp4EncryptJs("wasm:inputStream",u,i,"null"==c,p.segmentDuration,s,c,f);case 22:if(p.info_file=t.sent,y.timeEnd("@@@wxTransSingleFmp4EncryptJs"),"number"==typeof(l=p.info_file.ffmpeg_ret)&&0===l){t.next=30;break}return d="ffmpeg return error: ".concat(JSON.stringify(p.info_file)),w=R(h,d),p.cutFmp4Idle=!0,t.abrupt("return",{success:!1,ffmpegRetInfo:w});case 30:if("OK"===p.io_errmsg){t.next=34;break}return p.cutFmp4Idle=!0,p.io_errmsg="OK",t.abrupt("return",{success:!1});case 34:if(!p.disposingProcess){t.next=37;break}return p.cutFmp4Idle=!0,t.abrupt("return",{success:!0});case 37:if(!p.seekTaskCb){t.next=41;break}return p.seekTaskCb(),p.seekTaskCb=null,t.abrupt("return",{success:!0});case 41:if(!j()){t.next=45;break}return W(),p.cutFmp4Idle=!0,t.abrupt("return");case 45:if(!p.pauseProcess){t.next=48;break}return p.cutFmp4Idle=!0,t.abrupt("return",{success:!0});case 48:return e=void 0,t.abrupt("continue",0);case 52:W(),p.cutFmp4Idle=!0;case 54:return t.abrupt("return",{success:!0});case 57:return t.prev=57,t.t0=t.catch(2),R(m,T(t.t0),t.t0),p.cutFmp4Idle=!0,g=Object.assign({},p.info_file,{message:T(t.t0),stack:t.t0.stack||""}),t.abrupt("return",{success:!1,ffmpegRetInfo:g});case 63:t.next=0;break;case 65:case"end":return t.stop()}}),t,null,[[2,57]])})))).apply(this,arguments)}function H(){return K.apply(this,arguments)}function K(){return(K=s(o().mark((function t(){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!p.cutFmp4Idle||p.downloading){t.next=2;break}return t.abrupt("return",!0);case 2:return t.abrupt("return",new Promise((function(t){var e=setInterval((function(){p.cutFmp4Idle&&!p.downloading&&(t(!0),clearInterval(e))}),10)})));case 3:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function J(t){p.pauseProcess=t}function Y(t){t.firstRawBuf=null,p.registFmp4ReadyCb((function(e,n){t?(y.time("@@@registFmp4ReadyCb"),p.postMessage(r(r({success:!0,buffer:e.buffer},t),{},{fmp4Index:p.fmp4Index,duration:n}),[e.buffer]),t=null):p.postMessage({success:!0,buffer:e.buffer,cmd:"AUTO_CUT",fmp4Index:p.fmp4Index},[e.buffer])}))}function q(t,e){if(t&&!t.success){var n=Object.assign(r(r({},e),{},{fmp4Index:p.fmp4Index}),t);p.postMessage(n)}}function Q(t){var e,r=t=t||{},n=r.timeout,a=r.winBufSize,i=r.networkRetryTimes,o=r.retryTimeout,u=r.useLruCache,s=r.lruCacheSize;"number"==typeof n&&n>0&&function(t){"number"==typeof t&&t>0&&(p.networkTimeout=t)}(n),"number"==typeof o&&o>0&&function(t){"number"==typeof t&&t>0&&(p.networkRetryTimeout=t)}(o),"number"==typeof i&&i>0&&"number"==typeof(e=i)&&e>0&&(p.networkRetryTimes=e),"number"==typeof a&&a>0&&function(t){"number"==typeof t&&t>0&&(p.winLargeSize=t)}(a),"boolean"==typeof u&&u&&p.lruCache&&p.lruCache.updateLruMaxSize(s)}function X(t){return $.apply(this,arguments)}function $(){return($=s(o().mark((function t(e){var r,n,a,i,u,c,f,l,h,d,m,w,g;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.url,n=e.seed,a=e.disableDecrypt,i=e.first,u=e.timestampOffset,c=e.segmentDuration,f=e.firstRawBuf,l=e.contentLen,h=e.debug,d=e.debugTimeLog,m=e.useLruCache,w=e.lruCacheSize,y.log("@@@lru config: ",m,w,i),!p.disposingProcess){t.next=4;break}return t.abrupt("return");case 4:if(g=!!("number"==typeof u&&u>=0),!i&&g){t.next=16;break}if(!p.cutFmp4Idle){t.next=12;break}k(),m?b(w):v(),Q(e),t.next=14;break;case 12:return y.error("startCut: WORKER_CMD==CUT but wasm is running"),t.abrupt("return");case 14:t.next=17;break;case 16:J(!1);case 17:if(f&&B(f),l&&S(l),p.taskInfo.debug=h,p.taskInfo.debugTimeLog=d,p.taskInfo.url=r,p.taskInfo.seed=n,p.taskInfo.disableDecrypt=a,p.segmentLargeDuration=c||5,p.decryptor||a){t.next=28;break}return t.next=28,p.initDecrtptor(n);case 28:if(i||!g){t.next=40;break}if(!p.cutFmp4Idle){t.next=37;break}return Y(e),t.next=33,N(e);case 33:q(t.sent,e),t.next=38;break;case 37:p.registSeekTaskCb(s(o().mark((function t(){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return Y(e),t.next=3,N(e);case 3:q(t.sent,e);case 5:case"end":return t.stop()}}),t)}))));case 38:t.next=41;break;case 40:p.firstWinBuf||(y.time("@@@firstWinBuf"),p.registFirstWinBufferOkCb(s(o().mark((function t(){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return y.timeEnd("@@@firstWinBuf"),Y(e),t.next=4,N(e);case 4:q(t.sent,e);case 6:case"end":return t.stop()}}),t)})))),x(p.winSmallSize),C({url:r}));case 41:y.time("@@@registFmp4ReadyCb");case 42:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function V(t,e){t=t||{},Object.assign(t,{fmp4Index,__cbId__:e}),self.postMessage&&self.postMessage(t)}function Z(t){return(t=t||{}).__cbId__}function tt(t){return et.apply(this,arguments)}function et(){return(et=s(o().mark((function t(e){var r,n,a;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.buf,n=e.seed,a=e.start,t.next=3,p.initDecrtptor(n);case 3:V({buffer:M(r,a)},Z(e));case 5:case"end":return t.stop()}}),t)})))).apply(this,arguments)}k(),p.outputBufferIncSize=16777216,p.outputBuffer=new Uint8Array(p.outputBufferIncSize),p.registSeekTaskCb=function(t){p.seekTaskCb=t},p.registFirstWinBufferOkCb=function(t){p.firstWinBufferOkCb=t},p.registFmp4ReadyCb=function(t){p.fmp4ReadyCallBack=t},p.initDecrtptor=function(){var t=s(o().mark((function t(e){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,new Module.WxIsaac64(e);case 2:return p.decryptor=t.sent,t.next=5,p.decryptor.generate(131072);case 5:return t.next=7,p.decryptor.delete();case 7:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),self.onerror=function(t){R("WORKER_ERROR",t.toString(),t)},p.getContentLen=function(){var t=s(o().mark((function t(e){var r,n,a,i,u;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!p.taskInfo.size){t.next=2;break}return t.abrupt("return",p.taskInfo.size);case 2:return r=null,t.prev=3,t.next=6,P(e);case 6:if(n=t.sent){t.next=9;break}return t.abrupt("return",null);case 9:(a=n.get("content-length")||n.get("CONTENT-LENGTH"))?r=Number(a):"string"==typeof(i=n.get("content-range")||n.get("CONTENT-RANGE"))&&i.includes("/")&&(u=i.split("/")[1],r=Number(u)),"number"!=typeof r?R(d,"can not get content-length/content-range"):p.taskInfo.size=r,t.next=17;break;case 14:t.prev=14,t.t0=t.catch(3),R(d,"get content-length error: "+T(t.t0),t.t0);case 17:return t.abrupt("return",r);case 18:case"end":return t.stop()}}),t,null,[[3,14]])})));return function(e){return t.apply(this,arguments)}}(),p.wasm_ffmpeg_fopen=function(){var t=s(o().mark((function t(e,r,n){var a,i,u,s;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=Object.keys(files).length,a+=1,t.prev=2,i=new Uint8Array(Module.HEAPU8.buffer,e,r),u=String.fromCharCode.apply(null,i),t.next=7,getContentLen(p.taskInfo.url);case 7:return s=t.sent,files[a]=0==n?[u,n,0,s]:[u,n,0,0],t.abrupt("return",a);case 12:return t.prev=12,t.t0=t.catch(2),p.io_errmsg="wasm_ffmpeg_fopen",R(h,T(t.t0),t.t0),t.abrupt("return",-1);case 17:case"end":return t.stop()}}),t,null,[[2,12]])})));return function(e,r,n){return t.apply(this,arguments)}}(),p.wasm_ffmpeg_fread=function(){var t=s(o().mark((function t(e,r,n,i){var u,s,c,f,l,d,m,w,g;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(files[e]){t.next=3;break}return R(h,"[wasm_ffmpeg_fread] can't find fd data"),t.abrupt("return",0);case 3:if(t.prev=3,(u=a(files[e],4))[0],s=u[1],c=u[2],u[3],f=new Uint8Array(Module.HEAPU8.buffer,r,n),0==s){t.next=8;break}throw"must be read-only mode";case 8:if(!p.disposingProcess){t.next=10;break}return t.abrupt("return",0);case 10:return t.next=12,getContentLen(p.taskInfo.url);case 12:if(l=t.sent,n=Math.min(n,l-c),d=c,m=c+n-1,p.lruCache&&(w=p.lruCache.getBuffer(d,m)),y.log("@@@[fread]start: ".concat(d,", end: ").concat(m,", size: ").concat(n/1024,", hitLruCache: ").concat(!!w)),w){t.next=24;break}return g={url:p.taskInfo.url,start:d,end:m,stream_id:i},t.next=22,O(g);case 22:w=t.sent,p.lruCache&&p.lruCache.set(d,m,w.slice(0,n));case 24:if(w){t.next=26;break}return t.abrupt("return",-1);case 26:return f.set(w.subarray(0,n)),files[e][2]+=n,p.lastBytesRead=c,t.abrupt("return",n);case 32:if(t.prev=32,t.t0=t.catch(3),!p.disposingProcess){t.next=37;break}return console.warn("@@@[wasm_ffmpeg_fread] disposing",t.t0),t.abrupt("return",0);case 37:return p.io_errmsg="wasm_ffmpeg_fread",R(h,"[wasm_ffmpeg_fread] ".concat(T(t.t0)),t.t0),t.abrupt("return",-1);case 40:case"end":return t.stop()}}),t,null,[[3,32]])})));return function(e,r,n,a){return t.apply(this,arguments)}}(),p.wasm_ffmpeg_fwrite=function(t,e,r){if(!files[t])return R(h,"[wasm_ffmpeg_fwrite] can't find fd data"),r;if(p.disposingProcess)return console.warn("@@@[wasm_ffmpeg_fwrite] disposing"),r;try{var n=a(files[t],4),i=(n[0],n[1],n[2]),o=(n[3],new Uint8Array(Module.HEAPU8.buffer,e,r));if(i+r>=p.outputBuffer.byteLength){var u=new Uint8Array(i+r+p.outputBufferIncSize);u.set(p.outputBuffer),p.outputBuffer=u}for(var s=0;s<r;s++)p.outputBuffer[i+s]=o[s];return files[t][2]=i+r,r}catch(t){return p.io_errmsg="wasm_ffmpeg_fwrite",R(h,"[wasm_ffmpeg_fwrite]: ".concat(T(t)),t),-1}},p.wasm_ffmpeg_fseek=function(t,e,r,n,i){if(files[t])try{var o=new Uint8Array(Module.HEAPU8.buffer,e,r),u=parseInt(String.fromCharCode.apply(null,o)),s=a(files[t],4),c=(s[0],s[1],s[2],s[3]);if(0==n)files[t][2]=u;else if(1==n)files[t][2]+=u;else{if(2!=n)throw"unknown whence in seek";files[t][2]=c+u}for(var f=files[t][2].toString(),l=new Uint8Array(Module.HEAPU8.buffer,i,32),d=0;d<f.length;d++)l[d]=f.charCodeAt(d)}catch(t){return p.io_errmsg="wasm_ffmpeg_fseek",void R(h,"[wasm_ffmpeg_fseek] ".concat(T(t)),t)}else R(h,"[wasm_ffmpeg_fseek] can't find fd data")},p.wasm_ffmpeg_fclose=function(t,e){var r=p.files;if(r[t])try{var n=a(r[t],4),i=(n[0],n[1]),o=n[2];if(n[3],0!=i&&o>0){var u=p.outputBuffer.slice(0,o);p.info_file.duration_v=p.info_file.duration_a=e,p.disposingProcess||p.fmp4ReadyCallBack&&p.fmp4ReadyCallBack(u,e)}}catch(t){p.io_errmsg="wasm_ffmpeg_fclose",R(h,"[wasm_ffmpeg_fclose] ".concat(T(t)),t)}else R(h,"[wasm_ffmpeg_fclose] can't find fd data")},p.wasm_ffmpeg_fsize=function(t,e){if(files[t])for(var r=a(files[t],4),n=(r[0],r[1]),i=r[2],o=r[3],u=(0!=n?i:o).toString(),s=new Uint8Array(Module.HEAPU8.buffer,e,32),c=0;c<u.length;c++)s[c]=u.charCodeAt(c);else R(h,"[wasm_ffmpeg_fsize] can't find fd data")},p.wasm_ffmpeg_error_report=function(t,e,r){p.ffmpeg_errno=t;var n=new Uint8Array(Module.HEAPU8.buffer,e,r);p.ffmpeg_errmsg=String.fromCharCode.apply(null,n)},p.wasm_isaac_generate=function(t,e){p.decryptor_array=new Uint8Array(e);var r=new Uint8Array(Module.HEAPU8.buffer,t,e);p.decryptor_array.set(r.reverse())},p.onmessage=function(){var t=s(o().mark((function t(e){var r,n;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.data,"CUT"!==(n=r.cmd)){t.next=6;break}X(r),t.next=13;break;case 6:if("DISPOSE"!==n){t.next=12;break}return y.log("@@@[decryptWorker]worker start dispose"),t.next=10,z(r);case 10:t.next=13;break;case 12:"PAUSE"===n?(p.pauseProcess||J(!0),V({},Z(r))):"RESUME"===n?(p.pauseProcess&&!j()&&(J(!1),N()),V({},Z(r))):"UPDATE_CONFIG"===n?Q(r):"DECRYPT_BUFFER"===n&&tt(r);case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()})();