import{b as V,c as f}from"./chunk-QU25C3ZM.js";import{C as c,D as b,E as C,Fd as l,Fe as A,Qf as D,S as p,Yc as v,Z as S,ba as d,ce as y,dg as T,i as m,j as u,k as g,lg as I,n as s,vg as $}from"./chunk-OX24XL2F.js";import{i as h}from"./chunk-FQ4ILEWG.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 \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043E \u0432\u0438\u0434\u0435\u043E \""+i.name+"\" \u0443\u0436\u0435 \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043E\u0432\u044B\u0432\u0430\u0435\u0442\u0441\u044F."+"\u0415\u0441\u043B\u0438 \u0432\u044B \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0447\u0442\u043E PeerTube \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u043D\u0435\u043F\u0440\u0430\u0432\u0438\u043B\u044C\u043D\u043E (\u0432\u0438\u0434\u0435\u043E \u043D\u0435 \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u043F\u043E\u0441\u043B\u0435 \u0441\u0431\u043E\u044F \u0438 \u0442.\u0434.), \u0432\u044B \u043C\u043E\u0436\u0435\u0442\u0435 \u043F\u0440\u0438\u043D\u0443\u0434\u0438\u0442\u0435\u043B\u044C\u043D\u043E \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043E\u0432\u0430\u0442\u044C \u044D\u0442\u043E \u0432\u0438\u0434\u0435\u043E."+" Do you still want to run transcription?";return m(this.confirmService.confirm(_,"\u041F\u0440\u0438\u043D\u0443\u0434\u0438\u0442\u0435\u043B\u044C\u043D\u0430\u044F \u0442\u0440\u0430\u043D\u0441\u043A\u0440\u0438\u043F\u0446\u0438\u044F")).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:93ef1b86561141301263c1f349fa8abb749523958c3a6dfaf46ed36d22b0a506*///# sourceMappingURL=chunk-CKX3O2YX.js.map