import{b as _,c as u}from"./chunk-KHRLI7AH.js";import{$ as f,B as p,C as v,D as S,Gf as T,Mc as C,R as d,Td as y,Wf as I,Y as b,af as D,ag as $,i as E,j as l,k as g,kg as V,m as c,ud as h,we as A}from"./chunk-X3RCWQ3R.js";import{i as s}from"./chunk-SR6RTMQI.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 \xE1l\xEDtur myndskei\xF0i\xF0 \""+i.name+"\" vera \xFEegar umrita\xF0."+"Ef \xFE\xFA heldur a\xF0 PeerTube hafi rangt fyrir s\xE9r (myndskei\xF0 s\xE9 skemmt eftir hrun, o.s.frv.), getur\xF0u \xFEvinga\xF0 fram umritun \xE1 \xFEessu myndskei\xF0i."+" Do you still want to run transcription?";return E(this.confirmService.confirm(H,"\xDEvinga umritun")).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:3d16453f213eb5db982e7e7dd90631843ac5d3f860726a614777c3e9e3f9b57e*///# sourceMappingURL=chunk-WOGP3NJL.js.map