import{b as V,c as f}from"./chunk-MJB3GDSZ.js";import{B as c,C as b,Ch as I,D as C,Hh as $,Nd as l,Q as p,Re as A,Y as S,aa as d,bd as v,bh as D,i as m,j as u,k as g,me as y,n as s,vh as T}from"./chunk-747XQIKV.js";import{i as h}from"./chunk-D3F7ONO7.js";var F=(()=>{let n=class n{authHttp=d(v);serverService=d($);restExtractor=d(T);confirmService=d(I);listCaptions(t,i){let r=V.buildVideoPasswordHeader(i);return this.authHttp.get(`${f.BASE_VIDEO_URL}/${t}/captions`,{headers:r}).pipe(p(e=>this.serverService.getServerLocale().pipe(s(o=>({captionsResult:e,translations:o})))),s(({captionsResult:e,translations:o})=>{for(let a of e.data)a.language.label=A(a.language.label,o);return e;}),s(e=>(y(e.data,"language","label"),e))).pipe(c(e=>this.restExtractor.handleError(e)));}removeCaption(t,i){return this.authHttp.delete(`${f.BASE_VIDEO_URL}/${t}/captions/${i}`).pipe(c(r=>this.restExtractor.handleError(r)));}addCaption(t,i,r){let o=D({captionfile:r});return this.authHttp.put(`${f.BASE_VIDEO_URL}/${t}/captions/${i}`,o).pipe(c(a=>this.restExtractor.handleError(a)));}updateCaptions(t,i){let r=u(void 0);for(let e of i)e.action==="CREATE"||e.action==="UPDATE"?r=r.pipe(p(()=>this.addCaption(t,e.language.id,e.captionfile))):e.action==="REMOVE"&&(r=r.pipe(p(()=>this.removeCaption(t,e.language.id))));return r;}getCaptionContent({fileUrl:t}){return this.authHttp.get(t,{responseType:"text"});}generateCaption(t){let{videos:i}=t;return m(i).pipe(C(r=>this.generateCaptionOfSpecificVideo({video:r,forceTranscription:!1})),b(),s(r=>r.reduce((e,o)=>(o==="success"&&(e.success+=1),o==="already-has-captions"&&(e.alreadyHasCaptions+=1),o==="already-being-transcribed"&&(e.alreadyBeingTranscribed+=1),e),{success:0,alreadyHasCaptions:0,alreadyBeingTranscribed:0})),c(r=>this.restExtractor.handleError(r)));}generateCaptionOfSpecificVideo(t){let{video:i,forceTranscription:r}=t,e={forceTranscription:r};return this.authHttp.post(`${f.BASE_VIDEO_URL}/${i.id}/captions/generate`,e).pipe(s(()=>"success"),c(o=>{let a=o.error;if(a?.code===l.VIDEO_ALREADY_BEING_TRANSCRIBED&&!r){let _="PeerTube \u8A8D\u70BA\u5F71\u7247\u300C"+i.name+"\u300D\u5DF2\u8F49\u9304\u3002"+"\u82E5\u60A8\u8A8D\u70BA PeerTube \u932F\u8AA4\uFF08\u7576\u6A5F\u5F8C\uFF0C\u5F71\u7247\u8655\u65BC\u640D\u6BC0\u72C0\u614B\u7B49\uFF09\uFF0C\u60A8\u53EF\u4EE5\u5F37\u5236\u8F49\u9304\u8A72\u5F71\u7247\u3002"+" Do you still want to run transcription?";return m(this.confirmService.confirm(_,"\u5F37\u5236\u8F49\u9304")).pipe(p(O=>O===!1?g(()=>o):this.generateCaptionOfSpecificVideo({video:i,forceTranscription:!0})));}return a?.code===l.VIDEO_ALREADY_HAS_CAPTIONS?u("already-has-captions"):a?.code===l.VIDEO_ALREADY_BEING_TRANSCRIBED?u("already-being-transcribed"):g(()=>o);}));}};h(n,"\u0275fac",function(i){return new(i||n)();}),h(n,"\u0275prov",S({token:n,factory:n.ɵfac}));let E=n;return E;})();export{F as a};/**i18n:6f27118bd781e1b187bee9d5d6ca55c8b3017949bcb9fb3e18a73e038f249d42*///# sourceMappingURL=chunk-UWZDJKPT.js.map