import{r as C}from"./chunk-C6uGsfWa.js";import{Ja as g,Mr as S,Mt as Gje,Ri as Ze,St as G,cn as K,mr as Po,x as Ae,xs as q}from"./chunk-b0nJCs5_.js";import{t}from"./chunk-BMaHP5rD2.js";import{t as A}from"./chunk-2WQXD8yV2.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)),Ze(),G(r=>r.response.data),G(r=>r.find(k))).subscribe({next:r=>{if(!r){i.error(new Error(`Elemento ${s} ne trovita`));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:Gje({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=afcfafd5-1b07-5f88-9857-ebfdd424a75e
//# sourceMappingURL=chunk-WJVwu_bH2.js.map