1import{a as j}from"./chunk-KEEUBRDB.js";import{a as F,c as J,d as S}from"./chunk-V3JZPFOE.js";import{Af as A,B as n,M as T,Og as f,Pf as w,Q as p,S as o,Ug as Y,Xg as Q,Y as U,Ye as N,aa as u,cg as H,d as b,f as L,fg as B,gf as V,gh as M,hg as g,hh as k,j as C,ld as O,lh as G,md as P,n as m,pd as _,se as D,th as W,v as I,x as R}from"./chunk-HVCWS4IF.js";import{a as E,g as K,j as h}from"./chunk-KJ7W2O2B.js";var q=K(Q());var v=class{id;position;startTimestamp;stopTimestamp;type;video;constructor(t,e={}){this.id=t.id,this.position=t.position,this.startTimestamp=t.startTimestamp,this.stopTimestamp=t.stopTimestamp,this.type=t.type,t.video&&(this.video=new F(t.video,e))}};var y=class{id;uuid;shortUUID;isLocal;url;displayName;description;privacy;videosLength;type;createdAt;updatedAt;ownerAccount;videoChannelPosition;videoChannel;thumbnails;thumbnailPath;thumbnailUrl;embedPath;embedUrl;ownerBy;videoChannelBy;static buildWatchUrl(t){return N({shortUUID:t.shortUUID||t.uuid})}constructor(t,e){this.id=t.id,this.uuid=t.uuid,this.shortUUID=t.shortUUID,this.url=t.url,this.isLocal=t.isLocal,this.displayName=t.displayName,this.description=t.description,this.privacy=t.privacy,this.embedPath=t.embedPath,this.embedUrl=t.embedUrl||B()+t.embedPath,this.videosLength=t.videosLength,this.type=t.type,this.thumbnails=t.thumbnails,this.createdAt=new Date(t.createdAt),this.updatedAt=new Date(t.updatedAt),this.ownerAccount=t.ownerAccount,this.ownerBy=f.CREATE_BY_STRING(t.ownerAccount.name,t.ownerAccount.host),this.videoChannelPosition=t.videoChannelPosition,t.videoChannel&&(this.videoChannel=t.videoChannel,this.videoChannelBy=f.CREATE_BY_STRING(t.videoChannel.name,t.videoChannel.host)),this.privacy.label=V(this.privacy.label,e),this.type.id===D.WATCH_LATER&&(this.displayName=V(this.displayName,e))}getThumbnailUrl(t){let e=H()+"/client/assets/images/default-playlist.jpg";return Y(this.thumbnails,t,"16:9")||e}};var x=(0,q.default)("peertube:playlists:VideoPlaylistService"),r=class r{authHttp=u(_);auth=u(k);serverService=u(W);restExtractor=u(M);restService=u(G);videoExistsInPlaylistNotifier=new L(1);videoExistsInPlaylistCacheSubject=new b;videoExistsInPlaylistObservable;videoExistsObservableCache={};videoExistsCache={};myAccountPlaylistCache=void 0;myAccountPlaylistCacheRunning;myAccountPlaylistCacheSubject=new b;constructor(){this.videoExistsInPlaylistObservable=I(w({time:200,bulkGet:t=>this.auth.isLoggedIn()?this.doVideosExistInPlaylist(t):C({}),notifierObservable:this.videoExistsInPlaylistNotifier}).pipe(m(({response:t})=>t)),this.videoExistsInPlaylistCacheSubject)}listChannelPlaylists(t){let{videoChannel:e}=t,i=S.BASE_VIDEO_CHANNEL_URL+e.nameWithHost+"/video-playlists";return this.listPlaylists(E({url:i},t))}listAccountPlaylists(t){let{account:e}=t,i=J.BASE_ACCOUNT_URL+e.nameWithHost+"/video-playlists";return this.listPlaylists(E({url:i},t))}listPlaylists(t){let{url:e,sort:i,search:s,includeCollaborations:a}=t,l=new P,c=t.restPagination;return!c&&t.componentPagination&&(c=this.restService.componentToRestPagination(t.componentPagination)),l=this.restService.addRestGetParams(l,c,i),a&&(l=l.append("includeCollaborations","true")),s&&(l=this.restService.addObjectParams(l,{search:s})),this.authHttp.get(e,{params:l}).pipe(p(d=>this.extractPlaylists(d)),n(d=>this.restExtractor.handleError(d)))}listMyPlaylistWithCache(t,e){if(!e){if(this.myAccountPlaylistCacheRunning)return this.myAccountPlaylistCacheRunning;if(this.myAccountPlaylistCache)return C(this.myAccountPlaylistCache)}let i=this.listAccountPlaylists({account:t.account,sort:"-updatedAt",includeCollaborations:!0,search:e}).pipe(o(s=>{e||(this.myAccountPlaylistCacheRunning=void 0,this.myAccountPlaylistCache=s)}),T());return e||(this.myAccountPlaylistCacheRunning=i),i}getVideoPlaylist(t){let e=r.BASE_VIDEO_PLAYLIST_URL+t;return this.authHttp.get(e).pipe(p(i=>this.extractPlaylist(i)),n(i=>this.restExtractor.handleError(i)))}createVideoPlaylist(t){let e=g(t);return this.authHttp.post(r.BASE_VIDEO_PLAYLIST_URL,e).pipe(o(i=>{this.myAccountPlaylistCache&&(this.myAccountPlaylistCache.total++,this.myAccountPlaylistCache.data.push({id:i.videoPlaylist.id,displayName:t.displayName}),this.myAccountPlaylistCacheSubject.next(this.myAccountPlaylistCache))}),n(i=>this.restExtractor.handleError(i)))}updateVideoPlaylist(t,e){let i=g(e);return this.authHttp.put(r.BASE_VIDEO_PLAYLIST_URL+t.id,i).pipe(o(()=>
1{if(!this.myAccountPlaylistCache)return;let s=this.myAccountPlaylistCache.data.find(a=>a.id===t.id);s.displayName=e.displayName,this.myAccountPlaylistCacheSubject.next(this.myAccountPlaylistCache)}),n(s=>this.restExtractor.handleError(s)))}removeVideoPlaylist(t){return this.authHttp.delete(r.BASE_VIDEO_PLAYLIST_URL+t.id).pipe(o(()=>{this.myAccountPlaylistCache&&(this.myAccountPlaylistCache.total--,this.myAccountPlaylistCache.data=this.myAccountPlaylistCache.data.filter(e=>e.id!==t.id),this.myAccountPlaylistCacheSubject.next(this.myAccountPlaylistCache))}),n(e=>this.restExtractor.handleError(e)))}addVideoInPlaylist(t,e){let i=r.BASE_VIDEO_PLAYLIST_URL+t+"/videos";return this.authHttp.post(i,e).pipe(o(s=>{if(this.videoExistsCache[e.videoId].push({playlistId:t,playlistElementId:s.videoPlaylistElement.id,startTimestamp:e.startTimestamp,stopTimestamp:e.stopTimestamp}),this.runVideoExistsInPlaylistCheck(e.videoId),this.myAccountPlaylistCache){let l=this.myAccountPlaylistCache.data.find(d=>d.id===t);if(!l)return;let c=this.myAccountPlaylistCache.data.filter(d=>d!==l);this.myAccountPlaylistCache.data=[l,...c]}}),n(s=>this.restExtractor.handleError(s)))}updateVideoOfPlaylist(t,e,i,s){return this.authHttp.put(r.BASE_VIDEO_PLAYLIST_URL+t+"/videos/"+e,i).pipe(o(()=>{let a=this.videoExistsCache[s];if(a){let l=a.find(c=>c.playlistElementId===e);l.startTimestamp=i.startTimestamp,l.stopTimestamp=i.stopTimestamp}this.runVideoExistsInPlaylistCheck(s)}),n(a=>this.restExtractor.handleError(a)))}removeVideoFromPlaylist(t,e,i){return this.authHttp.delete(r.BASE_VIDEO_PLAYLIST_URL+t+"/videos/"+e).pipe(o(()=>{i&&(this.videoExistsCache[i]&&(this.videoExistsCache[i]=this.videoExistsCache[i].filter(s=>s.playlistElementId!==e)),this.runVideoExistsInPlaylistCheck(i))}),n(s=>this.restExtractor.handleError(s)))}reorderPlaylistsOfChannel(t,e,i){let s={startPosition:e,insertAfterPosition:i};return this.authHttp.post(S.BASE_VIDEO_CHANNEL_URL+t+"/video-playlists/reorder",s).pipe(n(a=>this.restExtractor.handleError(a)))}reorderVideosOfPlaylist(t,e,i){let s={startPosition:e,insertAfterPosition:i};return this.authHttp.post(r.BASE_VIDEO_PLAYLIST_URL+t+"/videos/reorder",s).pipe(n(a=>this.restExtractor.handleError(a)))}getPlaylistVideos(t){let e=r.BASE_VIDEO_PLAYLIST_URL+t.videoPlaylistId+"/videos",i=this.restService.componentToRestPagination(t.componentPagination),s=new P;return s=this.restService.addRestGetParams(s,i),this.authHttp.get(e,{params:s}).pipe(p(a=>this.extractVideoPlaylistElements(a)),n(a=>this.restExtractor.handleError(a)))}listenToMyAccountPlaylistsChange(){return this.myAccountPlaylistCacheSubject.asObservable()}listenToVideoPlaylistChange(t){if(this.videoExistsObservableCache[t])return this.videoExistsObservableCache[t];let e=this.videoExistsInPlaylistObservable.pipe(m(i=>i[t]),R(i=>!!i),o(i=>this.videoExistsCache[t]=i));return this.videoExistsObservableCache[t]=e,e}runVideoExistsInPlaylistCheck(t){return x("Running playlist check."),this.videoExistsCache[t]?(x("Found cache for %d.",t),this.videoExistsInPlaylistCacheSubject.next({[t]:this.videoExistsCache[t]})):(x("Fetching from network for %d.",t),this.videoExistsInPlaylistNotifier.next(t))}extractPlaylists(t){return this.serverService.getServerLocale().pipe(m(e=>{let i=t.data,s=t.total,a=[];for(let l of i)a.push(new y(l,e));return{data:a,total:s}}))}extractPlaylist(t){return this.serverService.getServerLocale().pipe(m(e=>new y(t,e)))}extractVideoPlaylistElements(t){return this.serverService.getServerLocale().pipe(m(e=>{let i=t.data,s=t.total,a=[];for(let l of i)a.push(new v(l,e));return{total:s,data:a}}))}doVideosExistInPlaylist(t){let e=r.MY_VIDEO_PLAYLIST_URL+"videos-exist",i=new P;return i=this.restService.addObjectParams(i,{videoIds:t}),this.authHttp.get(e,{params:i,context:new O().set(j,!0)}).pipe(n(s=>this.restExtractor.handleError(s)))}};h(r,"BASE_VIDEO_PLAYLIST_URL",A.apiUrl+"/api/v1/video-playlists/"),h(r,"MY_VIDEO_PLAYLIST_URL",A.apiUrl+"/api/v1/users/me/video-playlists/"),h(r,"\u0275fac",function(e){return new(e||r)}),h(r,"\u0275prov",U({token:r,factory:r.\u0275fac,providedIn:"root"}));var X=r;export{y as a,X as b}; 2/**i18n:347eeb695970c32bc275618edc2e751c67145d9fc3012e70543c114a99b9e016*/
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.