import{b as _,c as u}from"./chunk-K6LRUFYU.js";import{$ as f,B as p,C as v,D as S,Hf as T,Nc as C,R as d,Ud as y,Xf as I,Y as b,bf as D,dg as $,i as E,j as l,k as g,m as c,ng as V,vd as h,xe as A}from"./chunk-QXV2GR6R.js";import{i as s}from"./chunk-JJ4RDTEF.js";var F=(()=>{let n=class n{constructor(r,i,t,e){s(this,"authHttp");s(this,"serverService");s(this,"restExtractor");s(this,"confirmService");this.authHttp=r,this.serverService=i,this.restExtractor=t,this.confirmService=e;}listCaptions(r,i){let t=_.buildVideoPasswordHeader(i);return this.authHttp.get(`${u.BASE_VIDEO_URL}/${r}/captions`,{headers:t}).pipe(d(e=>this.serverService.getServerLocale().pipe(c(a=>({captionsResult:e,translations:a})))),c(({captionsResult:e,translations:a})=>{for(let o of e.data)o.language.label=A(o.language.label,a);return e;}),c(e=>(y(e.data,"language","label"),e))).pipe(p(e=>this.restExtractor.handleError(e)));}removeCaption(r,i){return this.authHttp.delete(`${u.BASE_VIDEO_URL}/${r}/captions/${i}`).pipe(p(t=>this.restExtractor.handleError(t)));}addCaption(r,i,t){let a=T({captionfile:t});return this.authHttp.put(`${u.BASE_VIDEO_URL}/${r}/captions/${i}`,a).pipe(p(o=>this.restExtractor.handleError(o)));}updateCaptions(r,i){let t=l(void 0);for(let e of i)e.action==="CREATE"||e.action==="UPDATE"?t=t.pipe(d(()=>this.addCaption(r,e.language.id,e.captionfile))):e.action==="REMOVE"&&(t=t.pipe(d(()=>this.removeCaption(r,e.language.id))));return t;}getCaptionContent({captionPath:r}){return this.authHttp.get(D.originServerUrl+r,{responseType:"text"});}generateCaption(r){let{videos:i}=r;return E(i).pipe(S(t=>this.generateCaptionOfSpecificVideo({video:t,forceTranscription:!1})),v(),c(t=>t.reduce((e,a)=>(a==="success"&&(e.success+=1),a==="already-has-captions"&&(e.alreadyHasCaptions+=1),a==="already-being-transcribed"&&(e.alreadyBeingTranscribed+=1),e),{success:0,alreadyHasCaptions:0,alreadyBeingTranscribed:0})),p(t=>this.restExtractor.handleError(t)));}generateCaptionOfSpecificVideo(r){let{video:i,forceTranscription:t}=r,e={forceTranscription:t};return this.authHttp.post(`${u.BASE_VIDEO_URL}/${i.id}/captions/generate`,e).pipe(c(()=>"success"),p(a=>{let o=a.error;if((o==null?void 0:o.code)===h.VIDEO_ALREADY_BEING_TRANSCRIBED&&!t){let H="PeerTube considers video \""+i.name+"\" is already being transcripted."+" If you think PeerTube is wrong (video in broken state after a crash etc.), you can force transcription on this video."+" Do you still want to run transcription?";return E(this.confirmService.confirm(H,"Prisili transkripciju")).pipe(d(O=>O===!1?g(()=>a):this.generateCaptionOfSpecificVideo({video:i,forceTranscription:!0})));}return(o==null?void 0:o.code)===h.VIDEO_ALREADY_HAS_CAPTIONS?l("already-has-captions"):(o==null?void 0:o.code)===h.VIDEO_ALREADY_BEING_TRANSCRIBED?l("already-being-transcribed"):g(()=>a);}));}};s(n,"\u0275fac",function(i){return new(i||n)(f(C),f(V),f(I),f($));}),s(n,"\u0275prov",b({token:n,factory:n.ɵfac}));let m=n;return m;})();export{F as a};/**i18n:224bcada6943fe8b17ea60808c2d370cec9507c3bd670ebe71692d099a3befa1*///# sourceMappingURL=chunk-IUCE563K.js.map