tvbox/0130/道长JS/cat/lib/hls.js

2 lines
32 KiB
JavaScript
Raw Normal View History

2024-02-12 02:37:55 +02:00
let t={};function e(e){if(t.strictMode)throw e;t.silent||console.error(e.message)}function s(t,...s){for(const[i,n]of s.entries())n||e(new Error(`${t} : Failed at [${i}]`))}function i(...t){for(const[s,[i,n]]of t.entries())i&&(n||e(new Error(`Conditional Assert : Failed at [${s}]`)))}function n(...t){for(const[s,i]of t.entries())void 0===i&&e(new Error(`Param Check : Failed at [${s}]`))}function a(...t){for(const[s,[i,n]]of t.entries())i&&void 0===n&&e(new Error(`Conditional Param Check : Failed at [${s}]`))}function r(t){e(new Error(`Invalid Playlist : ${t}`))}function o(t,e=10){if("number"==typeof t)return t;const s=10===e?Number.parseFloat(t):Number.parseInt(t,e);return Number.isNaN(s)?0:s}function E(t){(t.startsWith("0x")||t.startsWith("0X"))&&(t=t.slice(2));const e=new Uint8Array(t.length/2);for(let s=0;s<t.length;s+=2)e[s/2]=o(t.slice(s,s+2),16);return e}function T(t,s=0,i=t.length){i<=s&&e(new Error(`end must be larger than start : start=${s}, end=${i}`));const n=[];for(let e=s;e<i;e++)n.push(`0${(255&t[e]).toString(16).toUpperCase()}`.slice(-2));return`0x${n.join("")}`}function u(t,e,s=0){let i=-1;for(let n=0,a=0;n<t.length;n++)if(t[n]===e){if(a++===s)return[t.slice(0,n),t.slice(n+1)];i=n}return-1!==i?[t.slice(0,i),t.slice(i+1)]:[t]}function c(t){const e=[];let s=!1;for(const i of t)"-"!==i&&"_"!==i?s?(e.push(i.toUpperCase()),s=!1):e.push(i.toLowerCase()):s=!0;return e.join("")}function l(t){return`${t.getUTCFullYear()}-${("0"+(t.getUTCMonth()+1)).slice(-2)}-${("0"+t.getUTCDate()).slice(-2)}T${("0"+t.getUTCHours()).slice(-2)}:${("0"+t.getUTCMinutes()).slice(-2)}:${("0"+t.getUTCSeconds()).slice(-2)}.${("00"+t.getUTCMilliseconds()).slice(-3)}Z`}function h(e={}){t=Object.assign(t,e)}function X(){return Object.assign({},t)}class p{constructor({type:t,uri:e,groupId:s,language:a,assocLanguage:r,name:o,isDefault:E,autoselect:T,forced:u,instreamId:c,characteristics:l,channels:h}){n(t,s,o),i(["SUBTITLES"===t,e],["CLOSED-CAPTIONS"===t,c],["CLOSED-CAPTIONS"===t,!e],[u,"SUBTITLES"===t]),this.type=t,this.uri=e,this.groupId=s,this.language=a,this.assocLanguage=r,this.name=o,this.isDefault=E,this.autoselect=T,this.forced=u,this.instreamId=c,this.characteristics=l,this.channels=h}}class I{constructor({uri:t,isIFrameOnly:e=!1,bandwidth:s,averageBandwidth:i,score:a,codecs:r,resolution:o,frameRate:E,hdcpLevel:T,allowedCpc:u,videoRange:c,stableVariantId:l,programId:h,audio:X=[],video:p=[],subtitles:I=[],closedCaptions:N=[],currentRenditions:d={audio:0,video:0,subtitles:0,closedCaptions:0}}){n(t,s),this.uri=t,this.isIFrameOnly=e,this.bandwidth=s,this.averageBandwidth=i,this.score=a,this.codecs=r,this.resolution=o,this.frameRate=E,this.hdcpLevel=T,this.allowedCpc=u,this.videoRange=c,this.stableVariantId=l,this.programId=h,this.audio=X,this.video=p,this.subtitles=I,this.closedCaptions=N,this.currentRenditions=d}}class N{constructor({id:t,value:e,uri:i,language:a}){n(t,e||i),s("SessionData cannot have both value and uri, shoud be either.",!(e&&i)),this.id=t,this.value=e,this.uri=i,this.language=a}}class d{constructor({method:t,uri:e,iv:s,format:r,formatVersion:o}){n(t),a(["NONE"!==t,e]),i(["NONE"===t,!(e||s||r||o)]),this.method=t,this.uri=e,this.iv=s,this.format=r,this.formatVersion=o}}class A{constructor({hint:t=!1,uri:e,mimeType:s,byterange:i}){n(e),this.hint=t,this.uri=e,this.mimeType=s,this.byterange=i}}class S{constructor({id:t,classId:e,start:s,end:r,duration:o,plannedDuration:E,endOnNext:T,attributes:u={}}){n(t),a([!0===T,e]),i([r,s],[r,s<=r],[o,o>=0],[E,E>=0]),this.id=t,this.classId=e,this.start=s,this.end=r,this.duration=o,this.plannedDuration=E,this.endOnNext=T,this.attributes=u}}class f{constructor({type:t,duration:e,tagName:s,value:i}){n(t),a(["OUT"===t,e]),a(["RAW"===t,s]),this.type=t,this.duration=e,this.tagName=s,this.value=i}}class R{constructor(t){n(t),this.type=t}}class m extends R{constructor({isMasterPlaylist:t,uri:e,version:s,independentSegments:i=!1,start:a,source:r}){super("playlist"),n(t),this.isMasterPlaylist=t,this.uri=e,this.version=s,this.independentSegments=i,this.start=a,this.source=r}}class g extends m{co