import{r as C}from"./chunk-C6uGsfWa.js";import{Gt as K,Wa as g,Wn as Po,f as Ae,fr as S,gt as G,in as Lje,li as Xe,xs as q}from"./chunk-B_pj7Jpm.js";import{t}from"./chunk-KfmDNYov.js";import{t as A}from"./chunk-FhARnEsq.js";var a=(0,C(Po()).default)(`peertube:search:FindInBulkService`);var p=class n{searchService=g(A);advancedSearchForBulk;getVideoInBulk;getChannelInBulk;getPlaylistInBulk;constructor(){this.getVideoInBulk=this.buildBulkObservableObject(this.getVideosInBulk.bind(this)),this.getChannelInBulk=this.buildBulkObservableObject(this.getChannelsInBulk.bind(this)),this.getPlaylistInBulk=this.buildBulkObservableObject(this.getPlaylistsInBulk.bind(this)),this.advancedSearchForBulk=new t({searchTarget:`local`})}getVideo(e){return a(`Schedule video fetch for uuid %s.`,e),this.getData({observableObject:this.getVideoInBulk,finder:t=>t.uuid===e||t.shortUUID===e,param:e})}getChannel(e){return a(`Schedule channel fetch for handle %s.`,e),this.getData({observableObject:this.getChannelInBulk,finder:t=>t.nameWithHost===e||t.nameWithHostForced===e,param:e})}getPlaylist(e){return a(`Schedule playlist fetch for uuid %s.`,e),this.getData({observableObject:this.getPlaylistInBulk,finder:t=>t.uuid===e||t.shortUUID===e,param:e})}getData(e){let{observableObject:t,param:s,finder:k}=e;return new q(i=>{t.result.pipe(Ae(r=>r.params.includes(s)),Xe(),G(r=>r.response.data),G(r=>r.find(k))).subscribe({next:r=>{if(!r){i.error(new Error(`No se encontró el elemento ${s}`));return}i.next(r),i.complete()},error:r=>i.error(r)}),t.notifier.next(s)})}getVideosInBulk(e){return a(`Fetching videos %s.`,e.join(`, `)),this.searchService.searchVideos({uuids:e,componentPagination:{itemsPerPage:e.length,currentPage:1},skipCount:!0,advancedSearch:this.advancedSearchForBulk})}getChannelsInBulk(e){return a(`Fetching channels %s.`,e.join(`, `)),this.searchService.searchVideoChannels({handles:e,componentPagination:{itemsPerPage:e.length,currentPage:1},advancedSearch:this.advancedSearchForBulk})}getPlaylistsInBulk(e){return a(`Fetching playlists %s.`,e.join(`, `)),this.searchService.searchVideoPlaylists({uuids:e,componentPagination:{itemsPerPage:e.length,currentPage:1},advancedSearch:this.advancedSearchForBulk})}buildBulkObservableObject(e){let t=new K;return{notifier:t,result:Lje({time:100,bulkGet:e,notifierObservable:t.asObservable()})}}static ɵfac=function(t){return new(t||n)};static ɵprov=S({token:n,factory:n.ɵfac})};export{p as t};
//# debugId=a2cb58cd-c25a-5c91-9a8d-87e815999147
//# sourceMappingURL=chunk-DjbsLBsJ.js.map