import{b as V,c as f}from"./chunk-NJ5QGAXC.js";import{C as c,Cf as D,D as v,E as S,Oc as C,Rf as T,S as p,Ud as y,Z as b,Zf as I,aa as d,hg as $,i as m,j as u,k as g,n as s,ue as A,vd as l}from"./chunk-4JM6MIZ5.js";import{i as E}from"./chunk-QJQRWPYR.js";var k=(()=>{let n=class n{authHttp;serverService;restExtractor;confirmService;constructor(t,i,r,e){this.authHttp=t,this.serverService=i,this.restExtractor=r,this.confirmService=e;}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(S(r=>this.generateCaptionOfSpecificVideo({video:r,forceTranscription:!1})),v(),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 considera que o v\xEDdeo \""+i.name+"\" xa est\xE1 a ser transcrito."+"Se cres que PeerTube est\xE1 errado (v\xEDdeo estragado despois de fallar etc.), podes forzar a transcrici\xF3n de este v\xEDdeo."+" Do you still want to run transcription?";return m(this.confirmService.confirm(_,"Forzar transcrici\xF3n")).pipe(p(H=>H===!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);}));}};E(n,"\u0275fac",function(i){return new(i||n)(d(C),d($),d(T),d(I));}),E(n,"\u0275prov",b({token:n,factory:n.ɵfac}));let h=n;return h;})();export{k as a};/**i18n:68865f44f2a527c44cf5136a17c76a0ff8308c2bae5c7c8d50070a5fb9847c44*///# sourceMappingURL=chunk-YULFPS54.js.map