import{b as V,c as f}from"./chunk-7TPOLMSO.js";import{B as c,C as b,D as C,Fh as T,Mh as I,Q as p,Sh as $,Ud as l,Y as S,Yf as D,_e as A,aa as d,hd as v,i as m,j as u,k as g,n as s,ve as y}from"./chunk-R4Z6ZI3L.js";import{i as h}from"./chunk-P6NJDXIL.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 _="Po stronie PeerTube'a film pod tytu\u0142em \u201E"+i.name+"\u201D wydaje si\u0119 by\u0107 ju\u017C w trakcie transkrybowania."+"Je\u017Celi twierdzisz, \u017Ce PeerTube si\u0119 myli (film si\u0119 nie odtwarza po awarii itd.), mo\u017Cesz wymusi\u0107 wygenerowanie transkrypcji tego filmu."+" Do you still want to run transcription?";return m(this.confirmService.confirm(_,"Wymu\u015B stworzenie transkrypcji")).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:138e9aba5923606215625ab5641fbdc103d8a34cfe13ae910386f40f27aea675*///# sourceMappingURL=chunk-3DBNKHSQ.js.map