(function(d,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(d=typeof globalThis<"u"?globalThis:d||self,f(d.playlist={}))})(this,function(d){"use strict";const f={"tvg-id":"tvgId","tvg-name":"tvgName","tvg-language":"tvgLanguage","tvg-logo":"tvgLogo","tvg-url":"tvgUrl","tvg-rec,":"tvgRec","group-title":"groupTitle",timeshift:"timeshift",catchup:"catchup","catchup-days":"catchupDays","catchup-source":"catchupSource","x-tvg-url":"xTvgUrl","url-tvg":"urlTvg"},x=32,$=35,O=61,T=58,b=44,U=45,y=49,I=50,A=51,M=52,L=53,N=54,S=55,w=56,j=57,E=48,v=10,D=9,R=13,l=69,p=88,C=84,X=73,k=78,q=70,H=77,P=72,z=104,Q=85,V=[E,y,I,A,M,L,N,S,w,j,U];function B(c){const r=[],e={};let t=0,a={},u="",s=null;for(;t-1&&g>-1&&n>g&&(i=g),i===-1&&(i=h),a.duration=parseInt(c.slice(t,i),10),t=i;continue}if(o===$)if(s=null,c.charCodeAt(t+1)===l&&c.charCodeAt(t+2)===p&&c.charCodeAt(t+3)===C&&c.charCodeAt(t+4)===H&&c.charCodeAt(t+5)===A&&c.charCodeAt(t+6)===Q)t+=6,s="header";else if(c.charCodeAt(t+1)===l&&c.charCodeAt(t+2)===p&&c.charCodeAt(t+3)===C&&c.charCodeAt(t+4)===X&&c.charCodeAt(t+5)===k&&c.charCodeAt(t+6)===q&&c.charCodeAt(t+7)===T)t+=7,s="channel",a={};else{t=h;continue}if(o===z||o===P){s="http",a.url=c.slice(t,h).trim(),t=h,r.push(a),a={};continue}if(o===b){s="channel",a.name=c.slice(t+1,h).trim(),t=h,s=null;continue}if(o>64&&o<91||o>96&&o<123||o===45){const n=c.indexOf("=",t);u=c.slice(t,n),t=n;continue}if(o===O){t=t+2;const n=c.indexOf('"',t),g=c.slice(t,n);t=n;const i=f[u];i?s==="header"?e[i]=g:a[i]=g:(a.extras=a.extras||{},a.extras[u]=g),u=""}t++}return{channels:r,headers:e}}function G(c){let r="#EXTM3U";if(c.headers&&Object.entries(c.headers))for(const[e,t]of Object.entries(c.headers))r+=` ${e}="${t}"`;for(const e of c.channels)if(e.url){if(r+=` #EXTINF:`,r+=e!=null&&e.duration?e.duration:"-1",e.tvgId&&(r+=` tvg-id="${e.tvgId}"`),e.tvgName&&(r+=` tvg-name="${e.tvgName}"`),e.tvgLanguage&&(r+=` tvg-language="${e.tvgLanguage}"`),e.tvgLogo&&(r+=` tvg-logo="${e.tvgLogo}"`),e.tvgRec&&(r+=` tvg-rec="${e.tvgRec}"`),e.tvgChno&&(r+=` tvg-chno="${e.tvgChno}"`),e.groupTitle&&(r+=` group-title="${e.groupTitle}"`),e.tvgUrl&&(r+=` tvg-url="${e.tvgUrl}"`),e.timeshift&&(r+=` timeshift="${e.timeshift}"`),e.catchup&&(r+=` catchup="${e.catchup}"`),e.catchupDays&&(r+=` catchup-days="${e.catchupDays}"`),e.catchupSource&&(r+=` catchup-source="${e.catchupSource}"`),e.extras)for(const[t,a]of Object.entries(e.extras))r+=` ${t}="${a}"`;r+=",",e.name&&(r+=e.name),r+=` ${e.url}`}return r}d.parseM3U=B,d.writeM3U=G,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});