(function(g){var window=this;'use strict';var Fjb=function(a){var b=new g.WK("und",new g.aN("Default","und",!0));b.captionTracks=a.captionTracks;return b},Gjb=function(a){return new g.Ce(function(b,c){var d=a.length,e=[]; if(d)for(var f=function(n,p){d--;e[n]=p;d==0&&b(e)},h=function(n){c(n)},l=0,m;l0&&(a.channel.postMessage(h),Flb(a,h)));return l.return(f)})},Glb=function(a,b){a.observers.push(b); return function(){var c=a.observers.indexOf(b);c>=0&&a.observers.splice(c,1)}},Z5=function(a,b,c){return Y5(a,{mode:"readwrite", Pb:!0},function(d){return U5(d,b,c)})},Hlb=function(a,b){return Y5(a,{mode:"readwrite", Pb:!0},function(c){return xlb(c,b,"offlineOrchestrationActionWrapperEntity")})},Ilb=function(a,b){return Y5(a,{mode:"readwrite", Pb:!0},function(c){return V5(c,b)})},Jlb=function(a){return Y5(a,{mode:"readwrite", Pb:!0},function(b){return Alb(b,"videoPlaybackPositionEntity")})},$5=function(a,b,c){return Y5(a,{mode:"readonly", Pb:!0},function(d){return R5(d,b,c)})},a6=function(a,b,c){return Y5(a,{mode:"readonly", Pb:!0},function(d){return S5(d,b,c)})},Flb=function(a,b){a=g.w(a.observers); for(var c=a.next();!c.done;c=a.next())c=c.value,c(b)},Klb=function(){var a,b,c; return g.J(function(d){if(d.j==1)return g.wa(d,2),g.G(d,g.Nt(),4);if(d.j!=2){a=d.B;if(!a||!g.Js()||typeof g.Ka.BroadcastChannel==="undefined")return d.return();b=new Elb;return d.return(new X5(a,b))}c=g.ya(d);c instanceof Error&&g.xw(c);return d.return()})},b6=function(){Llb||(Llb=Klb()); return Llb},Mlb=function(a){var b; a=(b=a.options)==null?void 0:b.persistenceOption;return a==="ENTITY_PERSISTENCE_OPTION_PERSIST"||a==="ENTITY_PERSISTENCE_OPTION_INMEMORY_AND_PERSIST"},Nlb=function(a){var b; return g.J(function(c){return c.j==1?g.G(c,b6(),2):(b=c.B)?g.G(c,Y5(b,"readwrite",function(d){for(var e={},f=g.w(a),h=f.next(),l={};!h.done;l={Jk:void 0,oG:void 0},h=f.next())l.Jk=h.value,l.Jk.entityKey&&Mlb(l.Jk)&&(l.oG=g.vc(l.Jk.payload),h=void 0,l.Jk.type==="ENTITY_MUTATION_TYPE_REPLACE"&&(h=function(m){return function(){return U5(d,m.Jk.payload[m.oG],m.oG)}}(l)),l.Jk.type==="ENTITY_MUTATION_TYPE_DELETE"&&(h=function(m){return function(){return V5(d,m.Jk.entityKey)}}(l)),l.Jk.type==="ENTITY_MUTATION_TYPE_UPDATE"&& (h=function(m){return function(){return Blb(d,m.Jk.entityKey,m.Jk.payload[m.oG],m.oG)}}(l)),h&&(e[l.Jk.entityKey]=e[l.Jk.entityKey]?e[l.Jk.entityKey].then(h):h())); return g.kt.all(Object.values(e))}),0):c.return()})},Olb=function(a){var b; return g.J(function(c){if(c.j==1){b=a.mutations;if(!b||b.length<=0)return c.return();if(g.YP){var d={type:"ENTITY_LOADED"};b!==void 0&&(d.payload=b);g.YP.dispatch(d)}return g.G(c,Nlb(b),2)}b.length=0;g.va(c)})},Plb=function(a){return a!==void 0},Qlb=function(a){var b=g.pP(); b=Object.assign({},b);a=Object.assign({},a);for(var c in b)a[c]?(b[c]!==4&&(b[c]=a[c]),delete a[c]):b[c]!==2&&(b[c]=4);Object.assign(b,a);g.oKa(b);JSON.stringify(b);return b},Rlb=function(a){var b,c; return g.J(function(d){if(d.j==1)return g.G(d,g.Nt(),2);if(d.j!=3)return(b=d.B)?g.G(d,g.sP(b),3):d.return();c=d.B;return d.return(g.rt(c,["index","media","captions"],{mode:"readwrite",Pb:!0},function(e){var f=IDBKeyRange.bound(a+"|",a+"~");e=[e.objectStore("index").delete(f),e.objectStore("media").delete(f),e.objectStore("captions").delete(f)];return g.kt.all(e).then(function(){})}))})},Slb=function(){var a,b; return g.J(function(c){if(c.j==1)return g.G(c,g.Nt(),2);if(c.j!=3){a=c.B;if(!a)throw g.it("rvdfd");return g.G(c,g.sP(a),3)}b=c.B;return c.return(g.rt(b,["index","media"],{mode:"readwrite",Pb:!0},function(d){var e={};return g.xt(d.objectStore("index"),{},function(f){var h=f.cursor.key.match(/^([\w\-_]+)\|(a|v)$/),l=g.kt.resolve(void 0);if(h){var m=h[1];h=h[2];e[m]=e[m]||{};var n;e[m][h]=g.tKa((n=f.getValue())==null?void 0:n.fmts)}else l=f.delete().then(function(){}); return g.kt.all([g.zt(f),l]).then(function(p){return g.w(p).next().value})}).then(function(){for(var f={},h=g.w(Object.keys(e)),l=h.next();!l.done;l=h.next()){l=l.value; var m=e[l].v;f[l]=e[l].a&&m?1:2}var n=Qlb(f);return g.ooa(d.objectStore("media"),{},function(p){var q=p.cursor.key.match(g.xKa);q&&f[q[1]]||d.objectStore("media").delete(p.cursor.key);return g.foa(p)}).then(function(){return n})})}))})},Tlb=function(a,b){var c,d; return g.J(function(e){if(e.j==1)return g.G(e,g.Nt(),2);if(e.j!=3){c=e.B;if(!c)throw g.it("wct");return g.G(e,g.sP(c),3)}d=e.B;return g.G(e,g.rt(d,["captions"],{mode:"readwrite",Pb:!0},function(f){var h=[];f=f.objectStore("captions");for(var l=0;l0},m6=function(a){return a.actionType==="OFFLINE_ORCHESTRATION_ACTION_TYPE_ADD"&&!!a.entityKey},n6=function(a){return a.actionType==="OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH"&&!!a.entityKey},o6=function(a){return a.actionType==="OFFLINE_ORCHESTRATION_ACTION_TYPE_DELETE"&&!!a.entityKey},umb=function(a){return a.actionType==="OFFLINE_ORCHESTRATION_ACTION_TYPE_UPDATE"&&!!a.entityKey}, p6=function(a,b,c,d,e){e=e===void 0?!1:e; var f,h,l,m,n,p;return g.J(function(q){if(q.j==1)return f=g.mK(a,b),h=g.mK(a,"downloadStatusEntity"),g.G(q,Y5(c,{mode:"readonly",Pb:!0},function(r){return g.kt.all([R5(r,f,b),R5(r,h,"downloadStatusEntity")])}),2); l=q.B;m=l.length?l[0]:void 0;if(!m)return q.Ha(0);n=vmb;if(p=l.length>1?l[1]:void 0){if(p.downloadState==="DOWNLOAD_STATE_USER_DELETED"&&!e)return q.return();p.downloadState=d}else p={key:h,downloadState:d};g.Dw(m,n,p);return g.G(q,Y5(c,{mode:"readwrite",Pb:!0},function(r){return g.kt.all([U5(r,m,b),U5(r,p,"downloadStatusEntity")])}),0)})},q6=function(a,b){return a.actionType===b.actionType&&a.entityKey===b.entityKey},r6=function(a,b){if(a&&a.transferState!=="TRANSFER_STATE_COMPLETE"&&a.transferState!== "TRANSFER_STATE_FAILED"){var c=g.lK(a.key).entityId; k6({transferStatusType:"TRANSFER_STATUS_TYPE_TERMINATED_BY_USER",statusType:"CANCELLED"},{videoId:c,Tl:a,offlineModeType:b})}},s6=function(a){if(!a||!a.thumbnails)return[]; var b=[];a=g.w(a.thumbnails);for(var c=a.next();!c.done;c=a.next())c=c.value,c.url&&b.push(c.url);return b},wmb=function(a,b,c){c=c===void 0?[]:c; var d,e,f,h,l,m,n,p,q,r,t,u,y;return g.J(function(A){if(A.j==1)return c.length?g.G(A,a6(a,b),2):A.return([]);d=A.B;e=new Set;f=g.w(d);for(h=f.next();!h.done;h=f.next())if(l=h.value,m=l.id||l.key)n=g.lK(m).entityId,e.add(n);p=[];q=g.w(c);for(r=q.next();!r.done;r=q.next())t=r.value,u=t.offlineVideoData,y=void 0,((y=u)==null?0:y.videoId)&&!e.has(u.videoId)&&p.push(t);return A.return(p)})},xmb=function(a,b,c){return new g.EP(a,{cotn:b, raw_player_response:c,download_media:!0,start:Infinity,disable_watch_next:!0})},ymb=function(){return{priority:1, retryScheduleIntervalsInSeconds:[1,2,4]}},t6=function(a,b,c,d,e,f,h,l,m,n,p){this.entityType=a; this.actionId=b;this.action=c;this.parentActionId=d;this.rootActionId=e===void 0?b:e;this.childActionIds=f;this.prereqActionId=h;this.postreqActionIds=l;this.hasChildActionFailed=n;this.retryScheduleIndex=0;this.j=p||Date.now();this.retryScheduleIndex=m||0},u6=function(a){if(!a.key)throw Error("Entity key is required."); if(!a.actionProto)throw Error("OfflineOrchestrationAction is required.");var b=g.lK(a.key),c=g.lK(a.actionProto.entityKey);return new t6(c.entityType,b.entityId,a.actionProto,a.parentActionId,a.rootActionId,a.childActionIds,a.prereqActionId,a.postreqActionIds,a.retryScheduleIndex,a.hasChildActionFailed,Number(a.enqueueTimeSec)*1E3)},v6=function(a){return{key:g.mK(a.actionId,"offlineOrchestrationActionWrapperEntity"), actionProto:a.action,parentActionId:a.parentActionId,rootActionId:a.rootActionId,childActionIds:a.childActionIds,prereqActionId:a.prereqActionId,postreqActionIds:a.postreqActionIds,retryScheduleIndex:a.retryScheduleIndex,hasChildActionFailed:a.hasChildActionFailed,enqueueTimeSec:(a.j/1E3).toFixed()}},zmb=function(){var a; return g.J(function(b){return b.j==1?g.G(b,kmb(),2):(a=b.B)?b.return(a.delete("yt-player-local-img")):b.return(!0)})},w6=function(a){var b,c; return g.J(function(d){if(d.j==1)return g.G(d,kmb(),2);if(d.j!=3){b=d.B;if(!b)throw Error("Cache API not supported");return a.length?g.G(d,b.open("yt-player-local-img"),3):d.return()}c=d.B;return g.G(d,Promise.all(a.map(function(e){return c.delete(e)})),0)})},x6=function(a){var b,c; return g.J(function(d){if(d.j==1)return g.G(d,kmb(),2);if(d.j!=3){b=d.B;if(!b)throw Error("Cache API not supported");return a.length?g.G(d,b.open("yt-player-local-img"),3):d.return()}c=d.B;return g.G(d,c.addAll(a),0)})},y6=function(a,b,c,d,e){var f,h,l,m,n,p,q,r,t,u,y,A,D,F,H,M,N,S,ba,ha,na,Y,R,W,v,V,cb,Ab,Va,fb,bb; return g.J(function(pb){switch(pb.j){case 1:return f=g.mK(a,"mainVideoEntity"),h=g.mK(a,"ytMainChannelEntity"),l=g.mK(a,"transfer"),m=g.mK(a,"videoDownloadContextEntity"),g.G(pb,Y5(b,{mode:"readonly",Pb:!0},function($a){return g.kt.all([R5($a,f,"mainVideoEntity"),R5($a,h,"ytMainChannelEntity"),R5($a,l,"transfer"),R5($a,m,"videoDownloadContextEntity"),S5($a,"ytMainChannelEntity"),S5($a,"offlineOrchestrationActionWrapperEntity")])}),2); case 2:n=pb.B;p=g.w(n);q=p.next().value;r=p.next().value;t=p.next().value;u=p.next().value;y=p.next().value;A=p.next().value;D=q;F=r;H=t;M=u;N=y;S=A;if(!D&&!F){pb.Ha(3);break}ba=D?s6(D.thumbnail):[];if(!F){ha=[];pb.Ha(4);break}return g.G(pb,Amb(F,N),5);case 5:ha=pb.B;case 4:return na=ha,g.G(pb,w6(ba.concat(na)),3);case 3:Y=[];R=g.mK(a,"downloadStatusEntity");W=g.w(S);for(v=W.next();!v.done;v=W.next())V=v.value,cb=g.lK(V.key).entityId,Ab=u6(V),Va=g.lK(Ab.action.entityKey).entityId,cb!==a&&Va!==a|| q6(c,V.actionProto)||Y.push(V.key);return g.G(pb,Y5(b,{mode:"readwrite",Pb:!0},function($a){var B=Y.map(function(C){return V5($a,C)}); B.push(V5($a,f,{Nw:!0}));B.push(V5($a,R,{Nw:!0}));return g.kt.all(B)}),7); case 7:bb=(fb=M)==null?void 0:fb.offlineModeType,e&&(j6(e),e.offlineModeType&&(bb=e.offlineModeType)),r6(H,bb),h6(d,{entityKey:f,failureReason:"OFFLINE_OPERATION_FAILURE_REASON_VIDEO_DELETED"}),g.va(pb)}})},Dmb=function(a,b,c,d){var e,f,h,l,m,n,p,q,r,t,u,y,A,D,F,H,M,N,S,ba,ha,na,Y,R,W,v,V,cb,Ab,Va,fb,bb,pb,$a,B,C,E,I,L,X,fa,ca,K,la,qa,ka,Ha,lb,Pb,qc; return g.J(function(Pa){switch(Pa.j){case 1:return e=g.mK(a,"mainPlaylistEntity"),f=g.mK(a,"ytMainChannelEntity"),g.G(Pa,Y5(b,{mode:"readonly",Pb:!0},function(Nc){return g.kt.all([R5(Nc,e,"mainPlaylistEntity"),R5(Nc,f,"ytMainChannelEntity"),S5(Nc,"mainPlaylistEntity"),S5(Nc,"mainDownloadsListEntity"),S5(Nc,"ytMainChannelEntity"),S5(Nc,"offlineOrchestrationActionWrapperEntity")])}),2); case 2:h=Pa.B;l=g.w(h);m=l.next().value;n=l.next().value;p=l.next().value;q=l.next().value;r=l.next().value;t=l.next().value;u=m;y=n;A=p;D=q;F=r;H=t;if(!u&&!y){Pa.Ha(3);break}M=u?Bmb(u):[];if(!y){N=[];Pa.Ha(4);break}return g.G(Pa,Amb(y,F),5);case 5:N=Pa.B;case 4:return S=N,g.G(Pa,w6(M.concat(S)),3);case 3:ba=[];ha=new Map;if(!u){Pa.Ha(7);break}return g.G(Pa,Cmb(u,A,D),8);case 8:ba=Pa.B;na=g.w(ba);for(Y=na.next();!Y.done;Y=na.next())R=Y.value,ha.set(R,{videoId:R,playlistId:a,offlineDeleteReason:"OFFLINE_DELETE_REASON_PARENT_LIST_DELETE"}); return g.G(Pa,Y5(b,{mode:"readonly",Pb:!0},function(Nc){return g.kt.all([S5(Nc,"transfer"),S5(Nc,"videoDownloadContextEntity")])}),9); case 9:W=Pa.B;v=g.w(W);V=v.next().value;cb=v.next().value;Ab=V;Va=cb;fb=g.w(Ab);for(bb=fb.next();!bb.done;bb=fb.next())pb=bb.value,$a=g.lK(pb.key).entityId,(B=ha.get($a))&&pb&&(B.cotn=pb.cotn);C=g.w(Va);for(E=C.next();!E.done;E=C.next())I=E.value,L=g.lK(I.key).entityId,(X=ha.get(L))&&I&&(X.offlineModeType=I.offlineModeType);case 7:fa=[];ca=g.w(H);for(K=ca.next();!K.done;K=ca.next())la=K.value,qa=g.lK(la.key).entityId,ka=u6(la),qa!==a&&ka.rootActionId!==a||q6(c,la.actionProto)||fa.push(la.key);Ha= g.mK(a,"mainPlaylistEntity");return g.G(Pa,Y5(b,{mode:"readwrite",Pb:!0},function(Nc){var ke=fa.map(function(Jd){return V5(Nc,Jd)}); ke.push(V5(Nc,Ha,{Nw:!0}));return g.kt.all(ke)}),10); case 10:if(!u){Pa.Ha(0);break}ba.reverse();if(!ba){Pa.Ha(0);break}lb=g.w(ba);Pb=lb.next();case 13:if(Pb.done){Pa.Ha(0);break}qc=Pb.value;return g.G(Pa,y6(qc,b,c,d,ha.get(qc)),14);case 14:Pb=lb.next(),Pa.Ha(13)}})},Fmb=function(a,b,c,d){var e,f,h,l,m,n,p,q,r; return g.J(function(t){if(t.j==1)return e=g.mK("DOWNLOADS_LIST_ENTITY_ID_MANUAL_DOWNLOADS","mainDownloadsListEntity"),f=new Map,g.G(t,Y5(a,{mode:"readwrite",Pb:!0},function(u){var y=S5(u,"transfer"),A=S5(u,"offlineOrchestrationActionWrapperEntity"),D=S5(u,"videoDownloadContextEntity"),F=R5(u,e,"mainDownloadsListEntity");return g.kt.all([y,A,D,F]).then(function(H){H=g.w(H);var M=H.next().value;var N=H.next().value;var S=H.next().value;var ba=H.next().value;H=Emb.map(function(na){return Alb(u,na)}); N=g.w(N);for(var ha=N.next();!ha.done;ha=N.next())ha=ha.value,q6(b,ha.actionProto)||H.push(V5(u,ha.key,{Nw:!0}));ba&&(ba.downloads=[],H.push(U5(u,ba,"mainDownloadsListEntity")));if(S)for(S=g.w(S),ba=S.next();!ba.done;ba=S.next())ba=ba.value,N=g.lK(ba.key).entityId,N=g.mK(N,"transfer"),f.set(N,ba.offlineModeType);return g.kt.all(H).then(function(){return M})})}),2); h=t.B;l=g.w(h);for(m=l.next();!m.done;m=l.next())n=m.value,r6(n,f.get(n.key)),p=g.lK(n.key).entityId,q={videoId:p,offlineDeleteReason:d,cotn:n.cotn,offlineModeType:f.get(n.key)},j6(q),r=g.mK(p,"mainVideoEntity"),h6(c,{entityKey:r,failureReason:"OFFLINE_OPERATION_FAILURE_REASON_VIDEO_DELETED"});return g.G(t,zmb(),0)})},Bmb=function(a,b){var c=[]; if(a.thumbnailStyleData){a=g.w(a.thumbnailStyleData);for(var d=a.next();!d.done;d=a.next()){var e=void 0,f=void 0,h=void 0;c=c.concat(s6((e=d.value)==null?void 0:(f=e.value)==null?void 0:(h=f.collageThumbnail)==null?void 0:h.coverThumbnail))}}b=s6(b);return c.concat(b)},Cmb=function(a,b,c){var d,e,f,h,l,m,n,p,q,r,t,u,y,A,D,F,H,M,N,S,ba,ha,na; return g.J(function(Y){d=[];e=new Set;if(c.length)for(f=g.w(c),h=f.next();!h.done;h=f.next())if(l=h.value,m=void 0,(m=l.downloads)==null?0:m.length)for(n=g.w(l.downloads),p=n.next();!p.done;p=n.next())q=p.value,q.videoItem&&(r=g.lK(q.videoItem).entityId,e.add(r));if(a.videos){t=g.w(a.videos);for(u=t.next();!u.done;u=t.next())y=u.value,A=JSON.parse(g.lK(y).entityId),A.videoId&&!e.has(A.videoId)&&d.push(A.videoId);D=g.w(b);for(F=D.next();!F.done;F=D.next())if(H=F.value,H.key!==a.key&&(M=H.videos))for(N= g.w(M),S=N.next();!S.done;S=N.next())ba=S.value,ha=JSON.parse(g.lK(ba).entityId),ha.videoId&&(na=d.indexOf(ha.videoId),na!==-1&&d.splice(na,1))}return Y.return(d)})},Amb=function(a,b){var c,d,e,f,h,l,m,n; return g.J(function(p){c=s6(a.avatar);d=g.w(b);for(e=d.next();!e.done;e=d.next())if(f=e.value,f.id!==a.id)for(h=g.w(s6(f.avatar)),l=h.next();!l.done;l=h.next())m=l.value,n=c.indexOf(m),n!==-1&&c.splice(n,1);return p.return(c)})},Gmb=function(a){var b; return g.J(function(c){b=g.Q(a.frameworkUpdates,z6);return a.frameworkUpdates&&b?g.G(c,Olb(b),0):c.return()})},Jmb=function(a){var b; if((b=a.onResponseReceivedActions)!=null&&b.length){var c;a=(c=g.Q(g.Q(a.onResponseReceivedActions[0],Hmb),Imb))==null?void 0:c.actions;if(a!=null&&a.length)return a}},Kmb=function(a){var b,c,d; return g.J(function(e){if(e.j==1)return a?g.G(e,$5(a,A6,"mainDownloadsListEntity"),2):e.return([]);b=e.B;return((c=b)==null?0:(d=c.downloads)==null?0:d.length)?e.return(b.downloads.map(function(f){var h;return(h=f.videoItem)!=null?h:""})):e.return([])})},Mmb=function(a,b){var c; return g.J(function(d){return d.j==1?g.G(d,Lmb(a,b),2):(c=d.B)?g.G(d,Y5(a,{mode:"readwrite",Pb:!0},function(e){var f=[U5(e,c.mainDownloadsLibraryEntity,"mainDownloadsLibraryEntity")];c.mainDownloadsListEntity&&f.push(U5(e,c.mainDownloadsListEntity,"mainDownloadsListEntity"));return g.kt.all(f)}),0):d.Ha(0)})},Lmb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D,F,H; return g.J(function(M){if(M.j==1)return c=g.mK("main_downloads_library_id","mainDownloadsLibraryEntity"),d=g.mK("DOWNLOADS_LIST_ENTITY_ID_MANUAL_DOWNLOADS","mainDownloadsListEntity"),g.G(M,Y5(a,{mode:"readonly",Pb:!0},function(N){return g.kt.all([R5(N,c,"mainDownloadsLibraryEntity"),R5(N,d,"mainDownloadsListEntity")])}),2); e=M.B;f=g.w(e);h=f.next().value;l=f.next().value;m=h;n=l;m||(m={id:c});p=g.w(b);for(q=p.next();!q.done;q=p.next())if(r=q.value,r===A6){if(m.smartDownloadsList)return M.return();m.smartDownloadsList=r}else if(t=g.lK(r).entityType,u={},t==="mainPlaylistEntity"?u.playlistItem=r:t==="mainVideoEntity"&&(u.videoItem=r),!g.Bc(u)){y=void 0;if((y=n)==null?0:y.downloads){A=!1;D=g.w(n.downloads);for(F=D.next();!F.done;F=D.next())if(H=F.value,H.playlistItem===r||H.videoItem===r){A=!0;break}A||n.downloads.push(u)}else n= {id:d,downloads:[u]};m.downloadsList=d}return M.return({mainDownloadsLibraryEntity:m,mainDownloadsListEntity:n})})},Nmb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A; return g.J(function(D){if(D.j==1)return c=g.mK("main_downloads_library_id","mainDownloadsLibraryEntity"),d=g.mK("DOWNLOADS_LIST_ENTITY_ID_MANUAL_DOWNLOADS","mainDownloadsListEntity"),g.G(D,Y5(a,{mode:"readonly",Pb:!0},function(F){return g.kt.all([R5(F,c,"mainDownloadsLibraryEntity"),R5(F,d,"mainDownloadsListEntity"),R5(F,A6,"mainDownloadsListEntity")])}),2); e=D.B;f=g.w(e);h=f.next().value;l=f.next().value;m=f.next().value;n=h;p=l;q=m;if(!n)return D.Ha(0);if(b===A6&&((r=q)==null?0:r.downloads))q.downloads=[];else if((t=p)==null?0:t.downloads)for(u=g.lK(b).entityType,y=0;y=d)})},cnb=function(a,b){var c,d,e; return g.J(function(f){switch(f.j){case 1:return g.wa(f,2),g.G(f,bnb(a,b),4);case 4:return d=f.B,g.G(f,Gmb(d),5);case 5:c=Jmb(d);g.xa(f,3);break;case 2:e=g.ya(f),f6("getAndProcessSmartDownloadsResponse request or processing error",e);case 3:return f.return(c)}})},dnb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D,F,H,M,N,S,ba,ha,na; return g.J(function(Y){switch(Y.j){case 1:return g.G(Y,b6(),2);case 2:c=Y.B;if(!c)return Y.return([]);d=[];if((e=b)==null?0:e.length){d=b;Y.Ha(3);break}return g.G(Y,a6(c,"musicPlaylist"),4);case 4:d=Y.B;case 3:if(!d.length)return Y.return([]);f=[];Date.now();h=g.w(d);l=h.next();case 5:if(l.done)return f.length?g.G(Y,Zmb(f),10):Y.return([]);m=l.value;n=void 0;q=(p=(n=m)==null?void 0:n.entityMetadata)&&p.nextAutoRefreshIntervalSeconds?Number(p.nextAutoRefreshIntervalSeconds):NaN;Number.isNaN(q);t=r= 0;if(!m.downloadMetadata){Y.Ha(8);break}return g.G(Y,$5(c,m.downloadMetadata,"musicPlaylistDownloadMetadataEntity"),9);case 9:u=Y.B,A=y=void 0,r=Number((A=(y=u)==null?void 0:y.addedTimestampMillis)!=null?A:"0")/1E3,F=D=void 0,t=Number((F=(D=u)==null?void 0:D.lastModifiedTimestampMillis)!=null?F:"0")/1E3;case 8:H=[];M=void 0;if((M=m.tracks)==null?0:M.length)for(N=g.w(m.tracks),S=N.next();!S.done;S=N.next())ba=S.value,H.push(g.lK(ba).entityId);ha={playlistId:m.playlistId,videoIds:H,offlineLastModifiedTimestamp:String(t.toFixed()), autoSync:a,offlineDateAddedTimestamp:String(r.toFixed())};f.push(ha);l=h.next();Y.Ha(5);break;case 10:return na=Y.B,Y.return(na)}})},bnb=function(a,b){var c,d,e,f,h,l,m,n,p,q; return g.J(function(r){switch(r.j){case 1:return c=g.cA(),g.G(r,b6(),2);case 2:d=r.B;if(!d){r.Ha(3);break}return g.G(r,dmb(d),4);case 4:e=r.B;case 3:var t=e;f={context:g.Ly(),browseId:"FEdownloads",browseRequestSupportedMetadata:{downloadsBrowseParams:{offlineFeatureSettingState:{isSdEnabled:a},offlineClientState:t,clientStateRequestData:{preferredFormatType:b}}}};h=g.Py(enb);g.wa(r,5);m={Fr:!0};return g.G(r,g.Sz(c,f,h,void 0,m),7);case 7:l=r.B;g.xa(r,6);break;case 5:n=g.ya(r);if(n instanceof g.$z)throw p= "DPS network manager error for smart downloads: "+n.message,f6(p,n),Error(p);f6("DPS fetch request error for smart downloads",n);throw Error("DPS fetch request error for smart downloads");case 6:q=G6(l);if(l)q!==void 0&&H6(q,"smart downloads");else throw f6("Network request failed for smart downloads"),Error("Network request failed for smart downloads");return r.return(l)}})},gnb=function(a,b){var c,d,e,f,h,l,m,n; return g.J(function(p){switch(p.j){case 1:return c=g.cA(),d={context:g.Ly(),videoPlaybackPositionEntities:a,lastSyncTimestampUsec:b},e=g.Py(fnb),g.wa(p,2),h={Fr:!0},g.G(p,g.Sz(c,d,e,void 0,h),4);case 4:f=p.B;g.xa(p,3);break;case 2:l=g.ya(p);if(l instanceof g.$z)throw m="VPPS network manager error: "+l.message,f6(m,l),Error(m);f6("VPPS fetch request error",l);throw Error("VPPS fetch request error");case 3:n=G6(f);if(f)n!==void 0&&H6(n,"position sync");else throw f6("Network request failed for position sync"), Error("Network request failed for position sync");return p.return(f)}})},inb=function(a,b,c){var d,e,f,h,l,m,n,p; return g.J(function(q){switch(q.j){case 1:d=g.cA();var r=c.refreshData,t=c.isEnqueuedForExpiredStreamUrlRefetch,u=c.K3,y=c.offlineSourceData,A={entityKey:a};r&&(A.refreshData=r);t&&(A.isExpiredStreamUrlRefetch=t);u&&(A.downloadParameters=u);y&&(A.offlineSourceData=y);e={context:g.LQ(b),signatureTimestamp:19936,videos:[A]};f=g.Py(hnb);g.wa(q,2);l={Fr:!0};return g.G(q,g.Sz(d,e,f,void 0,l),4);case 4:h=q.B;g.xa(q,3);break;case 2:m=g.ya(q);if(m instanceof g.$z)throw n="GetPDE network manager error: "+ m.message,f6(n,m),Error(n);f6("GetPDE fetch request error",m);throw Error("GetPDE fetch request error");case 3:p=G6(h);if(h)p!==void 0&&H6(p,"PDE");else throw f6("Network request failed for PDE"),Error("Network request failed for PDE");return q.return(h)}})},G6=function(a){var b; return(b=a.errorMetadata)==null?void 0:b.status},H6=function(a,b){b=b?" for "+b:""; if(a===0)throw a="Empty response body"+b,f6(a),Error(a);a="Response with error"+b;f6(a);throw Error(a);},Zmb=function(a){var b,c,d,e,f,h,l,m; return g.J(function(n){switch(n.j){case 1:return b=g.cA(),c=Ylb(a),d=g.Py(jnb),g.wa(n,2),f={Fr:!0},g.G(n,g.Sz(b,c,d,void 0,f),4);case 4:e=n.B;g.xa(n,3);break;case 2:h=g.ya(n);if(h instanceof g.$z)throw l="offlinePlaylistSyncCheck network manager error: "+h.message,f6(l,h),Error(l);f6("offlinePlaylistSyncCheck fetch request error",h);throw Error("offlinePlaylistSyncCheck fetch request error");case 3:m=G6(e);if(!e)throw f6("Network request failed for playlist sync"),Error("Network request failed for playlist sync"); if(m!==void 0)H6(m,"playlist sync");else if(!e.offlinePlaylistSyncCheckDatas||!e.offlinePlaylistSyncCheckDatas.length)throw f6("No data for playlist sync"),Error("No data for playlist sync");return n.return(e.offlinePlaylistSyncCheckDatas.map(function(p){return p.offlinePlaylistSyncCheckData}))}})},I6=function(a){this.j=a},knb=function(a,b){var c,d,e,f,h,l; return g.J(function(m){switch(m.j){case 1:c=new Map,d=g.w(b),e=d.next();case 2:if(e.done){m.Ha(4);break}f=e.value;h=c;l=h.set;return g.G(m,a.B(f),5);case 5:l.call(h,f,m.B);e=d.next();m.Ha(2);break;case 4:return m.return(c)}})},J6=function(a,b,c,d,e,f){b=g.mK(b,c); d=Object.assign({},f,{priority:d,retryScheduleIntervalsInSeconds:e});return{actionType:a,entityKey:b,actionMetadata:d}},K6=function(a,b,c,d,e,f){this.status=a; this.j=b;this.D=c;this.B=d;this.C=e;this.downloadState=f},lnb=function(a,b,c){this.j=a; this.W=b;this.C=c},onb=function(a,b){var c,d,e,f,h,l,m,n,p; return g.J(function(q){switch(q.j){case 1:return c=b.entityKey,e=(d=g.Q(b.actionMetadata,L6))==null?void 0:d.isEnqueuedForExpiredStreamUrlRefetch,g.wa(q,2),f=void 0,g.G(q,mnb(a,b),4);case 4:f=q.B;g.wa(q,5);var r=(r=g.Q(b.actionMetadata,L6))?{maximumDownloadQuality:r.maximumDownloadQuality}:void 0;return g.G(q,inb(c,a.W,{isEnqueuedForExpiredStreamUrlRefetch:e,K3:r,offlineSourceData:f}),7);case 7:h=q.B;g.xa(q,6,2);break;case 5:return g.ya(q,2),l=l6(b)?"OFFLINE_ORCHESTRATION_FAILURE_REASON_RECOVERABLE_NETWORK_ERROR": "OFFLINE_ORCHESTRATION_FAILURE_REASON_UNRECOVERABLE_NETWORK_ERROR",f6("PDE handleAdd error"),q.return(M6(b,!1,void 0,"OFFLINE_OPERATION_FAILURE_REASON_NETWORK_REQUEST_FAILED",l,"DOWNLOAD_STATE_FAILED"));case 6:return g.G(q,nnb(a,h,b),8);case 8:return q.return(M6(b,!0,h.orchestrationActions));case 2:return m=g.ya(q),n="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",p="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",m instanceof g.dt&&m.type==="QUOTA_EXCEEDED"&&(n="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED", p="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"),f6("PDE handleAdd error"),q.return(M6(b,!1,void 0,n,p,"DOWNLOAD_STATE_FAILED"))}})},pnb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D,F,H,M; return g.J(function(N){switch(N.j){case 1:return c=b.entityKey,g.G(N,Y5(a.j,{mode:"readonly",Pb:!0},function(S){var ba=R5(S,c,"playbackData"),ha=R5(S,g.mK(g.lK(b.entityKey).entityId,"offlineVideoPolicy"),"offlineVideoPolicy");S=R5(S,g.mK(g.lK(b.entityKey).entityId,"transfer"),"transfer");return g.kt.all([ba,ha,S])}),2); case 2:d=N.B;e=g.w(d);f=e.next().value;h=e.next().value;l=e.next().value;m=f;n=h;p=l;if(!m||!n)return N.return(M6(b,!0));q={lastPlayerResponseTimestampSeconds:m.playerResponseTimestamp,offlineToken:n.offlineToken};r={};if((t=p)==null?0:t.maximumDownloadQuality)r.maximumDownloadQuality=p.maximumDownloadQuality;g.wa(N,3);u=void 0;return g.G(N,mnb(a,b),5);case 5:return u=N.B,g.wa(N,6),g.G(N,inb(c,a.W,{refreshData:q,K3:r,offlineSourceData:u}),8);case 8:y=N.B;g.xa(N,7,3);break;case 6:return g.ya(N,3), A=l6(b)?"OFFLINE_ORCHESTRATION_FAILURE_REASON_RECOVERABLE_NETWORK_ERROR":"OFFLINE_ORCHESTRATION_FAILURE_REASON_UNRECOVERABLE_NETWORK_ERROR",f6("PDE handleRefresh error"),N.return(M6(b,!1,void 0,"OFFLINE_OPERATION_FAILURE_REASON_NETWORK_REQUEST_FAILED",A,"DOWNLOAD_STATE_FAILED"));case 7:return g.G(N,nnb(a,y,b),9);case 9:return N.return(M6(b,!0,y.orchestrationActions));case 3:return D=g.ya(N),F="PDE handleRefresh error",D instanceof Error&&(F="PDE handleRefresh error: "+D.message),H="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN", M="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",D instanceof g.dt&&D.type==="QUOTA_EXCEEDED"&&(H="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED",M="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"),f6(F),N.return(M6(b,!1,void 0,H,M,"DOWNLOAD_STATE_FAILED"))}})},mnb=function(a,b){var c,d,e,f; return g.J(function(h){if(h.j==1)return c=g.lK(b.entityKey).entityId,d=g.mK(c,"videoDownloadContextEntity"),g.G(h,$5(a.j,d,"videoDownloadContextEntity"),2);e=h.B;return(f=e)!=null&&f.offlineModeType?h.return({offlineModeType:e.offlineModeType}):h.return(void 0)})},nnb=function(a,b,c){var d,e,f,h,l; return g.J(function(m){if(m.j==1){if(!b.frameworkUpdates||!g.Q(b.frameworkUpdates,z6))return m.return();if(!(g.Q(b.frameworkUpdates,z6).mutations&&g.Q(b.frameworkUpdates,z6).mutations.length>0&&g.Q(b.frameworkUpdates,z6).mutations[0].type==="ENTITY_MUTATION_TYPE_DELETE"))return m.Ha(2);d=g.lK(g.Q(b.frameworkUpdates,z6).mutations[0].entityKey).entityId;return g.G(m,B6(a.j,d),3)}if(m.j!=2){e=m.B;f=g.Q(c.actionMetadata,L6);if(l=(h=f)==null?void 0:h.playlistId)e.playlistId=l;e.offlineDeleteReason="OFFLINE_DELETE_REASON_UNKNOWN"; return g.KO(a.W)?g.G(m,y6(d,a.j,c,a.C,e),2):g.yy(a.W)?g.G(m,C6(d,a.j,c,a.C),2):m.Ha(2)}return g.G(m,Olb(g.Q(b.frameworkUpdates,z6)),0)})},M6=function(a,b,c,d,e,f){return new K6(b?"OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS":"OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",l6(a),c,d,e,f)},qnb=function(a,b){this.j=a; this.W=b},rnb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r; return g.J(function(t){switch(t.j){case 1:return c=l6(b),g.G(t,a6(a.j,"videoPlaybackPositionEntity"),2);case 2:d=t.B;if(d.length===0)return t.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));g.wa(t,3);return g.G(t,N5.getInstance(),5);case 5:e=t.B;if(!e)throw Error("prefStorage is undefined");return g.G(t,e.get("psi"),6);case 6:return f=t.B,m=(l=(h=f)==null?void 0:h.hR)!=null?l:"0",g.G(t,gnb(d,m),7);case 7:return n=t.B,p={isPaused:n.watchHistoryPaused,hR:n.syncTimestampUsec},g.G(t,e.set("psi", p),8);case 8:if(p.isPaused){t.Ha(9);break}return g.G(t,Olb(g.Q(n.frameworkUpdates,z6)),9);case 9:g.xa(t,4);break;case 3:return q=g.ya(t),r="PPE handleRefresh error: "+(q instanceof Error?q.message:"unknown error"),f6(r),t.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED"));case 4:return t.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c))}})}, tnb=function(a,b){var c,d,e,f,h,l,m,n,p,q; return g.J(function(r){switch(r.j){case 1:return c=l6(b),d=g.lK(b.entityKey).entityId,g.G(r,$5(a.j,b.entityKey,"videoPlaybackPositionEntity"),2);case 2:e=r.B;if(!e||d!==e.videoId)return r.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));g.wa(r,3);return g.G(r,N5.getInstance(),5);case 5:f=r.B;if(!f)throw Error("prefStorage is undefined");return g.G(r,f.get("psi"),6);case 6:h=r.B;l=g.Q(b.actionMetadata,snb);if(((m=h)==null?void 0:m.isPaused)!==!1||(n=l)==null||!n.lastPlaybackPositionSeconds|| ((p=l)==null?void 0:p.lastPlaybackPositionSeconds)===((q=e)==null?void 0:q.lastPlaybackPositionSeconds)){r.Ha(7);break}e.lastPlaybackPositionSeconds=l.lastPlaybackPositionSeconds;return g.G(r,Z5(a.j,e,"videoPlaybackPositionEntity"),7);case 7:g.xa(r,4);break;case 3:return g.ya(r),r.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED"));case 4:return r.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS", c))}})},unb=function(a,b){var c,d,e; return g.J(function(f){switch(f.j){case 1:c=l6(b);g.wa(f,2);d=g.lK(b.entityKey).entityId;if(d==="!*$_ALL_ENTITIES_!*$")return g.G(f,Jlb(a.j),5);e=g.mK(d,"videoPlaybackPositionEntity");return g.G(f,Ilb(a.j,e),5);case 5:g.xa(f,3);break;case 2:return g.ya(f),f.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED"));case 3:return f.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS", c))}})},vnb=function(a,b){this.j=a; this.W=b},xnb=function(a,b){var c,d; return g.J(function(e){switch(e.j){case 1:return c=l6(b),g.G(e,$5(a.j,b.entityKey,"transfer"),2);case 2:if(d=e.B)return e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));g.wa(e,3);return g.G(e,wnb(a,b),5);case 5:g.xa(e,4);break;case 3:return g.ya(e),e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED"));case 4:return e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS", c))}})},ynb=function(a,b){var c,d; return g.J(function(e){switch(e.j){case 1:return c=l6(b),g.G(e,$5(a.j,b.entityKey,"transfer"),2);case 2:d=e.B;if(!d||d.transferState!=="TRANSFER_STATE_COMPLETE")return e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));g.wa(e,3);return g.G(e,wnb(a,b,!0),5);case 5:g.xa(e,4);break;case 3:return g.ya(e),e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED")); case 4:return e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c))}})},znb=function(a,b){var c,d,e,f,h,l,m,n,p,q; return g.J(function(r){switch(r.j){case 1:return c=l6(b),d=g.lK(b.entityKey).entityId,g.G(r,Y5(a.j,{mode:"readonly",Pb:!0},function(t){var u=R5(t,b.entityKey,"transfer");t=R5(t,g.mK(d,"videoDownloadContextEntity"),"videoDownloadContextEntity");return g.kt.all([u,t])}),2); case 2:e=r.B;f=g.w(e);h=f.next().value;l=f.next().value;m=h;n=l;if(!m||m.transferState!=="TRANSFER_STATE_WAITING_FOR_PLAYER_RESPONSE_REFRESH")return r.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));g.wa(r,3);m.transferState="TRANSFER_STATE_TRANSFER_IN_QUEUE";return g.G(r,Z5(a.j,m,"transfer"),5);case 5:p=g.lK(m.key).entityId;k6({transferStatusType:"TRANSFER_STATUS_TYPE_REENQUEUED_BY_PLAYER_RESPONSE_REFRESH"},{videoId:p,Tl:m,offlineModeType:(q=n)==null?void 0:q.offlineModeType});g.xa(r, 4);break;case 3:return g.ya(r),r.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED"));case 4:return r.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c))}})},wnb=function(a,b,c){c=c===void 0?!1:c; var d,e,f,h,l,m,n,p,q,r,t,u,y,A,D;return g.J(function(F){if(F.j==1)return d=g.Q(b.actionMetadata,Anb),e=g.lK(b.entityKey).entityId,f=g.mK(e,"downloadStatusEntity"),g.G(F,Y5(a.j,{mode:"readonly",Pb:!0},function(H){var M=R5(H,f,"downloadStatusEntity");H=R5(H,g.mK(e,"videoDownloadContextEntity"),"videoDownloadContextEntity");return g.kt.all([M,H])}),2); if(F.j!=3)return h=F.B,l=g.w(h),m=l.next().value,n=l.next().value,p=m,q=n,r="TRANSFER_STATE_TRANSFER_IN_QUEUE",((t=p)==null?void 0:t.downloadState)==="DOWNLOAD_STATE_USER_DELETED"&&(r="TRANSFER_STATE_PAUSED_BY_USER"),A={key:b.entityKey,transferState:r,cotn:g.kv(16),enqueuedTimestampMs:Date.now().toString(),maximumDownloadQuality:(u=d)==null?void 0:u.maximumDownloadQuality,preferredAudioTrack:(y=d)==null?void 0:y.preferredAudioTrack,transferRetryCount:0,isRefresh:c,hasLoggedFirstStarted:!1},g.G(F, Y5(a.j,{mode:"readwrite",Pb:!0},function(H){var M=[];c&&M.push(V5(H,g.mK(e,"offlineVideoStreams")));M.push(U5(H,A,"transfer"));return g.kt.all(M)}),3); k6({transferStatusType:"TRANSFER_STATUS_TYPE_ENQUEUED",statusType:"ADDED_TO_QUEUE"},{videoId:e,Tl:A,offlineModeType:(D=q)==null?void 0:D.offlineModeType});g.va(F)})},Cnb=function(a,b,c,d){if(!a.action.entityKey)throw Error("entityKey is missing."); var e=g.lK(a.action.entityKey);e={entityType:e.r8,entityId:e.entityId,offlineOrchestrationActionType:a.action.actionType,orchestrationAction:{orchestrationActionId:a.actionId}};b&&(e.offlineOrchestrationActionResult=b.status,e.isRetryable=c?!1:b.j,b.C&&(e.offlineOrchestrationFailureReason=Bnb(b.C,e.isRetryable)));var f,h;if((f=a.action.actionMetadata)==null?0:(h=f.offlineLoggingData)==null?0:h.offlineModeType)e.offlineModeType=a.action.actionMetadata.offlineLoggingData.offlineModeType;d&&(e.additionalOrchestrationActions= d.map(function(l){return{orchestrationActionId:l.actionId}})); return e},Bnb=function(a,b){return a!=="OFFLINE_ORCHESTRATION_FAILURE_REASON_RECOVERABLE_NETWORK_ERROR"||b?a==="OFFLINE_ORCHESTRATION_FAILURE_REASON_UNRECOVERABLE_NETWORK_ERROR"&&b?"OFFLINE_ORCHESTRATION_FAILURE_REASON_RECOVERABLE_NETWORK_ERROR":a:"OFFLINE_ORCHESTRATION_FAILURE_REASON_UNRECOVERABLE_NETWORK_ERROR"},Dnb=function(a,b){var c={offlineOrchestrationContext:Cnb(a)}; b=bmb(b,c);cmb(amb(),b,a.rootActionId)},Enb=function(a,b,c,d){d=d===void 0?[]:d; b={offlineOrchestrationContext:Cnb(a,b,c,d)};b=bmb(3,b);cmb(amb(),b,a.rootActionId)},Fnb=function(){this.actions=[]},Gnb=function(a,b){b=g.w(b); for(var c=b.next();!c.done;c=b.next())c=c.value,Dnb(c,1),a.actions.push(c);a.actions.sort(a.j)},Hnb=function(a,b){if(b)for(var c=0;c0,n>0&&q?(d=Math.min(d,m),e=Math.min(n,e)):c.push(l);isFinite(d)&&(!a.C.isActive()||d0&&Rnb(a,c);return g.G(u,Knb(a),0)})},Unb=function(a){var b,c,d,e,f,h,l; return g.J(function(m){if(m.j==1)return g.G(m,Tnb(a),2);b=m.B;c=[];d=g.w(b);for(e=d.next();!e.done;e=d.next())f=e.value,h=g.lK(f.key),l=h.entityId,Inb(a.j,l)||c.push(f);return g.G(m,Snb(a,c),0)})},Pnb=function(a){a=a*1E3-Date.now(); return a>4E3?4E3:a},Onb=function(a,b){var c,d,e; return g.J(function(f){c=g.w(b);for(d=c.next();!d.done;d=c.next()){e=d.value;var h=void 0,l=void 0,m=((l=e.action)==null?void 0:(h=l.actionMetadata)==null?void 0:h.retryScheduleIntervalsInSeconds)||[1,2,4];h=1;e.retryScheduleIndex0)})},$nb=function(a,b){this.api=a; this.j=b;this.logger=new g.uN("woffle");this.B=!1;this.hd={QP:this.QP};this.logger.debug("Initialized OfflineMediaManager")},aob=function(a){return g.J(function(b){return b.return(Vlb(a))})},bob=function(a){var b; return g.J(function(c){if(c.j==1)return g.G(c,g.uKa(a),2);b=c.B;return c.return(b.filter(function(d){return!!d.url}).map(function(d){return d.url}))})},O6=function(a,b){var c=g.qP(b); if(c===1||c===0)return Promise.resolve();(c=cob(a,b))&&c.stopVideo();a.C=0;return aob(b)},P6=function(a,b,c,d){c=c===void 0?!1:c; d=d===void 0?!0:d;var e=typeof b==="string"?b:b.videoDetails.videoId;g.qP(e)===2&&((b=cob(a,e))?b.stopVideo():a.logger.info(function(){return"Corresponding player for "+e+" not found. Pausing anyway"}),g.rP(e,2),a.C=2,c?dob(a.j):d&&eob(a.j))},cob=function(a,b){var c; return((c=a.player)==null?void 0:c.getVideoData().videoId)===b?a.player:null},fob=function(a,b,c){b.getPlayerResponse(); g.rP(b.videoId,2);a.C=2;a.B=!1;var d;(d=a.player)==null||d.dispose();a.player=a.api.Xz(9,b);b={};g.Yw(a.player,(b.localmediachange=a.AL,b.signatureexpired=a.cS,b.statechange=a.Maa,b),a);var e=a.QP(c);g.q4a(a.player,g.$K(e,e,!0,"m"),!1);a.logger.debug(function(){return"Starting headless playback with quality: "+e}); g.AW(a.player,!1)},Q6=function(a){g.O.call(this); this.j=a;this.B=Glb(this.j,this.C.bind(this))},gob=function(a,b){var c,d,e,f,h,l,m; return g.J(function(n){switch(n.j){case 1:if(b.length===0)return n.return([]);c=b.map(function(p){return g.mK(p,"transfer")}); return g.G(n,a6(a.j,"transfer",c),2);case 2:d=n.B;e=d.filter(Plb).map(function(p){return g.lK(p.key).entityId}); f=b.filter(function(p){return e.indexOf(p)===-1}); if(f.length===0)return n.return([]);h=g.w(f);l=h.next();case 3:if(l.done){n.Ha(5);break}m=l.value;return g.G(n,aob(m),4);case 4:l=h.next();n.Ha(3);break;case 5:return n.return(f)}})},job=function(a,b,c,d,e,f){var h,l,m; return g.J(function(n){h="STREAM_TYPE_UNKNOWN";c.video&&c.audio?(h="STREAM_TYPE_AUDIO_AND_VIDEO",f6("unexpected stream type")):c.video&&!c.audio?h="STREAM_TYPE_VIDEO":!c.video&&c.audio&&(h="STREAM_TYPE_AUDIO");l=g.mK(b,"offlineVideoStreams");m={numBytesDownloaded:e.toFixed(),numTotalBytes:f.toFixed(),streamType:h,streamState:"DOWNLOAD_STREAM_STATE_IN_PROGRESS",formatStreamBytes:JSON.stringify(d),itag:h==="STREAM_TYPE_AUDIO_AND_VIDEO"?Number(c.itag):void 0};return g.G(n,Y5(a,{mode:"readwrite",Pb:!0}, function(p){var q=R5(p,l,"offlineVideoStreams"),r=R5(p,g.mK(b,"transfer"),"transfer");return g.kt.all([q,r]).then(function(t){t=g.w(t);var u=t.next().value;t=t.next().value;if(!t)return V5(p,l).then(function(){}); var y=hob(u);u=iob(u,d,m,l);var A=U5(p,u,"offlineVideoStreams");hob(u)>y&&(t.lastProgressTimeMs=Date.now().toString());y=[A];t.offlineVideoStreams||(t.offlineVideoStreams=[]);t.offlineVideoStreams.indexOf(l)===-1&&(t.offlineVideoStreams.push(l),y.push(U5(p,t,"transfer")));return g.kt.all(y)})}),0)})},kob=function(a,b){var c,d,e,f,h; return g.J(function(l){if(l.j==1)return c=g.mK(b,"offlineVideoStreams"),g.G(l,$5(a,c,"offlineVideoStreams"),2);d=l.B;if(!d||!d.streamsProgress)return l.return();e=g.w(d.streamsProgress);for(f=e.next();!f.done;f=e.next())h=f.value,h.streamState="DOWNLOAD_STREAM_STATE_COMPLETE",h.numTotalBytes!==h.numBytesDownloaded&&(h.numBytesDownloaded=h.numTotalBytes);return g.G(l,Z5(a,d,"offlineVideoStreams"),0)})},iob=function(a,b,c,d){if(a&&a.streamsProgress){d=a; a:{b=b.itag+";"+b.xtags;for(var e=a.streamsProgress,f=0;f1E3)){f.Ha(4);break}a.Ga=d;return g.G(f,job(a.B,c.videoId,c.B,c.CP,c.bytesDownloaded,c.j),5);case 5:if(a.Y&&!(a.Y&&d-a.qa>a.Wa)){f.Ha(4);break}a.qa=d;return g.G(f,T6(a,b),7);case 7:e=f.B,rmb({videoId:b,Tl:a.j,offlineModeType:e},c.bytesDownloaded,c.j);case 4:a.D.start(108E5),g.va(f)}})}, yob=function(a){var b=(a.j.transferRetryCount||0)<3; b&&(a=a.j,a.transferRetryCount=(a.transferRetryCount||0)+1);return b},zob=function(a,b){b=b===void 0?"TRANSFER_FAILURE_REASON_UNKNOWN":b; var c,d,e,f;return g.J(function(h){if(h.j==1)return a.j||U6(a,"setTransferToFailed: "+b),c="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",b==="TRANSFER_FAILURE_REASON_NETWORK"?c="OFFLINE_OPERATION_FAILURE_REASON_NETWORK_REQUEST_FAILED":b==="TRANSFER_FAILURE_REASON_FILESYSTEM_WRITE"&&(c="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED"),g.G(h,V6(a,"TRANSFER_STATE_FAILED","DOWNLOAD_STREAM_STATE_ERROR_STREAMS_MISSING",b),2);if(h.j!=3)return h6(a.ra,{entityKey:(d=a.j)==null?void 0:d.key,failureReason:c}), e=a.j?g.lK(a.j.key).entityId:"",g.G(h,T6(a,e),3);f=h.B;var l={videoId:e,Tl:a.j,offlineModeType:f},m=b,n={transferStatusType:"TRANSFER_STATUS_TYPE_TERMINATED_WITH_FAILURE",statusType:"FAILED"};m&&(n.transferFailureReason=m,n.failureReason=tmb(m));k6(n,l);g.va(h)})},V6=function(a,b,c,d){var e; return g.J(function(f){if(f.j==1){if(!a.j)return U6(a,"saveTransferState: "+b),f.return();a.j.transferState=b;a.j.failureReason=d;g.wa(f,2);return g.G(f,rob(a,function(h){return c?S5(h,"offlineVideoStreams",a.j.offlineVideoStreams).then(function(l){for(var m=g.w(l),n=m.next();!n.done;n=m.next())if((n=n.value)&&n.streamsProgress){n=g.w(n.streamsProgress);for(var p=n.next();!p.done;p=n.next())p.value.streamState=c}return xlb(h,l.filter(function(q){return!!q}),"offlineVideoStreams")}):g.kt.resolve(void 0)}), 4)}if(f.j!=2)return g.xa(f,0); e=g.ya(f);return e instanceof g.dt&&e.type==="QUOTA_EXCEEDED"?g.G(f,a.sy("TRANSFER_FAILURE_REASON_FILESYSTEM_WRITE"),0):f.Ha(0)})},rob=function(a,b){var c; return g.J(function(d){if(!a.j)return d.return();c=a.j;return g.G(d,Y5(a.B,{mode:"readwrite",Pb:!0},function(e){var f=[U5(e,c,"transfer")];b&&f.push(b(e));return g.kt.all(f)}),0)})},R6=function(a){a.j=void 0; a.G=void 0;a.D.stop()},tob=function(a,b){var c,d,e,f,h; return g.J(function(l){if(l.j==1)return c=g.lK(b.key),d=c.entityId,e=g.mK(d,"playbackData"),g.G(l,$5(a.B,e,"playbackData"),2);f=l.B;if((h=f)==null?0:h.playerResponseJson)return l.return(JSON.parse(f.playerResponseJson));throw Error("No PlayerResponse found");})},U6=function(a,b){a.api.oa("woffle",{mcte:b}); f6("missing current transfer entity.")},T6=function(a,b){var c,d,e; return g.J(function(f){if(f.j==1)return g.G(f,$5(a.B,g.mK(b,"videoDownloadContextEntity"),"videoDownloadContextEntity"),2);c=f.B;return f.return((e=(d=c)==null?void 0:d.offlineModeType)!=null?e:void 0)})},uob=function(a){return Aob[a.transferState]!==void 0},vob=function(a,b){var c=Aob[a.transferState],d=Aob[b.transferState]; return c!==d?c-d:Number(a.enqueuedTimestampMs)-Number(b.enqueuedTimestampMs)},W6=function(a,b){var c=this; this.W=a;this.api=b;this.N=new g.Ou;this.G=new g.cj;this.hd={xY:function(){return c.C.hd.xY()}, AY:function(){return c.N}, Vna:function(){return c.C}, TQ:function(){return c.TQ()}, XT:function(){return c.XT()}, cU:function(){return c.cU()}, oT:function(){return c.oT()}, lT:function(){return c.lT()}, LM:function(d){return c.LM(d)}}; this.C=new mmb(function(){return Bob(c)},function(){c.cU()},this.api.cj(),this.api.L.bind(this.api)); this.j=new g6(this.api);nmb(this.C)},Bob=function(a){return g.J(function(b){a.api.ib("onOrchestrationBecameLeader"); return g.G(b,a.XT(),0)})},Dob=function(a){var b,c; return g.J(function(d){if(d.j==1)return g.G(d,b6(),2);if(d.j!=3){b=d.B;if(!b)return f6("PES is undefined"),d.return();a.B=new lob(b,a.api,a.C,a.j);c=a.iF(b);return g.G(d,Lnb(b,c,a.C,a.j,a.W),3)}a.K=d.B;return g.G(d,Cob(a),0)})},Cob=function(a){var b; return g.J(function(c){switch(c.j){case 1:if(!a.B)return f6("transferManager is undefined"),c.return();if(a.B.j){c.Ha(2);break}return g.G(c,S6(a.B),2);case 2:if(!a.W.L("woffle_enable_main_downloads_library")){c.Ha(4);break}return g.G(c,a.I_(),4);case 4:if(!a.W.L("html5_offline_playback_position_sync")){c.Ha(6);break}return g.G(c,a.bX(),7);case 7:return g.G(c,a.LM(864E5),6);case 6:return g.G(c,a.refreshAllStaleEntities(43200,!0),9);case 9:return g.G(c,a.QO(),10);case 10:if(!a.W.L("html5_retry_downloads_for_expiration")){c.Ha(11); break}return g.G(c,a.lT(),11);case 11:return a.Z=g.dr(function(){a.refreshAllStaleEntities(43200,!0);a.QO()},9E5),a.W.L("html5_offline_playback_position_sync")&&a.setUpPositionSyncInterval(),g.Ms(g.Os(),function(){return a.oT()}),g.G(c,b6(),13); case 13:return b=c.B,g.G(c,lmb(b),14);case 14:omb(a.C),g.va(c)}})},Eob=function(){var a,b,c,d,e,f; return g.J(function(h){switch(h.j){case 1:return g.G(h,b6(),2);case 2:a=h.B;if(!a)return h.return([]);b=Date.now()/1E3;return g.G(h,a6(a,"offlineVideoPolicy"),3);case 3:c=h.B,d=g.w(c),e=d.next();case 4:if(e.done){h.Ha(6);break}f=e.value;if(!(f.expirationTimestamp&&Number(f.expirationTimestamp)0&&b.push({key:Number("PLAYLIST_THUMBNAIL_STYLE_FIRST_VIDEO"),value:{collageThumbnail:{coverThumbnail:c[0].offlineVideoData.thumbnail}}});if((a=a.additionalMetadadatas)&&a.length>0)for(a=g.w(a),c=a.next();!c.done;c=a.next()){var d=c.value.offlineBundleItemPlaylistData,e=void 0;c=(e=d)==null?void 0:e.style;e=void 0;d={collageThumbnail:{coverThumbnail:(e=d)==null?void 0:e.coverThumbnail}};switch(c){case "BUNDLE_ITEM_STYLE_UNSPECIFIED":b.push({key:Number("PLAYLIST_THUMBNAIL_STYLE_UNKNOWN"), value:d});break;case "BUNDLE_ITEM_STYLE_TWO_BY_TWO":b.push({key:Number("PLAYLIST_THUMBNAIL_STYLE_TWO_BY_TWO"),value:d});break;case "BUNDLE_ITEM_STYLE_ONE_AND_TWO_AVATAR":b.push({key:Number("PLAYLIST_THUMBNAIL_STYLE_ONE_AND_TWO_AVATAR"),value:d});break;case "BUNDLE_ITEM_STYLE_ONE_AND_TWO":b.push({key:Number("PLAYLIST_THUMBNAIL_STYLE_ONE_AND_TWO"),value:d})}}return b},Qob=function(a){switch(a.privacy){case "PRIVATE":return"PLAYLIST_VISIBILITY_PRIVATE"; case "PUBLIC":return"PLAYLIST_VISIBILITY_PUBLIC";case "UNLISTED":return"PLAYLIST_VISIBILITY_UNLISTED";default:return"PLAYLIST_VISIBILITY_UNKNOWN"}},Job=function(a,b,c){b={offlineVideoData:b, playlistId:c};if(a=g.Q(a.actionMetadata,Lob))b.maximumDownloadQuality=a.maximumDownloadQuality;return{mainVideoEntityActionMetadata:b}},Sob=function(a,b,c){this.j=a; this.W=b;this.C=c},Vob=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u; return g.J(function(y){switch(y.j){case 1:return c=l6(b),d=g.lK(b.entityKey),e=d.entityId,f=g.Q(b.actionMetadata,Z6),l=!((h=f)==null?0:h.playlistId),g.wa(y,2),g.G(y,Tob(a,e,void 0,(m=f)==null?void 0:m.offlineVideoData,l),4);case 4:g.xa(y,3);break;case 2:return n=g.ya(y),p="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",q="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",n instanceof g.dt&&n.type==="QUOTA_EXCEEDED"&&(p="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED",q="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"), y.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,p,q));case 3:r=1;r=Number(((t=b.actionMetadata)==null?void 0:t.priority)||0)+1;var A=(A=g.Q(b.actionMetadata,Z6))?{playbackDataActionMetadata:{maximumDownloadQuality:A.maximumDownloadQuality}}:void 0;u=J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_ADD",e,"playbackData",r,Uob,A);return y.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,[u]))}})},Wob=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D,F; return g.J(function(H){switch(H.j){case 1:return c=l6(b),d=g.lK(b.entityKey),e=d.entityId,g.G(H,$5(a.j,b.entityKey,"mainVideoEntity"),2);case 2:f=H.B;if(!f){h=void 0;H.Ha(3);break}return g.G(H,$5(a.j,f.downloadState,"mainVideoDownloadStateEntity"),4);case 4:h=H.B;case 3:l=h;if(!f||!l)return H.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));g.wa(H,5);return g.G(H,Tob(a,e,l.addedTimestampMillis,(n=g.Q(b.actionMetadata,Z6))==null?void 0:n.offlineVideoData),7);case 7:p=1;p=Number(((q= b.actionMetadata)==null?void 0:q.priority)||0)+1;m=J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH",e,"playbackData",p,Uob);g.xa(H,6);break;case 5:r=g.ya(H);if(!(r instanceof Error&&r.message==="No data")){if(r instanceof Error&&r.message==="Empty response body")f6(r.message);else return t="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",u="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",r instanceof g.dt&&r.type==="QUOTA_EXCEEDED"&&(t="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED", u="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"),H.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,t,u));H.Ha(6);break}return g.G(H,B6(a.j,e),9);case 9:y=H.B;A=g.Q(b.actionMetadata,Z6);if(F=(D=A)==null?void 0:D.playlistId)y.playlistId=F;y.offlineDeleteReason="OFFLINE_DELETE_REASON_UNAVAILABLE";return g.G(H,y6(e,a.j,b,a.C,y),6);case 6:return H.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,m?[m]:void 0))}})},Xob=function(a,b){var c,d,e,f,h,l,m,n,p,q; return g.J(function(r){switch(r.j){case 1:return c=l6(b),g.wa(r,2),d=g.lK(b.entityKey).entityId,d==="!*$_ALL_ENTITIES_!*$"?g.G(r,Fmb(a.j,b,a.C,(p=b.actionMetadata)==null?void 0:(q=p.offlineLoggingData)==null?void 0:q.offlineDeleteReason),5):g.G(r,B6(a.j,d),6);case 6:e=r.B;f=g.Q(b.actionMetadata,Z6);if(l=(h=f)==null?void 0:h.playlistId)e.playlistId=l;e.offlineDeleteReason=(m=b.actionMetadata)==null?void 0:(n=m.offlineLoggingData)==null?void 0:n.offlineDeleteReason;return g.G(r,y6(d,a.j,b,a.C,e),7); case 7:if(!a.W.L("woffle_enable_main_downloads_library")){r.Ha(5);break}return g.G(r,Nmb(a.j,b.entityKey),5);case 5:g.xa(r,3);break;case 2:return g.ya(r),r.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED"));case 3:return r.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c))}})},Tob=function(a,b,c,d,e){var f,h,l,m,n,p; return g.J(function(q){switch(q.j){case 1:if(f=d){q.Ha(2);break}return g.G(q,Xmb([b]),3);case 3:h=q.B,f=h[0];case 2:return g.G(q,Yob(a,f,c,e),4);case 4:l=q.B;m=l.mainVideoEntity;n=l.channelEntity;g.wa(q,5);var r=s6(m.thumbnail),t=s6(n.avatar);return g.G(q,x6(r.concat(t)),7);case 7:g.xa(q,0);break;case 5:p=g.ya(q),p instanceof Error&&p.message==="Failed to fetch"&&f6(p.message),g.va(q)}})},Yob=function(a,b,c,d){var e,f,h,l,m,n,p,q,r,t,u,y,A; return g.J(function(D){switch(D.j){case 1:c||(c=Date.now().toString());f=(e=b.channel)==null?void 0:e.offlineChannelData;h={id:g.mK(b.videoId,"ytMainChannelEntity"),channelId:f.channelId,title:f.title,avatar:f.thumbnail};l={key:g.mK(b.videoId,"mainVideoDownloadStateEntity"),playbackData:g.mK(b.videoId,"playbackData"),addedTimestampMillis:c,videoDownloadContextEntity:g.mK(b.videoId,"videoDownloadContextEntity")};m={key:g.mK(b.videoId,"videoPlaybackPositionEntity"),videoId:b.videoId,lastPlaybackPositionSeconds:"0"}; a.W.L("html5_offline_playback_position_sync")&&(n={playbackPosition:m.key});p=g.mK(b.videoId,"mainVideoEntity");q={key:p,videoId:b.videoId,title:b.title,thumbnail:b.thumbnail,localizedStrings:{viewCount:b.shortViewCountText},userState:n,lengthSeconds:b.lengthSeconds?Number(b.lengthSeconds):void 0,publishedTimestampMillis:b.publishedTimestamp?(Number(b.publishedTimestamp)*1E3).toString():void 0,formattedDescription:b.description,owner:h.id,downloadState:l.key};if(!a.W.L("woffle_enable_main_downloads_library")|| !d){D.Ha(2);break}return g.G(D,Lmb(a.j,[p]),3);case 3:if(u=D.B)r=u.mainDownloadsLibraryEntity,t=u.mainDownloadsListEntity;case 2:return A=vmb,y={key:g.mK(b.videoId,"downloadStatusEntity"),downloadState:"DOWNLOAD_STATE_PENDING_DOWNLOAD"},g.Dw(l,A,y),g.G(D,Y5(a.j,{mode:"readwrite",Pb:!0},function(F){var H=U5(F,h,"ytMainChannelEntity"),M=U5(F,l,"mainVideoDownloadStateEntity"),N=U5(F,q,"mainVideoEntity");H=[H,M,N];a.W.L("html5_offline_playback_position_sync")&&(M=U5(F,m,"videoPlaybackPositionEntity"), H.push(M));r&&(M=U5(F,r,"mainDownloadsLibraryEntity"),H.push(M));t&&(M=U5(F,t,"mainDownloadsListEntity"),H.push(M));y&&(F=U5(F,y,"downloadStatusEntity"),H.push(F));return g.kt.all(H)}),4); case 4:return D.return({mainVideoEntity:q,channelEntity:h})}})},Zob=function(a,b,c){this.j=a; this.W=b;this.C=c},apb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D,F,H,M,N,S,ba,ha,na,Y,R,W; return g.J(function(v){switch(v.j){case 1:return c=l6(b),d=[],g.G(v,N5.getInstance(),2);case 2:e=v.B;if(!e){v.Ha(3);break}return g.G(v,e.get("sdois"),4);case 4:return f=v.B,g.G(v,(l=e)==null?void 0:l.get("lmqf"),5);case 5:h=v.B;case 3:g.wa(v,6);if(f===void 0)throw Error("prefStorage or opt-in state is undefined");m=[];if(f){v.Ha(8);break}return g.G(v,Kmb(a.j),9);case 9:m=v.B,m.reverse();case 8:if(!m.length){v.Ha(10);break}n=g.w(m);p=n.next();case 11:if(p.done){v.Ha(10);break}q=p.value;if(!q){v.Ha(12); break}r=g.lK(q).entityId;return g.G(v,B6(a.j,r),14);case 14:return t=v.B,t.offlineDeleteReason="OFFLINE_DELETE_REASON_PARENT_LIST_DELETE",g.G(v,y6(r,a.j,{entityKey:q,actionType:b.actionType},a.C,t),12);case 12:p=n.next();v.Ha(11);break;case 10:return g.G(v,bnb(f,(u=h)!=null?u:"SD"),16);case 16:return y=v.B,g.G(v,Gmb(y),17);case 17:A=Jmb(y);if(!a.W.L("woffle_enable_main_downloads_library")){v.Ha(18);break}if(f){v.Ha(19);break}return g.G(v,Nmb(a.j,A6),19);case 19:return g.G(v,Mmb(a.j,[A6]),18);case 18:if((D= A)==null?0:D.length)for(F=g.w(A),H=F.next();!H.done;H=F.next())if(N=M=H.value,S=N.actionType,ba=N.entityKey,ha=N.actionMetadata,S&&ba&&ha&&!g.Q(ha,$ob)){S==="OFFLINE_ORCHESTRATION_ACTION_TYPE_DELETE"&&(ha.offlineLoggingData={offlineDeleteReason:"OFFLINE_DELETE_REASON_PARENT_LIST_DELETE"});if(na=g.Q(M.actionMetadata,Z6))na.playlistId="DOWNLOADS_LIST_ENTITY_ID_SMART_DOWNLOADS",M.actionMetadata=Object.assign({},M.actionMetadata,{mainVideoEntityActionMetadata:na});d.push(M)}g.xa(v,7);break;case 6:return Y= g.ya(v),R="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",W="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",Y instanceof g.dt&&Y.type==="QUOTA_EXCEEDED"&&(R="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED",W="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"),v.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,R,W));case 7:return v.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,d))}})},bpb=function(){W6.apply(this,arguments); this.Y="mainVideoEntity"},cpb=function(a,b,c){b=b===void 0?43200:b; c=c===void 0?!0:c;var d=d===void 0?!1:d;var e,f,h;return g.J(function(l){switch(l.j){case 1:if(!a.N.Kh())return l.return([]);e=[];g.wa(l,2);return g.G(l,$mb(b,c,d),4);case 4:e=l.B;g.xa(l,3);break;case 2:f=g.ya(l),f instanceof Error&&f.message==="No data"||f instanceof Error&&f.message==="Empty response body"&&f6(f.message);case 3:return h=Fob(a,e,c),l.return(h)}})},dpb=function(a,b,c,d){d=d===void 0?!1:d; var e,f,h,l,m,n,p,q,r,t,u,y,A,D,F;return g.J(function(H){switch(H.j){case 1:return e=[],g.G(H,anb(),2);case 2:return(f=H.B)||d?g.G(H,cnb(b,c),3):H.return([]);case 3:h=H.B;if((l=h)==null||!l.length)return H.return([]);m={offlineDeleteReason:"OFFLINE_DELETE_REASON_PARENT_LIST_REFRESH"};n=g.w(h);p=n.next();case 4:if(p.done){H.Ha(6);break}r=q=p.value;t=r.actionType;u=r.entityKey;y=r.actionMetadata;if(!(t&&u&&y)||g.Q(y,$ob)){H.Ha(5);break}t==="OFFLINE_ORCHESTRATION_ACTION_TYPE_DELETE"&&(y.offlineLoggingData= m);A=g.lK(u);D=A.entityId;return g.G(H,X6(a,[D],"mainVideoEntity",t,y),8);case 8:F=H.B,e=e.concat(F);case 5:p=n.next();H.Ha(4);break;case 6:return H.return(e)}})},epb=function(a,b){this.j=a; this.C=b},gpb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D; return g.J(function(F){switch(F.j){case 1:return c=l6(b),d=g.lK(b.entityKey),e=d.entityId,f=[],g.wa(F,2),g.G(F,fpb(a,e),4);case 4:f=F.B;if((h=f)==null||!h.length){F.Ha(5);break}return g.G(F,Smb(a.j,b.entityKey),5);case 5:g.xa(F,3);break;case 2:return l=g.ya(F),m="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",n="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",l instanceof g.dt&&l.type==="QUOTA_EXCEEDED"&&(m="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED",n="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"), F.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,m,n));case 3:return p=[],g.G(F,wmb(a.j,"musicTrack",f),7);case 7:f=F.B;if(f.length)for(q=g.w(f),r=q.next();!r.done;r=q.next())if(t=r.value,u=t.offlineVideoData,y=void 0,(y=u)==null?0:y.videoId)A=void 0,D=Number(((A=b.actionMetadata)==null?void 0:A.priority)||0)+1,p.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_ADD",u.videoId,"musicTrack",D,$6,F6(b,u,e)));return F.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,p))}})}, hpb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D,F,H,M,N,S,ba,ha,na,Y,R,W,v,V,cb,Ab,Va,fb,bb,pb,$a,B,C,E,I,L,X,fa,ca,K,la,qa,ka,Ha,lb,Pb,qc,Pa,Nc,ke,Jd,Kg,ig,Qh; return g.J(function(Oc){switch(Oc.j){case 1:return c=l6(b),d=b.entityKey,e=g.lK(d).entityId,f=[],h=!1,e==="!*$_ALL_ENTITIES_!*$"?(h=!0,g.G(Oc,a6(a.j,"musicAlbumRelease"),5)):g.G(Oc,$5(a.j,d,"musicAlbumRelease"),4);case 4:(l=Oc.B)&&f.push(l);Oc.Ha(3);break;case 5:f=Oc.B;case 3:if((m=f)==null||!m.length)return Oc.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));if(h){n=[];p=g.w(f);for(q=p.next();!q.done;q=p.next())r=q.value,t=g.lK(r.id).entityId,n.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH", t,"musicAlbumRelease",0,$6));return Oc.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,n))}u=[];y=f[0];A=void 0;if(!y.downloadMetadata){Oc.Ha(6);break}return g.G(Oc,$5(a.j,y.downloadMetadata,"musicAlbumReleaseDownloadMetadataEntity"),7);case 7:D=Oc.B,A=Number((H=(F=D)==null?void 0:F.addedTimestampMillis)!=null?H:"0")/1E3;case 6:return g.wa(Oc,8),g.G(Oc,fpb(a,e,(M=A)==null?void 0:M.toString()),10);case 10:u=Oc.B;g.xa(Oc,9);break;case 8:N=g.ya(Oc);if(!(N instanceof Error&&N.message=== "No data")){if(N instanceof Error&&N.message==="Empty response body")f6(N.message);else return S="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",ba="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",N instanceof g.dt&&N.type==="QUOTA_EXCEEDED"&&(S="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED",ba="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"),Oc.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,S,ba));Oc.Ha(9);break}return g.G(Oc,D6(e,"musicAlbumRelease", a.j,b,a.C),9);case 9:ha=[];na=new Map;if((Y=u)==null?0:Y.length)for(R=g.w(u),W=R.next();!W.done;W=R.next())v=W.value,V=v.offlineVideoData,cb=void 0,((cb=V)==null?0:cb.videoId)&&na.set(V.videoId,V);Ab=new Map;Va=[];if((fb=y)==null?0:(bb=fb.tracks)==null?0:bb.length)for(pb=g.w(y.tracks),$a=pb.next();!$a.done;$a=pb.next())if(B=$a.value,C=g.lK(B).entityId)na.has(C)?(Ab.set(C,na.get(C)),na.delete(C)):Va.push(C);I=Number(((E=b.actionMetadata)==null?void 0:E.priority)||0)+1;L=g.w(na.entries());for(X=L.next();!X.done;X= L.next())fa=X.value,ca=g.w(fa),K=ca.next().value,la=ca.next().value,qa=K,ka=la,ha.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_ADD",qa,"musicTrack",I,$6,F6(b,ka)));Ha=g.w(Ab.entries());for(lb=Ha.next();!lb.done;lb=Ha.next())Pb=lb.value,qc=g.w(Pb),Pa=qc.next().value,Nc=qc.next().value,ke=Pa,Jd=Nc,ha.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH",ke,"musicTrack",I,$6,F6(b,Jd)));Kg=g.w(Va);for(ig=Kg.next();!ig.done;ig=Kg.next())Qh=ig.value,ha.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_DELETE",Qh, "musicTrack",0,$6));return Oc.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,ha))}})},ipb=function(a,b){var c,d; return g.J(function(e){switch(e.j){case 1:return c=l6(b),g.wa(e,2),d=g.lK(b.entityKey).entityId,d==="!*$_ALL_ENTITIES_!*$"?g.G(e,E6(a.j,b,a.C),5):g.G(e,D6(d,"musicAlbumRelease",a.j,b,a.C),6);case 6:return g.G(e,Tmb(a.j,b.entityKey),5);case 5:g.xa(e,3);break;case 2:return g.ya(e),e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED"));case 3:return e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS", c))}})},fpb=function(a,b,c){var d,e,f; return g.J(function(h){switch(h.j){case 1:return g.G(h,Ymb([b]),2);case 2:return d=h.B,g.G(h,jpb(a,d[0],c),3);case 3:return e=h.B,f=s6(e.thumbnailDetails),g.G(h,x6(f),4);case 4:return h.return(d[0].videos)}})},jpb=function(a,b,c){var d,e,f,h,l,m,n,p,q,r,t,u,y,A; return g.J(function(D){if(D.j==1){d=b.additionalMetadadatas;e=void 0;if(d&&d.length>0)for(f=g.w(d),h=f.next();!h.done;h=f.next())if(l=h.value,l.offlineMusicPlaylistData){e=l.offlineMusicPlaylistData;break}m=b.playlistId;n=Umb(b);p=n.b3;q=n.Z2;r=c?(Number(c)*1E3).toString():Date.now().toString();t=b.lastModifiedTimestamp?(Number(b.lastModifiedTimestamp)*1E3).toString():"0";u={id:g.mK(m,"musicAlbumReleaseDownloadMetadataEntity"),trackDownloadMetadatas:q,lastModifiedTimestampMillis:t,addedTimestampMillis:r, syncState:"DOWNLOAD_SYNC_STATE_UP_TO_DATE"};y={id:g.mK(m,"musicAlbumRelease"),title:b.title,audioPlaylistId:m,trackCount:b.totalVideoCount,tracks:p,downloadMetadata:u.id};e&&(y.thumbnailDetails=(A=e.albumHqThumbnail)!=null?A:e.albumArtistThumbnail,y.artistDisplayName=e.albumArtistDisplayName,y.releaseDate=e.albumReleaseDate,y.contentRating={explicitType:e.albumReleaseExplicitType},y.releaseType=e.albumReleaseType);return g.G(D,Y5(a.j,{mode:"readwrite",Pb:!0},function(F){var H=U5(F,y,"musicAlbumRelease"); F=U5(F,u,"musicAlbumReleaseDownloadMetadataEntity");return g.kt.all([H,F])}),2)}return D.return(y)})},kpb=function(a,b){this.j=a; this.C=b},mpb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D; return g.J(function(F){switch(F.j){case 1:return c=l6(b),d=g.lK(b.entityKey),e=d.entityId,f=[],g.wa(F,2),g.G(F,lpb(a,e),4);case 4:f=F.B;if((h=f)==null||!h.length){F.Ha(5);break}return g.G(F,Smb(a.j,b.entityKey),5);case 5:g.xa(F,3);break;case 2:return l=g.ya(F),m="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",n="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",l instanceof g.dt&&l.type==="QUOTA_EXCEEDED"&&(m="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED",n="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"), F.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,m,n));case 3:return p=[],g.G(F,wmb(a.j,"musicTrack",f),7);case 7:f=F.B;if(f.length)for(q=g.w(f),r=q.next();!r.done;r=q.next())if(t=r.value,u=t.offlineVideoData,y=void 0,(y=u)==null?0:y.videoId)A=void 0,D=Number(((A=b.actionMetadata)==null?void 0:A.priority)||0)+1,p.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_ADD",u.videoId,"musicTrack",D,a7,F6(b,u,e)));return F.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,p))}})}, npb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D,F,H,M,N,S,ba,ha,na,Y,R,W,v,V,cb,Ab,Va,fb,bb,pb,$a,B,C,E,I,L,X,fa,ca,K,la,qa,ka,Ha,lb,Pb,qc,Pa,Nc,ke,Jd,Kg,ig,Qh,Oc,Rh,uh,jg,vh,gd,Dj,Hk,Ik,Ej,Zc,Sh; return g.J(function(ic){switch(ic.j){case 1:return c=l6(b),d=b.entityKey,e=g.lK(d).entityId,f=[],h=!1,e==="!*$_ALL_ENTITIES_!*$"?(h=!0,g.G(ic,a6(a.j,"musicPlaylist"),5)):g.G(ic,$5(a.j,d,"musicPlaylist"),4);case 4:(l=ic.B)&&f.push(l);ic.Ha(3);break;case 5:f=ic.B;case 3:if((m=f)==null||!m.length)return ic.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));n=g.Q(b.actionMetadata,Vmb);q=(p=n)==null?void 0:p.autoSync;r=[];u=t=!0;y=!1;A=void 0;if(!h&&q===!1){ic.Ha(6);break}g.wa(ic,7);return g.G(ic, dnb(!!q,f),9);case 9:r=ic.B;g.xa(ic,8);break;case 7:D=g.ya(ic);if(!(D instanceof Error&&D.message==="No data")){D instanceof Error&&D.message==="Empty response body"&&f6(D.message);ic.Ha(8);break}return e==="!*$_ALL_ENTITIES_!*$"?g.G(ic,E6(a.j,b,a.C),8):g.G(ic,D6(e,"musicPlaylist",a.j,b,a.C),8);case 8:if(!r.length||!h&&r[0].playlistId!==e)return ic.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));case 6:if(h){F=[];H=g.w(r);for(M=H.next();!M.done;M=H.next())N=M.value,N.upToDate||q&& !N.shouldAutoSyncMetadata||!N.playlistId||(S={autoSync:q},F.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH",N.playlistId,"musicPlaylist",0,a7,{musicPlaylistEntityActionMetadata:S})));return ic.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,F))}r.length&&(ba=r[0],y=!!ba.upToDate,q&&(t=(ha=ba.shouldAutoSyncMetadata)!=null?ha:!0,u=(na=ba.shouldAutoSyncVideos)!=null?na:!0,ba.checkInSeconds&&(A=ba.checkInSeconds)));if(y||!t)return ic.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS", c));Y=[];R=f[0];W=void 0;if(!R.downloadMetadata){ic.Ha(15);break}return g.G(ic,$5(a.j,R.downloadMetadata,"musicPlaylistDownloadMetadataEntity"),16);case 16:v=ic.B,W=Number((cb=(V=v)==null?void 0:V.addedTimestampMillis)!=null?cb:"0")/1E3;case 15:return g.wa(ic,17),g.G(ic,lpb(a,e,(Ab=W)==null?void 0:Ab.toString(),A),19);case 19:Y=ic.B;g.xa(ic,18);break;case 17:Va=g.ya(ic);if(!(Va instanceof Error&&Va.message==="No data")){if(Va instanceof Error&&Va.message==="Empty response body")f6(Va.message);else return fb= "OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",bb="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",Va instanceof g.dt&&Va.type==="QUOTA_EXCEEDED"&&(fb="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED",bb="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"),ic.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,fb,bb));ic.Ha(18);break}return g.G(ic,D6(e,"musicPlaylist",a.j,b,a.C),18);case 18:if(!u)return ic.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS", c));pb=[];$a=new Map;if((B=Y)==null?0:B.length)for(C=g.w(Y),E=C.next();!E.done;E=C.next())I=E.value,L=I.offlineVideoData,X=void 0,((X=L)==null?0:X.videoId)&&$a.set(L.videoId,L);fa=new Map;ca=[];if((K=R)==null?0:(la=K.tracks)==null?0:la.length)for(qa=g.w(R.tracks),ka=qa.next();!ka.done;ka=qa.next())if(Ha=ka.value,lb=g.lK(Ha).entityId)$a.has(lb)?(fa.set(lb,$a.get(lb)),$a.delete(lb)):ca.push(lb);qc=Number(((Pb=b.actionMetadata)==null?void 0:Pb.priority)||0)+1;Pa=g.w($a.entries());for(Nc=Pa.next();!Nc.done;Nc= Pa.next())ke=Nc.value,Jd=g.w(ke),Kg=Jd.next().value,ig=Jd.next().value,Qh=Kg,Oc=ig,pb.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_ADD",Qh,"musicTrack",qc,a7,F6(b,Oc)));Rh=g.w(fa.entries());for(uh=Rh.next();!uh.done;uh=Rh.next())jg=uh.value,vh=g.w(jg),gd=vh.next().value,Dj=vh.next().value,Hk=gd,Ik=Dj,pb.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH",Hk,"musicTrack",qc,a7,F6(b,Ik)));Ej=g.w(ca);for(Zc=Ej.next();!Zc.done;Zc=Ej.next())Sh=Zc.value,pb.push(J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_DELETE", Sh,"musicTrack",0,a7));return ic.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,pb))}})},opb=function(a,b){var c,d; return g.J(function(e){switch(e.j){case 1:return c=l6(b),g.wa(e,2),d=g.lK(b.entityKey).entityId,d==="!*$_ALL_ENTITIES_!*$"?g.G(e,E6(a.j,b,a.C),5):g.G(e,D6(d,"musicPlaylist",a.j,b,a.C),6);case 6:return g.G(e,Tmb(a.j,b.entityKey),5);case 5:g.xa(e,3);break;case 2:return g.ya(e),e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED"));case 3:return e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS", c))}})},lpb=function(a,b,c,d){var e,f,h; return g.J(function(l){switch(l.j){case 1:return g.G(l,Ymb([b]),2);case 2:return e=l.B,g.G(l,ppb(a,e[0],c,d),3);case 3:return f=l.B,h=s6(f.thumbnailDetails),g.G(l,x6(h),4);case 4:return l.return(e[0].videos)}})},ppb=function(a,b,c,d){var e,f,h,l,m,n,p,q,r; return g.J(function(t){return t.j==1?(e=b.playlistId,f=Umb(b),h=f.b3,l=f.Z2,m=c?(Number(c)*1E3).toString():Date.now().toString(),n=b.lastModifiedTimestamp?(Number(b.lastModifiedTimestamp)*1E3).toString():"0",p={id:g.mK(e,"musicPlaylistDownloadMetadataEntity"),trackDownloadMetadatas:l,lastModifiedTimestampMillis:n,addedTimestampMillis:m,syncState:"DOWNLOAD_SYNC_STATE_UP_TO_DATE"},q={id:g.mK(e,"musicPlaylist"),title:b.title,playlistId:e,thumbnailDetails:b.thumbnail,visibility:qpb(b),trackCount:b.totalVideoCount, tracks:h,downloadMetadata:p.id},d&&(((r=q)==null?0:r.entityMetadata)?q.entityMetadata.nextAutoRefreshIntervalSeconds=String(d):q&&(q.entityMetadata={nextAutoRefreshIntervalSeconds:String(d)})),g.G(t,Y5(a.j,{mode:"readwrite",Pb:!0},function(u){var y=U5(u,q,"musicPlaylist");u=U5(u,p,"musicPlaylistDownloadMetadataEntity");return g.kt.all([y,u])}),2)):t.return(q)})},qpb=function(a){switch(a.privacy){case "PRIVATE":return"PLAYLIST_ENTITY_VISIBILITY_PRIVATE"; case "PUBLIC":return"PLAYLIST_ENTITY_VISIBILITY_PUBLIC";case "UNLISTED":return"PLAYLIST_ENTITY_VISIBILITY_UNLISTED";default:return"PLAYLIST_ENTITY_VISIBILITY_UNKNOWN"}},rpb=function(a,b){this.j=a; this.C=b},vpb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u; return g.J(function(y){switch(y.j){case 1:return c=l6(b),d=g.lK(b.entityKey),e=d.entityId,f=g.Q(b.actionMetadata,spb),g.wa(y,2),g.G(y,tpb(a,e,void 0,(h=f)==null?void 0:h.track,(l=f)==null?void 0:l.albumRelease),4);case 4:if((m=f)==null?0:m.playlistId){y.Ha(5);break}return g.G(y,Smb(a.j,b.entityKey),5);case 5:g.xa(y,3);break;case 2:return n=g.ya(y),p="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",q="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",n instanceof g.dt&&n.type==="QUOTA_EXCEEDED"&& (p="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED",q="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"),y.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,p,q));case 3:t=Number(((r=b.actionMetadata)==null?void 0:r.priority)||0)+1;var A=(A=g.Q(b.actionMetadata,spb))?{playbackDataActionMetadata:{maximumDownloadQuality:A.maximumDownloadQuality}}:void 0;u=J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_ADD",e,"playbackData",t,upb,A);return y.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS", c,[u]))}})},wpb=function(a,b){var c,d,e,f,h,l,m,n,p,q,r,t,u,y,A; return g.J(function(D){switch(D.j){case 1:return c=l6(b),d=g.lK(b.entityKey),e=d.entityId,g.G(D,$5(a.j,b.entityKey,"musicTrack"),2);case 2:f=D.B;if(!f){h=void 0;D.Ha(3);break}return g.G(D,$5(a.j,f.downloadMetadata,"musicTrackDownloadMetadataEntity"),4);case 4:h=D.B;case 3:l=h;if(!f||!l)return D.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c));n=g.Q(b.actionMetadata,spb);g.wa(D,5);return g.G(D,tpb(a,e,l.addedTimestampMillis,(p=n)==null?void 0:p.track,(q=n)==null?void 0:q.albumRelease), 7);case 7:t=Number(((r=b.actionMetadata)==null?void 0:r.priority)||0)+1;m=J6("OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH",e,"playbackData",t,upb);g.xa(D,6);break;case 5:u=g.ya(D);if(!(u instanceof Error&&u.message==="No data")){if(u instanceof Error&&u.message==="Empty response body")f6(u.message);else return y="OFFLINE_OPERATION_FAILURE_REASON_UNKNOWN",A="OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED",u instanceof g.dt&&u.type==="QUOTA_EXCEEDED"&&(y="OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED", A="OFFLINE_ORCHESTRATION_FAILURE_REASON_NO_STORAGE"),D.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,y,A));D.Ha(6);break}return g.G(D,C6(e,a.j,b,a.C),6);case 6:return D.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS",c,m?[m]:void 0))}})},xpb=function(a,b){var c,d; return g.J(function(e){switch(e.j){case 1:return c=l6(b),g.wa(e,2),d=g.lK(b.entityKey).entityId,d==="!*$_ALL_ENTITIES_!*$"?g.G(e,E6(a.j,b,a.C),5):g.G(e,C6(d,a.j,b,a.C),6);case 6:return g.G(e,Tmb(a.j,b.entityKey),5);case 5:g.xa(e,3);break;case 2:return g.ya(e),e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_FAILURE",c,void 0,"OFFLINE_OPERATION_FAILURE_REASON_DATABASE_REQUEST_FAILED","OFFLINE_ORCHESTRATION_FAILURE_REASON_DATABASE_OPERATION_FAILED"));case 3:return e.return(new K6("OFFLINE_ORCHESTRATION_ACTION_RESULT_SUCCESS", c))}})},tpb=function(a,b,c,d,e){var f,h,l,m,n,p; return g.J(function(q){switch(q.j){case 1:if(f=d){q.Ha(2);break}return g.G(q,Xmb([b]),3);case 3:h=q.B,l=h[0],f=Rmb(l);case 2:return g.G(q,ypb(a,f,b,e,c),4);case 4:m=q.B;n=m.musicTrackEntity;p=m.q7;var r=s6(n.thumbnailDetails),t=[];p&&(t=s6(p.thumbnailDetails));return g.G(q,x6(r.concat(t)),0)}})},ypb=function(a,b,c,d,e){var f; return g.J(function(h){return h.j==1?(e||(e=Date.now().toString()),f={id:g.mK(c,"musicTrackDownloadMetadataEntity"),playbackData:g.mK(c,"playbackData"),addedTimestampMillis:e,videoDownloadContextEntity:g.mK(c,"videoDownloadContextEntity")},d&&(b.albumRelease=d.id),g.G(h,Y5(a.j,{mode:"readwrite",Pb:!0},function(l){var m=[],n=U5(l,f,"musicTrackDownloadMetadataEntity");m.push(n);n=U5(l,b,"musicTrack");m.push(n);d&&(l=U5(l,d,"musicAlbumRelease"),m.push(l));return g.kt.all(m)}),2)):h.j!=3?g.G(h,p6(c,"musicTrackDownloadMetadataEntity", a.j,"DOWNLOAD_STATE_PENDING_DOWNLOAD"),3):h.return({musicTrackEntity:b, q7:d})})},b7=function(){W6.apply(this,arguments); this.Y="musicTrack"},zpb=function(){g.ST.apply(this,arguments); var a=this;this.events=new g.iE(this);this.W=this.player.U();this.hd={Wna:function(){return a.j}, tK:function(){return a.tK()}, tQ:function(b){return a.tQ(b)}}},Apb=function(a){var b; a=g.Q((b=a.getWatchNextResponse())==null?void 0:b.currentVideoEndpoint,g.VP);if(a==null?0:a.playlistId)var c=a.playlistId;return c},Bpb=function(a,b){var c,d,e,f; return g.J(function(h){if(h.j==1){c=b.clientPlaybackNonce;d={cpn:c,offlineSourceVisualElement:g.lw(b.Ma||"").getAsJson(),selectedOfflineMode:"OFFLINE_NOW",isPartialPlayback:!1};b.B&&(d.videoFmt=Number(b.B.itag));b.D&&(d.audioFmt=Number(b.D.itag));if((e=Apb(b))&&b.videoId){var l=b.videoId;l=e!=="PPSV"?Promise.resolve(!1):a.j.YU(l);h=g.G(h,l,3)}else h=h.Ha(2);return h}h.j!=2&&(f=h.B)&&(d.selectedOfflineMode="OFFLINE_MODE_TYPE_AUTO_OFFLINE");a.B=c;g.Xs("offlinePlaybackStarted",d);g.va(h)})}; g.z(M5,L5);g.ea.Object.defineProperties(M5.prototype,{entityMetadata:{configurable:!0,enumerable:!0,get:function(){return this.j.entityMetadata}, set:function(a){this.j.entityMetadata=a}}}); g.z(Hjb,M5);Hjb.prototype.B=function(){return[]}; g.z(Ijb,M5);Ijb.prototype.B=function(){var a=[];this.j.alternateChannel&&a.push(this.j.alternateChannel);this.j.alternateChannelList&&a.push.apply(a,g.x(this.j.alternateChannelList));this.j.oneofChannelEntity&&a.push(this.j.oneofChannelEntity);return[].concat(g.x(new Set(a)))}; g.z(Jjb,M5);Jjb.prototype.B=function(){var a=[];this.j.entryCollection&&a.push(this.j.entryCollection);return[].concat(g.x(new Set(a)))}; g.z(Kjb,L5);Kjb.prototype.B=function(){var a=[];this.j.video&&a.push(this.j.video);return[].concat(g.x(new Set(a)))}; g.z(Ljb,M5);Ljb.prototype.B=function(){var a=[];this.j.parentPlaylist&&a.push(this.j.parentPlaylist);if(this.j.entries)for(var b=g.w(this.j.entries),c=b.next();!c.done;c=b.next())a.push.apply(a,g.x((new Kjb(c.value)).B()));return[].concat(g.x(new Set(a)))}; g.z(Mjb,M5);Mjb.prototype.B=function(){var a=[];this.j.descriptionEntity&&a.push(this.j.descriptionEntity);this.j.creators&&a.push.apply(a,g.x(this.j.creators));this.j.theBiggestFan&&a.push(this.j.theBiggestFan);return[].concat(g.x(new Set(a)))}; g.z(Njb,M5);Njb.prototype.B=function(){return[]}; g.z(Ojb,M5);Ojb.prototype.B=function(){return[]}; g.z(Pjb,M5);Pjb.prototype.B=function(){return[]}; g.z(Qjb,M5);Qjb.prototype.B=function(){return[]}; g.z(Rjb,M5);Rjb.prototype.B=function(){return[]}; g.z(Sjb,M5);Sjb.prototype.B=function(){return[]}; g.z(Tjb,M5);Tjb.prototype.B=function(){return[]}; g.z(Ujb,M5);Ujb.prototype.B=function(){return[]}; g.z(Vjb,M5);Vjb.prototype.B=function(){var a=[];this.j.downloadsList&&a.push(this.j.downloadsList);this.j.smartDownloadsList&&a.push(this.j.smartDownloadsList);this.j.recommendedDownloadsList&&a.push(this.j.recommendedDownloadsList);this.j.refresh&&a.push(this.j.refresh);return[].concat(g.x(new Set(a)))}; g.z(Wjb,L5);Wjb.prototype.B=function(){var a=[];this.j.video&&a.push(this.j.video);this.j.playlist&&a.push(this.j.playlist);this.j.videoItem&&a.push(this.j.videoItem);this.j.playlistItem&&a.push(this.j.playlistItem);return[].concat(g.x(new Set(a)))}; g.z(Xjb,M5);Xjb.prototype.B=function(){var a=[];this.j.refresh&&a.push(this.j.refresh);if(this.j.downloads)for(var b=g.w(this.j.downloads),c=b.next();!c.done;c=b.next())a.push.apply(a,g.x((new Wjb(c.value)).B()));return[].concat(g.x(new Set(a)))}; g.z(Yjb,M5);Yjb.prototype.B=function(){var a=[];this.j.localImageEntities&&a.push.apply(a,g.x(this.j.localImageEntities));return[].concat(g.x(new Set(a)))}; g.z(Zjb,M5);Zjb.prototype.B=function(){var a=[];this.j.playbackData&&a.push(this.j.playbackData);this.j.localImageEntities&&a.push.apply(a,g.x(this.j.localImageEntities));this.j.videoDownloadContextEntity&&a.push(this.j.videoDownloadContextEntity);return[].concat(g.x(new Set(a)))}; g.z($jb,M5);$jb.prototype.B=function(){return[]}; g.z(akb,M5);akb.prototype.B=function(){var a=[];this.j.fakeChildren&&a.push.apply(a,g.x(this.j.fakeChildren));return[].concat(g.x(new Set(a)))}; g.z(bkb,M5);bkb.prototype.B=function(){var a=[];this.j.video&&a.push(this.j.video);this.j.playbackData&&a.push(this.j.playbackData);this.j.offlineVideoPolicy&&a.push(this.j.offlineVideoPolicy);return[].concat(g.x(new Set(a)))}; g.z(ckb,M5);ckb.prototype.B=function(){return[]}; g.z(dkb,M5);dkb.prototype.B=function(){var a=[];this.j.channelOwner&&a.push(this.j.channelOwner);this.j.videos&&a.push.apply(a,g.x(this.j.videos));this.j.collaboratorChannels&&a.push.apply(a,g.x(this.j.collaboratorChannels));this.j.downloadState&&a.push(this.j.downloadState);this.j.refresh&&a.push(this.j.refresh);return[].concat(g.x(new Set(a)))}; g.z(ekb,M5);ekb.prototype.B=function(){var a=[];this.j.video&&a.push(this.j.video);this.j.channelContributor&&a.push(this.j.channelContributor);return[].concat(g.x(new Set(a)))}; g.z(fkb,L5);fkb.prototype.B=function(){var a=[];this.j.localImageEntities&&a.push.apply(a,g.x(this.j.localImageEntities));this.j.videoDownloadContextEntity&&a.push(this.j.videoDownloadContextEntity);return[].concat(g.x(new Set(a)))}; g.z(gkb,L5);gkb.prototype.B=function(){var a=[];this.j.recommendedVideoMetadata&&a.push.apply(a,g.x((new fkb(this.j.recommendedVideoMetadata)).B()));return[].concat(g.x(new Set(a)))}; g.z(hkb,L5);hkb.prototype.B=function(){var a=[];this.j.playbackPosition&&a.push(this.j.playbackPosition);return[].concat(g.x(new Set(a)))}; g.z(ikb,M5);ikb.prototype.B=function(){var a=[];this.j.owner&&a.push(this.j.owner);this.j.downloadState&&a.push(this.j.downloadState);this.j.userState&&a.push.apply(a,g.x((new hkb(this.j.userState)).B()));this.j.additionalMetadata&&a.push.apply(a,g.x((new gkb(this.j.additionalMetadata)).B()));return[].concat(g.x(new Set(a)))}; g.z(jkb,M5);jkb.prototype.B=function(){var a=[];this.j.userChannelDetails&&a.push(this.j.userChannelDetails);return[].concat(g.x(new Set(a)))}; g.z(kkb,M5);kkb.prototype.B=function(){var a=[];this.j.channelOwner&&a.push(this.j.channelOwner);this.j.playbackPosition&&a.push(this.j.playbackPosition);this.j.localImageEntities&&a.push.apply(a,g.x(this.j.localImageEntities));this.j.downloadStatus&&a.push(this.j.downloadStatus);return[].concat(g.x(new Set(a)))}; g.z(lkb,M5);lkb.prototype.B=function(){return[]}; g.z(mkb,M5);mkb.prototype.B=function(){return[]}; g.z(nkb,M5);nkb.prototype.B=function(){return[]}; g.z(okb,M5);okb.prototype.B=function(){return[]}; g.z(pkb,M5);pkb.prototype.B=function(){return[]}; g.z(qkb,M5);qkb.prototype.B=function(){return[]}; g.z(rkb,M5);rkb.prototype.B=function(){return[]}; g.z(skb,M5);skb.prototype.B=function(){return[]}; g.z(tkb,M5);tkb.prototype.B=function(){var a=[];this.j.trackDownloadMetadatas&&a.push.apply(a,g.x(this.j.trackDownloadMetadatas));return[].concat(g.x(new Set(a)))}; g.z(ukb,M5); ukb.prototype.B=function(){var a=[];this.j.downloadedTracks&&a.push.apply(a,g.x(this.j.downloadedTracks));this.j.smartDownloadedTracks&&a.push.apply(a,g.x(this.j.smartDownloadedTracks));this.j.downloadedEpisodes&&a.push.apply(a,g.x(this.j.downloadedEpisodes));this.j.downloadedAlbumReleases&&a.push.apply(a,g.x(this.j.downloadedAlbumReleases));this.j.smartDownloadedAlbumReleases&&a.push.apply(a,g.x(this.j.smartDownloadedAlbumReleases));this.j.downloadedPlaylists&&a.push.apply(a,g.x(this.j.downloadedPlaylists));this.j.smartDownloadedPlaylists&& a.push.apply(a,g.x(this.j.smartDownloadedPlaylists));this.j.metadataOnlyTracks&&a.push.apply(a,g.x(this.j.metadataOnlyTracks));return[].concat(g.x(new Set(a)))}; g.z(vkb,M5);vkb.prototype.B=function(){var a=[];this.j.trackDownloadMetadatas&&a.push.apply(a,g.x(this.j.trackDownloadMetadatas));return[].concat(g.x(new Set(a)))}; g.z(wkb,M5);wkb.prototype.B=function(){var a=[];this.j.playbackData&&a.push(this.j.playbackData);this.j.localImageEntities&&a.push.apply(a,g.x(this.j.localImageEntities));this.j.videoDownloadContextEntity&&a.push(this.j.videoDownloadContextEntity);return[].concat(g.x(new Set(a)))}; g.z(xkb,M5);xkb.prototype.B=function(){var a=[];this.j.musicLibraryStatusEntity&&a.push(this.j.musicLibraryStatusEntity);this.j.primaryArtists&&a.push.apply(a,g.x(this.j.primaryArtists));this.j.details&&a.push(this.j.details);this.j.userDetails&&a.push(this.j.userDetails);this.j.tracks&&a.push.apply(a,g.x(this.j.tracks));this.j.share&&a.push(this.j.share);this.j.downloadMetadata&&a.push(this.j.downloadMetadata);this.j.refresh&&a.push(this.j.refresh);return[].concat(g.x(new Set(a)))}; g.z(ykb,M5);ykb.prototype.B=function(){var a=[];this.j.albumRelease&&a.push(this.j.albumRelease);this.j.tracks&&a.push.apply(a,g.x(this.j.tracks));return[].concat(g.x(new Set(a)))}; g.z(zkb,M5);zkb.prototype.B=function(){var a=[];this.j.albumRelease&&a.push(this.j.albumRelease);return[].concat(g.x(new Set(a)))}; g.z(Akb,M5);Akb.prototype.B=function(){var a=[];this.j.details&&a.push(this.j.details);this.j.userDetails&&a.push(this.j.userDetails);return[].concat(g.x(new Set(a)))}; g.z(Bkb,M5);Bkb.prototype.B=function(){var a=[];this.j.parentArtist&&a.push(this.j.parentArtist);return[].concat(g.x(new Set(a)))}; g.z(Ckb,M5);Ckb.prototype.B=function(){var a=[];this.j.parentArtist&&a.push(this.j.parentArtist);return[].concat(g.x(new Set(a)))}; g.z(Dkb,M5);Dkb.prototype.B=function(){return[]}; g.z(Ekb,M5);Ekb.prototype.B=function(){return[]}; g.z(Fkb,L5);Fkb.prototype.B=function(){var a=[];this.j.creatorEntity&&a.push(this.j.creatorEntity);return[].concat(g.x(new Set(a)))}; g.z(Gkb,M5); Gkb.prototype.B=function(){var a=[];this.j.tracks&&a.push.apply(a,g.x(this.j.tracks));this.j.refresh&&a.push(this.j.refresh);this.j.musicLibraryStatusEntity&&a.push(this.j.musicLibraryStatusEntity);this.j.details&&a.push(this.j.details);this.j.downloadMetadata&&a.push(this.j.downloadMetadata);this.j.sideloadMetadata&&a.push(this.j.sideloadMetadata);this.j.userDetails&&a.push(this.j.userDetails);this.j.entryCollection&&a.push(this.j.entryCollection);this.j.share&&a.push(this.j.share);this.j.podcastShowAdditionalMetadata&&a.push.apply(a, g.x((new Fkb(this.j.podcastShowAdditionalMetadata)).B()));return[].concat(g.x(new Set(a)))}; g.z(Hkb,M5);Hkb.prototype.B=function(){return[]}; g.z(Ikb,M5); Ikb.prototype.B=function(){var a=[];this.j.musicLibraryStatusEntity&&a.push(this.j.musicLibraryStatusEntity);this.j.artists&&a.push.apply(a,g.x(this.j.artists));this.j.audioModeVersion&&a.push(this.j.audioModeVersion);this.j.videoModeVersion&&a.push(this.j.videoModeVersion);this.j.userDetails&&a.push(this.j.userDetails);this.j.details&&a.push(this.j.details);this.j.albumRelease&&a.push(this.j.albumRelease);this.j.share&&a.push(this.j.share);this.j.libraryEdit&&a.push(this.j.libraryEdit);this.j.downloadMetadata&& a.push(this.j.downloadMetadata);this.j.playbackPosition&&a.push(this.j.playbackPosition);return[].concat(g.x(new Set(a)))}; g.z(Jkb,M5);Jkb.prototype.B=function(){var a=[];this.j.parentTrack&&a.push(this.j.parentTrack);return[].concat(g.x(new Set(a)))}; g.z(Kkb,M5);Kkb.prototype.B=function(){var a=[];this.j.parentTrack&&a.push(this.j.parentTrack);return[].concat(g.x(new Set(a)))}; g.z(Lkb,M5);Lkb.prototype.B=function(){return[]}; g.z(Mkb,M5);Mkb.prototype.B=function(){return[]}; g.z(Nkb,M5);Nkb.prototype.B=function(){return[]}; g.z(Okb,M5);Okb.prototype.B=function(){return[]}; g.z(Pkb,M5);Pkb.prototype.B=function(){var a=[];this.j.transfer&&a.push(this.j.transfer);this.j.adsPlaybackData&&a.push.apply(a,g.x(this.j.adsPlaybackData));this.j.drmLicense&&a.push(this.j.drmLicense);this.j.offlineVideoPolicy&&a.push(this.j.offlineVideoPolicy);this.j.videoDownloadContextEntity&&a.push(this.j.videoDownloadContextEntity);return[].concat(g.x(new Set(a)))}; g.z(Qkb,M5);Qkb.prototype.B=function(){return[]}; g.z(Rkb,M5);Rkb.prototype.B=function(){var a=[];this.j.offlineVideoStreams&&a.push.apply(a,g.x(this.j.offlineVideoStreams));this.j.captionTrack&&a.push.apply(a,g.x(this.j.captionTrack));return[].concat(g.x(new Set(a)))}; g.z(Skb,M5);Skb.prototype.B=function(){return[]}; g.z(Tkb,M5);Tkb.prototype.B=function(){return[]}; g.z(Ukb,M5);Ukb.prototype.B=function(){return[]}; g.z(Vkb,M5);Vkb.prototype.B=function(){return[]}; g.z(Wkb,M5);Wkb.prototype.B=function(){return[]}; g.z(Xkb,M5);Xkb.prototype.B=function(){return[]}; g.z(Ykb,M5);Ykb.prototype.B=function(){return[]}; g.z(Zkb,M5);Zkb.prototype.B=function(){return[]}; g.z($kb,M5);$kb.prototype.B=function(){return[]}; g.z(alb,M5);alb.prototype.B=function(){return[]}; g.z(blb,M5);blb.prototype.B=function(){return[]}; g.z(clb,M5);clb.prototype.B=function(){return[]}; g.z(dlb,M5);dlb.prototype.B=function(){return[]}; g.z(elb,M5);elb.prototype.B=function(){return[]}; g.z(flb,M5);flb.prototype.B=function(){return[]}; var enb=["browse","music/browse","unplugged/browse"],jnb=["offline/playlist_sync_check"],Wmb=["offline"],fnb=["offline/offline_video_playback_position_sync"],hnb=["offline/get_playback_data_entity"];N5.getInstance=function(){return g.J(function(a){return a.return(new Promise(function(b){g.Nt().then(function(c){c?(N5.instance||(N5.instance=new N5(c)),b(N5.instance)):b(void 0)})}))})}; N5.prototype.get=function(a){var b=this,c,d,e;return g.J(function(f){if(f.j==1)return g.G(f,glb(b.token),2);if(f.j!=3)return c=f.B,g.G(f,c.get("prefs",a),3);d=f.B;if(!d)return f.return();e=(0,g.T)();return d.expirationTimestampMs<=e?f.return():f.return(d.value)})}; N5.prototype.set=function(a,b,c){c=c===void 0?31536E3:c;var d=this,e,f,h;return g.J(function(l){if(l.j==1)return e=(0,g.T)(),f={key:a,value:b,expirationTimestampMs:e+c*1E3},g.G(l,glb(d.token),2);h=l.B;return g.G(l,g.ut(h,"prefs",f),0)})}; N5.prototype.remove=function(a){var b=this,c;return g.J(function(d){if(d.j==1)return g.G(d,glb(b.token),2);c=d.B;return g.G(d,c.delete("prefs",a),0)})}; var O5;g.z(P5,g.Hs);g.z(Q5,olb);Q5.prototype.C=function(a,b){b=qlb(b);a=(new TextEncoder).encode(JSON.stringify(a));return this.j.encrypt(a,b)}; Q5.prototype.B=function(a,b){if(!(a instanceof Uint8Array))throw klb(1);var c=new TextDecoder;b=qlb(b);a=this.j.decrypt(a,b);return JSON.parse(c.decode(a))}; var rlb={buttonEntity:$kb,captionTrack:Lkb,channelHandle:Hjb,commerceAcquisitionClientPayloadEntity:blb,commerceCartListEntity:clb,continuationTokenEntity:ckb,downloadQualityPickerEntity:Sjb,downloadsPageRefreshTokenEntity:Ujb,downloadsPageViewConfigurationEntity:lkb,downloadStatusEntity:Tjb,sfvAudioItemCurrentlyPlayingEntity:Tkb,emojiFountainDataEntity:Ykb,emojiCustomizationSetEntity:Xkb,fakeChannel:Ijb,fakePlaylist:Jjb,fakePlaylistEntryCollection:Ljb,fakeVideo:Mjb,fakeVideoDescription:Njb,featuredProductsEntity:qkb, flowStateEntity:Ojb,iconBadgeEntity:dlb,interstitialInteractionStateEntity:Qjb,liveChatPollStateEntity:Rjb,liveReactionsDataEntity:Zkb,logoEntity:Pjb,macroMarkerEntity:mkb,mainDownloadsLibraryEntity:Vjb,mainDownloadsListEntity:Xjb,mainPlaylistDownloadStateEntity:Yjb,mainPlaylistEntity:dkb,mainPlaylistVideoEntity:ekb,mainVideoDownloadStateEntity:Zjb,mainVideoEntity:ikb,markersEngagementPanelSyncEntity:nkb,markersVisibilityOverrideEntity:okb,musicAlbumReleaseDetail:ykb,musicAlbumReleaseDownloadMetadataEntity:tkb, musicAlbumRelease:xkb,musicAlbumReleaseUserDetail:zkb,musicArtistDetail:Bkb,musicArtist:Akb,musicArtistUserDetail:Ckb,musicDownloadsLibraryEntity:ukb,musicLibraryEdit:Dkb,musicLibraryStatusEntity:Ekb,musicPlaylist:Gkb,musicPlaylistDownloadMetadataEntity:vkb,musicShare:Hkb,musicTrackDetail:Jkb,musicTrackDownloadMetadataEntity:wkb,musicTrack:Ikb,musicTrackUserDetail:Kkb,offlineOrchestrationActionWrapperEntity:Mkb,offlineVideoPolicy:Nkb,offlineVideoStreams:Okb,offlineabilityEntity:$jb,orchestrationWebSamplingEntity:akb, pageHeaderEntity:Wkb,pdpStateEntity:elb,pinnedProductEntity:rkb,playbackData:Pkb,playerStateEntity:pkb,quantityIncrementerEntity:flb,refresh:Qkb,saveToPlaylistListEntity:Ukb,settingEntity:Vkb,transfer:Rkb,trendingOfferEntity:skb,videoDownloadContextEntity:Skb,videoPlaybackPositionEntity:alb,ytMainChannelEntity:jkb,ytMainDownloadedVideoEntity:bkb,ytMainVideoEntity:kkb};g.z(W5,olb);W5.prototype.C=function(a){return a}; W5.prototype.B=function(a){if(a instanceof Uint8Array)throw klb(0);return a}; g.z(X5,g.O);X5.prototype.B=function(a){Flb(this,a.data)}; X5.prototype.xa=function(){this.channel.close()}; var Llb;var Hmb=new g.lq("elementsCommand");var z6=new g.lq("entityBatchUpdate");var vmb=new g.lq("downloadStatusEntity");var Lob=new g.lq("mainPlaylistEntityActionMetadata");var Z6=new g.lq("mainVideoEntityActionMetadata");var Vmb=new g.lq("musicPlaylistEntityActionMetadata");var spb=new g.lq("musicTrackEntityActionMetadata");var Imb=new g.lq("offlineOrchestrationActionCommand");var $ob=new g.lq("localImageEntityActionMetadata");var L6=new g.lq("playbackDataActionMetadata");var Anb=new g.lq("transferEntityActionMetadata");var snb=new g.lq("videoPlaybackPositionEntityActionMetadata");g.mK("","downloadsPageViewConfigurationEntity");g.mK("DOWNLOADS_LIST_ENTITY_ID_MANUAL_DOWNLOADS","mainDownloadsListEntity");var A6=g.mK("DOWNLOADS_LIST_ENTITY_ID_SMART_DOWNLOADS","mainDownloadsListEntity");g.mK("DOWNLOADS_LIST_ENTITY_ID_SMART_DOWNLOADS","refresh");g.mK("SMART_DOWNLOADS_ENABLED","settingEntity");g.mK("SMART_DOWNLOADS_OPT_IN_BANNER_DISMISSED","settingEntity");var $lb;new g.cj;new g.cj;emb.prototype.request=function(a,b,c){b=b===void 0?{}:b;return this.locks.request(a,b,function(d){return c(d)})};var e6=g.Ka.caches,d6,jmb;c6.prototype.open=function(a){return e6.open(hmb(a))}; c6.prototype.has=function(a){return e6.has(hmb(a))}; c6.prototype.delete=function(a){return e6.delete(hmb(a))}; c6.prototype.match=function(a,b){var c=this,d,e,f,h,l,m;return g.J(function(n){switch(n.j){case 1:return g.G(n,c.keys(),2);case 2:d=n.B,e=g.w(d),f=e.next();case 3:if(f.done){n.Ha(5);break}h=f.value;return g.G(n,c.open(h),6);case 6:return l=n.B,g.G(n,l.match(a,b),7);case 7:if(m=n.B)return n.return(m);f=e.next();n.Ha(3);break;case 5:return n.return()}})}; g.z(gmb,c6);gmb.prototype.keys=function(){var a,b,c,d,e,f,h,l,m;return g.J(function(n){if(n.j==1)return a=[],b=g.Is("CacheStorage keys"),g.G(n,e6.keys(),2);c=n.B;d=g.w(c);for(e=d.next();!e.done;e=d.next()){f=e.value;var p=f.indexOf(":");h=p===-1?{ML:f}:{ML:f.substring(0,p),datasyncId:f.substring(p+1)};l=h.ML;m=h.datasyncId;m===b&&a.push(l)}return n.return(a)})};g.z(g6,g.O);g6.prototype.C=function(a){this.api.ib("onOfflineOperationFailure",a.data)}; g6.prototype.D=function(a){this.api.publish("offlinetransferpause",a.data)}; g6.prototype.xa=function(){var a;(a=this.j)==null||a.close();var b;(b=this.B)==null||b.close()};mmb.prototype.Jf=function(){this.j&&i6(this)}; mmb.prototype.jM=function(){this.B&&this.B.resolve();this.C=this.j=!1;this.Y()};var Qnb=["OFFLINE_ORCHESTRATION_ACTION_TYPE_ADD","OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH"];var Emb="captionTrack downloadStatusEntity ytMainChannelEntity mainPlaylistEntity mainPlaylistDownloadStateEntity mainPlaylistVideoEntity mainVideoEntity mainVideoDownloadStateEntity offlineVideoPolicy offlineVideoStreams playbackData transfer videoDownloadContextEntity videoPlaybackPositionEntity".split(" ");var Qmb="downloadStatusEntity musicAlbumRelease musicDownloadsLibraryEntity musicPlaylist musicTrack musicTrackDownloadMetadataEntity offlineVideoPolicy offlineVideoStreams playbackData transfer videoDownloadContextEntity".split(" ");g.z(lnb,I6);lnb.prototype.B=function(a){return m6(a)?onb(this,a):n6(a)?pnb(this,a):Promise.reject(Error("Unsupported action type: "+a.actionType))};g.z(qnb,I6);qnb.prototype.B=function(a){return n6(a)?rnb(this,a):umb(a)?tnb(this,a):o6(a)?unb(this,a):Promise.reject(Error("Unsupported action type: "+a.actionType))};g.z(vnb,I6);vnb.prototype.B=function(a){return m6(a)?xnb(this,a):n6(a)?ynb(this,a):umb(a)?znb(this,a):Promise.reject(Error("Unsupported action type: "+a.actionType))};Fnb.prototype.j=function(a,b){var c=a.action.actionMetadata.priority-b.action.actionMetadata.priority;c===0&&(a.jb.j&&(c=1));return c};g.z(N6,g.O);N6.prototype.xa=function(){this.Y&&this.Y();g.O.prototype.xa.call(this)}; N6.prototype.createAction=function(a,b){var c=g.lK(a.entityKey).entityType,d=g.kv(16);return new t6(c,d,a,b.actionId,b.rootActionId)}; N6.prototype.ra=function(a){var b=this,c,d,e,f,h,l,m,n,p;return g.J(function(q){if(q.j==1){if(b.La())return q.return();d=(c=a.offlineOrchestrationActionWrapperEntity)!=null?c:new Set;e=[];f=g.w(d);for(h=f.next();!h.done;h=f.next())l=h.value,m=g.lK(l),n=m.entityId,Inb(b.j,n)||e.push(l);return g.G(q,Tnb(b,e),2)}p=q.B;return g.G(q,Snb(b,p),0)})}; N6.prototype.retry=function(){var a=this;return g.J(function(b){return g.G(b,Unb(a),0)})};g.k=$nb.prototype;g.k.Maa=function(a){var b=this,c,d,e,f;return g.J(function(h){if(!g.Z(a.state,128))return h.Ha(0);c=a.state.fh;var l=(d=c)==null?void 0:d.errorCode,m=(e=c)==null?void 0:e.dA;f=l==="net.connect"&&m===1?"TRANSFER_FAILURE_REASON_NETWORK_LOST":(l==null?0:l.startsWith("net."))?"TRANSFER_FAILURE_REASON_NETWORK":"TRANSFER_FAILURE_REASON_INTERNAL";return g.G(h,b.sy(b.player.getVideoData().videoId,f),0)})}; g.k.sy=function(a,b){var c=this;return g.J(function(d){if(d.j==1){if(c.B)return d.return();c.B=!0;return b==="TRANSFER_FAILURE_REASON_NETWORK_LOST"?(P6(c,a,!1,!0),d.Ha(0)):g.G(d,O6(c,a),3)}g.rP(a,4);return g.G(d,c.j.sy(b),0)})}; g.k.AL=function(a){a.status===2?(a.status!==this.C&&(sob(this.j),g.rP(a.videoId,2)),a.ZG&&xob(this.j,a.videoId,a.ZG)):a.status===4?(O6(this,a.videoId),this.sy(a.videoId,a.CK?"TRANSFER_FAILURE_REASON_FILESYSTEM_WRITE":"TRANSFER_FAILURE_REASON_INTERNAL")):a.status===1&&wob(this.j);this.C=a.status;this.api.ib("localmediachange",{videoId:a.videoId,status:a.status})}; g.k.cS=function(){var a=this,b;return g.J(function(c){if(c.j==1){if(a.B)return c.return();a.B=!0;b=a.player.getVideoData().videoId;return g.G(c,O6(a,b),2)}return g.G(c,a.j.cS(),0)})}; g.k.QP=function(a){switch(a){case "HD_1080":return"hd1080";case "HD":return"hd720";case "SD":return"large";case "LD":return"tiny";default:return"hd720"}}; g.k.L=function(a){return this.api.U().L(a)};g.z(Q6,g.O);Q6.prototype.xa=function(){this.B&&this.B();g.O.prototype.xa.call(this)}; Q6.prototype.C=function(a){var b=this,c,d,e,f,h,l,m,n;return g.J(function(p){d=(c=a.transfer)!=null?c:new Set;e=[];f=g.w(d);for(h=f.next();!h.done;h=f.next())l=h.value,m=g.lK(l),n=m.entityId,e.push(n);return e.length===0?p.return():g.G(p,gob(b,e),0)})};g.z(lob,g.O);g.k=lob.prototype;g.k.xa=function(){this.Aa&&this.Aa();this.Fa.dispose();this.D.dispose();this.Ka&&g.Ic(this.K.Fm,this.Ka);this.Ma&&g.Ic(this.K.Fm,this.Ma);g.O.prototype.xa.call(this)}; g.k.Rca=function(a){var b=this,c,d,e;return g.J(function(f){switch(f.j){case 1:c=g.mK(a,"transfer");if(b.j&&c===b.j.key){P6(b.N,b.G,!0);b.D.stop();f.Ha(0);break}return g.G(f,Y5(b.B,{mode:"readwrite",Pb:!0},function(h){return R5(h,c,"transfer").then(function(l){if(l&&l.transferState!=="TRANSFER_STATE_COMPLETE"&&l.transferState!=="TRANSFER_STATE_FAILED")return l.transferState="TRANSFER_STATE_PAUSED_BY_USER",U5(h,l,"transfer").then(function(){return l})})}),3); case 3:d=f.B;if(!d){f.Ha(0);break}if(!a||!b.C){f.Ha(5);break}return g.G(f,p6(a,b.C,b.B,"DOWNLOAD_STATE_PAUSED"),5);case 5:return g.G(f,T6(b,a),7);case 7:e=f.B,smb({videoId:a,Tl:d,offlineModeType:e}),g.va(f)}})}; g.k.Qca=function(){var a=this;if(this.j&&this.G){P6(this.N,this.G,!1);var b=this.j,c=(b==null?0:b.key)?g.lK(b.key).entityId:"";c&&this.C&&(new Promise(function(d,e){p6(c,a.C,a.B,"DOWNLOAD_STATE_PAUSED").catch(function(f){e(f)})})).catch(function(d){f6("Download state setting error",d)})}this.D.stop()}; g.k.tH=function(){this.j?oob(this,this.j):S6(this)}; g.k.W4=function(a){var b=this;return g.J(function(c){switch(c.j){case 1:if(!b.j){c.Ha(2);break}if(b.j.transferState==="TRANSFER_STATE_COMPLETE"||b.j.transferState==="TRANSFER_STATE_FAILED"||!a.transfer||!a.transfer.has(b.j.key)){c.Ha(3);break}return g.G(c,$5(b.B,b.j.key,"transfer"),4);case 4:b.j=c.B;if(b.j){c.Ha(3);break}return g.G(c,pob(b),3);case 3:if(b.j)return c.return();case 2:return g.G(c,S6(b),0)}})}; g.k.sy=function(a,b){var c=this,d,e,f,h,l;return g.J(function(m){switch(m.j){case 1:if(!c.j){U6(c,"onTransferFailure: "+a);m.Ha(2);break}d=c.j;f=((e=d)==null?0:e.key)?g.lK(d.key).entityId:"";a:switch(a){case "TRANSFER_FAILURE_REASON_FILESYSTEM_WRITE":case "TRANSFER_FAILURE_REASON_EXTERNAL_FILESYSTEM_WRITE":case "TRANSFER_FAILURE_REASON_PLAYABILITY":case "TRANSFER_FAILURE_REASON_TOO_MANY_RETRIES":var n=!1;break a;default:n=!0}return n&&yob(c)?g.G(m,V6(c,"TRANSFER_STATE_TRANSFER_IN_QUEUE"),8):g.G(m, zob(c,a),5);case 5:if(!f||!c.C){m.Ha(2);break}return g.G(m,p6(f,c.C,c.B,"DOWNLOAD_STATE_FAILED"),2);case 8:return g.G(m,T6(c,f),9);case 9:h=m.B;k6({transferStatusType:"TRANSFER_STATUS_TYPE_REENQUEUED_BY_RETRY"},{videoId:f,Tl:d,offlineModeType:h});if(!f||!c.C){m.Ha(2);break}return g.G(m,p6(f,c.C,c.B,"DOWNLOAD_STATE_RETRYABLE_FAILURE"),2);case 2:R6(c),l=S6(c,!0),b&&b(l),g.va(m)}})}; g.k.cS=function(a){var b=this,c,d,e,f,h,l,m,n,p,q,r,t;return g.J(function(u){switch(u.j){case 1:if(!b.j){U6(b,"onMaybeTransferStreamsExpired");u.Ha(2);break}return yob(b)?g.G(u,V6(b,"TRANSFER_STATE_WAITING_FOR_PLAYER_RESPONSE_REFRESH"),9):g.G(u,zob(b,"TRANSFER_FAILURE_REASON_STREAM_MISSING"),5);case 5:if(!b.C){u.Ha(2);break}c=b.j;e=((d=c)==null?0:d.key)?g.lK(c.key).entityId:"";if(!e){u.Ha(2);break}return g.G(u,p6(e,b.C,b.B,"DOWNLOAD_STATE_FAILED"),2);case 9:return b.j||U6(b,"onMaybeTransferStreamsExpiredRetryAttempting"), f=b.j,l=((h=f)==null?0:h.key)?g.lK(f.key).entityId:"",g.G(u,T6(b,l),10);case 10:return m=u.B,k6({transferStatusType:"TRANSFER_STATUS_TYPE_DEQUEUED_BY_PLAYER_RESPONSE_EXPIRATION"},{videoId:l,Tl:f,offlineModeType:m}),n=ymb(),g.Dw(n,L6,{isEnqueuedForExpiredStreamUrlRefetch:!0}),p=g.mK(l,"playbackData"),q={actionType:"OFFLINE_ORCHESTRATION_ACTION_TYPE_ADD",entityKey:p,actionMetadata:n},r=v6(new t6("playbackData",l,q)),g.G(u,Z5(b.B,r,"offlineOrchestrationActionWrapperEntity"),2);case 2:R6(b),t=S6(b,!0), a&&a(t),g.va(u)}})}; var Cpb={},Aob=(Cpb.TRANSFER_STATE_TRANSFERRING=1,Cpb.TRANSFER_STATE_TRANSFER_IN_QUEUE=2,Cpb);g.k=W6.prototype;g.k.TQ=function(){return this.G.promise}; g.k.XT=function(){if(this.B&&this.K)return this.G.promise;Dob(this).then(this.G.resolve).catch(this.G.reject);return this.G.promise}; g.k.iF=function(a){var b={};return b.playbackData=new lnb(a,this.W,this.j),b.transfer=new vnb(a,this.W),b.videoPlaybackPositionEntity=new qnb(a,this.W),b}; g.k.oT=function(){var a=this;return g.J(function(b){return a.B?g.G(b,mob(a.B),0):b.Ha(0)})}; g.k.cU=function(){var a=this,b,c;return g.J(function(d){if(d.j==1)return a.B||a.K?g.G(d,a.TQ(),2):d.return();a.Z!==void 0&&(g.fr(a.Z),a.Z=void 0);a.D!==void 0&&(g.fr(a.D),a.D=void 0);(b=a.B)==null||b.dispose();a.B=void 0;(c=a.K)==null||c.dispose();a.K=void 0;a.api.ib("onOrchestrationLostLeader");a.G=new g.cj;g.va(d)})}; g.k.isOrchestrationLeader=function(){return this.C.j}; g.k.YU=function(){return g.J(function(a){return a.return(!1)})}; g.k.ES=function(a){var b=this.j;b.api.publish("offlinetransferpause",a);var c;(c=b.B)==null||c.postMessage(a)}; g.k.tH=function(a){var b,c;return g.J(function(d){if(d.j==1)return g.G(d,b6(),2);b=d.B;if(!b)return d.return();c=g.mK(a,"transfer");return g.G(d,Y5(b,{mode:"readwrite",Pb:!0},function(e){var f=R5(e,c,"transfer"),h=R5(e,g.mK(a,"videoDownloadContextEntity"),"videoDownloadContextEntity");return g.kt.all([f,h]).then(function(l){l=g.w(l);var m=l.next().value;var n=l.next().value;return m&&m.transferState==="TRANSFER_STATE_PAUSED_BY_USER"?(m.transferState="TRANSFER_STATE_TRANSFER_IN_QUEUE",U5(e,m,"transfer").then(function(){k6({transferStatusType:"TRANSFER_STATUS_TYPE_REENQUEUED_BY_USER_RESUME", statusType:"USER_RESUMED"},{videoId:a,Tl:m,offlineModeType:n==null?void 0:n.offlineModeType});return g.kt.resolve(null)})):g.kt.resolve(null)})}),0)})}; g.k.YS=function(a){a=a===void 0?43200:a;var b=this,c,d,e,f,h,l,m,n;return g.J(function(p){if(p.j==1)return b.N.Kh()?g.G(p,b6(),2):p.return(Eob());if(p.j!=3){c=p.B;if(!c)return p.return([]);d=Date.now()/1E3;return g.G(p,a6(c,"offlineVideoPolicy"),3)}e=p.B;f=[];h=g.w(e);for(l=h.next();!l.done;l=h.next())m=l.value,Number(m.lastUpdatedTimestampSeconds)+a<=d&&(n=g.lK(m.key).entityId,f.push(n));return f.length?p.return(X6(b,f,b.Y,"OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH")):p.return([])})}; g.k.deleteAll=function(){return X6(this,["!*$_ALL_ENTITIES_!*$"],this.Y,"OFFLINE_ORCHESTRATION_ACTION_TYPE_DELETE",{offlineLoggingData:{offlineDeleteReason:"OFFLINE_DELETE_REASON_USER_INITIATED"}})}; g.k.refreshAllStaleEntities=function(a){var b=this;return g.J(function(c){return c.j==1?g.G(c,b.YS(a),2):c.return(c.B)})}; g.k.setUpPositionSyncInterval=function(a){var b=this;this.D!==void 0&&(g.fr(this.D),this.D=void 0);var c=a!=null?a:864E5;this.D=g.dr(function(){b.LM(c)},c)}; g.k.LM=function(a){var b=this,c,d,e,f,h,l;return g.J(function(m){switch(m.j){case 1:return g.wa(m,2),g.G(m,N5.getInstance(),4);case 4:c=m.B;if(!c)throw Error("prefStorage is undefined");return g.G(m,c.get("psi"),5);case 5:d=m.B;f=((e=d)==null?0:e.hR)?Number(d.hR)/1E3:0;h=Date.now();if(!(f+a<=h)){m.Ha(6);break}return g.G(m,X6(b,["!*$_ALL_ENTITIES_!*$"],"videoPlaybackPositionEntity","OFFLINE_ORCHESTRATION_ACTION_TYPE_REFRESH"),6);case 6:g.xa(m,0);break;case 2:l=g.ya(m),f6("Offline manager error",l), g.va(m)}})}; g.k.lT=function(){var a=this,b,c,d,e,f,h,l;return g.J(function(m){if(m.j==1)return g.G(m,b6(),2);if(m.j!=3)return(b=m.B)?g.G(m,a6(b,"transfer"),3):m.return([]);c=m.B;d=[];e=g.w(c);for(f=e.next();!f.done;f=e.next())h=f.value,h.transferState==="TRANSFER_STATE_WAITING_FOR_PLAYER_RESPONSE_REFRESH"&&h.key&&(l=g.lK(h.key).entityId,d.push(l));return m.return(Gob(a,d))})}; g.k.QO=function(){return g.J(function(a){return a.return([])})}; g.k.I_=function(){return g.J(function(a){g.va(a)})}; g.k.bX=function(){return g.J(function(a){g.va(a)})};g.z(Hob,I6);Hob.prototype.B=function(a){return m6(a)?Kob(this,a):n6(a)?Mob(this,a):o6(a)?Nob(this,a):Promise.reject(Error("Unsupported action type: "+a.actionType))}; var Y6=[10];g.z(Sob,I6);Sob.prototype.B=function(a){return m6(a)?Vob(this,a):n6(a)?Wob(this,a):o6(a)?Xob(this,a):Promise.reject(Error("Unsupported action type: "+a.actionType))}; var Uob=[10];g.z(Zob,I6);Zob.prototype.B=function(a){return n6(a)?apb(this,a):Promise.reject(Error("Unsupported action type: "+a.actionType))};g.z(bpb,W6);g.k=bpb.prototype;g.k.iF=function(a){var b=W6.prototype.iF.call(this,a);b.mainVideoEntity=new Sob(a,this.W,this.j);b.mainPlaylistEntity=new Hob(a,this.W,this.j);b.mainDownloadsListEntity=new Zob(a,this.W,this.j);return b}; g.k.refreshAllStaleEntities=function(a,b){var c=this,d,e,f,h,l,m,n,p,q,r,t;return g.J(function(u){switch(u.j){case 1:d=[];if(!c.W.L("web_player_offline_playlist_auto_refresh")){u.Ha(2);break}return g.G(u,cpb(c,a,b),3);case 3:d=u.B;case 2:return g.G(u,N5.getInstance(),4);case 4:return e=u.B,g.G(u,(f=e)==null?void 0:f.get("sdois"),5);case 5:return h=u.B,g.G(u,(l=e)==null?void 0:l.get("lmqf"),6);case 6:m=u.B;if(!h){u.Ha(7);break}p=d;q=p.concat;return g.G(u,dpb(c,h,(n=m)!=null?n:"SD",a===0),8);case 8:d= q.call(p,u.B);case 7:return r=d,t=r.concat,g.G(u,W6.prototype.refreshAllStaleEntities.call(c,a,b),9);case 9:return d=t.call(r,u.B),u.return(d)}})}; g.k.YU=function(a){var b,c,d,e,f,h,l,m;return g.J(function(n){if(n.j==1)return g.G(n,b6(),2);if(n.j!=3)return(b=n.B)?g.G(n,$5(b,A6,"mainDownloadsListEntity"),3):n.return(!1);c=n.B;if((d=c)==null?0:(e=d.downloads)==null?0:e.length)for(f=g.mK(a,"mainVideoEntity"),h=g.w(c.downloads),l=h.next();!l.done;l=h.next())if(m=l.value,m.videoItem===f)return n.return(!0);return n.return(!1)})}; g.k.QO=function(){var a=this,b,c,d,e,f,h,l,m;return g.J(function(n){if(n.j==1)return g.G(n,b6(),2);if(n.j!=3)return(b=n.B)?g.G(n,a6(b,"downloadStatusEntity"),3):n.return([]);c=n.B;d=[];e=g.w(c);for(f=e.next();!f.done;f=e.next())h=f.value,h.downloadState==="DOWNLOAD_STATE_USER_DELETED"&&h.key&&(l=g.lK(h.key).entityId,d.push(l));return d.length?(m={offlineLoggingData:{offlineDeleteReason:"OFFLINE_DELETE_REASON_USER_INITIATED"}},n.return(X6(a,d,"mainVideoEntity","OFFLINE_ORCHESTRATION_ACTION_TYPE_DELETE", m))):n.return([])})}; g.k.bX=function(){var a;return g.J(function(b){return b.j==1?g.G(b,b6(),2):(a=b.B)?g.G(b,Y5(a,{mode:"readwrite",Pb:!0},function(c){return S5(c,"mainVideoEntity").then(function(d){var e=[];d=g.w(d);for(var f=d.next();!f.done;f=d.next()){f=f.value;var h=void 0;(h=f.userState)!=null&&h.playbackPosition||(h=g.lK(f.key).entityId,h={key:g.mK(h,"videoPlaybackPositionEntity"),videoId:h,lastPlaybackPositionSeconds:"0"},e.push(U5(c,h,"videoPlaybackPositionEntity")),f.userState={playbackPosition:h.key},e.push(U5(c, f,"mainVideoEntity")))}return g.kt.all(e)})}),0):b.return()})}; g.k.I_=function(){var a,b,c,d,e,f,h,l,m,n,p,q,r,t,u,y,A,D,F,H,M,N,S,ba,ha,na,Y,R,W,v,V,cb,Ab,Va,fb,bb,pb,$a;return g.J(function(B){if(B.j==1)return g.G(B,b6(),2);if(B.j!=3){a=B.B;if(!a)return B.return();b=g.mK("DOWNLOADS_LIST_ENTITY_ID_MANUAL_DOWNLOADS","mainDownloadsListEntity");return g.G(B,Y5(a,{mode:"readonly",Pb:!0},function(C){return g.kt.all([R5(C,b,"mainDownloadsListEntity"),R5(C,A6,"mainDownloadsListEntity"),S5(C,"mainVideoEntity"),S5(C,"mainPlaylistEntity")])}),3)}c=B.B; d=g.w(c);e=d.next().value;f=d.next().value;h=d.next().value;l=d.next().value;m=e;n=f;p=h;q=l;r=new Set;if((t=m)==null?0:(u=t.downloads)==null?0:u.length)for(y=g.w(m.downloads),A=y.next();!A.done;A=y.next())D=A.value,F=void 0,(H=(F=D.videoItem)!=null?F:D.playlistItem)&&r.add(H);if((M=n)==null?0:(N=M.downloads)==null?0:N.length)for(S=g.w(n.downloads),ba=S.next();!ba.done;ba=S.next())ha=ba.value,ha.videoItem&&r.add(ha.videoItem);na=new Set;Y=[];R=g.w(q);for(W=R.next();!W.done;W=R.next()){v=W.value;if(v.videos)for(V= g.w(v.videos),cb=V.next();!cb.done;cb=V.next())Ab=cb.value,(Va=JSON.parse(g.lK(Ab).entityId).videoId)&&na.add(Va);v.key&&!r.has(v.key)&&Y.push(v.key)}fb=g.w(p);for(bb=fb.next();!bb.done;bb=fb.next())pb=bb.value,pb.key&&!r.has(pb.key)&&($a=g.lK(pb.key).entityId,na.has($a)||Y.push(pb.key));return Y.length?g.G(B,Mmb(a,Y),0):B.Ha(0)})};g.z(epb,I6);epb.prototype.B=function(a){return m6(a)?gpb(this,a):n6(a)?hpb(this,a):o6(a)?ipb(this,a):Promise.reject(Error("Unsupported action type: "+a.actionType))}; var $6=[10];g.z(kpb,I6);kpb.prototype.B=function(a){return m6(a)?mpb(this,a):n6(a)?npb(this,a):o6(a)?opb(this,a):Promise.reject(Error("Unsupported action type: "+a.actionType))}; var a7=[10];g.z(rpb,I6);rpb.prototype.B=function(a){return m6(a)?vpb(this,a):n6(a)?wpb(this,a):o6(a)?xpb(this,a):Promise.reject(Error("Unsupported action type: "+a.actionType))}; var upb=[10];g.z(b7,W6);b7.prototype.iF=function(a){var b=W6.prototype.iF.call(this,a);b.musicTrack=new rpb(a,this.j);b.musicPlaylist=new kpb(a,this.j);b.musicAlbumRelease=new epb(a,this.j);return b}; b7.prototype.refreshAllStaleEntities=function(a,b){var c=this,d,e,f;return g.J(function(h){if(h.j==1)return e=d=[],f=e.concat,g.G(h,W6.prototype.refreshAllStaleEntities.call(c,a,b),2);d=f.call(e,h.B);return h.return(d)})};g.z(zpb,g.ST);g.k=zpb.prototype;g.k.create=function(){var a=this;g.P(this,this.events);g.KO(this.W)?this.j=new bpb(this.W,this.player):g.yy(this.W)&&(this.j=new b7(this.W,this.player));this.events.T(this.player,"onPlaybackStartExternal",function(){a.tK()}); this.events.T(this.player,"videodatachange",function(){a.tK()}); this.W.L("html5_offline_playback_position_sync")&&this.events.T(this.player,"presentingplayerstatechange",this.tQ)}; g.k.pn=function(){return!1}; g.k.B1=function(a,b,c,d){var e=this;return g.J(function(f){return e.j?f.return(X6(e.j,a,b,c,d)):f.return(Promise.reject())})}; g.k.deleteAll=function(){return this.j.deleteAll()}; g.k.YS=function(a){return this.j.YS(a)}; g.k.refreshAllStaleEntities=function(a){return this.j.refreshAllStaleEntities(a)}; g.k.setUpPositionSyncInterval=function(a){this.j.setUpPositionSyncInterval(a)}; g.k.ES=function(a){this.j.ES(a)}; g.k.tH=function(a){return this.j.tH(a)}; g.k.tK=function(){var a=this,b;return g.J(function(c){b=a.player.getVideoData();return g.GQ(b)?Apb(b)&&a.B!==b.clientPlaybackNonce?g.G(c,Bpb(a,b),0):c.Ha(0):c.return()})}; g.k.tQ=function(a){var b=this,c,d,e,f;return g.J(function(h){if(!g.fy(a,2)&&!g.fy(a,512))return h.return();c=Math.floor(b.player.getCurrentTime()).toString();d=b.player.getVideoData();e=d.videoId;f={videoPlaybackPositionEntityActionMetadata:{lastPlaybackPositionSeconds:c}};return g.G(h,b.B1([e],"videoPlaybackPositionEntity","OFFLINE_ORCHESTRATION_ACTION_TYPE_UPDATE",f),0)})}; g.k.isOrchestrationLeader=function(){return this.j.isOrchestrationLeader()}; g.k.updateDownloadState=function(a,b){var c,d,e,f;return g.J(function(h){if(h.j==1)return g.G(h,b6(),2);c=h.B;if(!c)return f6("PES is undefined"),h.return();d=g.lK(a);e=d.entityType;f=d.entityId;return g.G(h,p6(f,e,c,b,!0),0)})};g.RT("offline",zpb);})(_yt_player);