import{A as Bc,An as M,Fa as er,Hi as Zt,Ja as g,Lr as Se,Mr as S,St as G,To as je,_c as wQ,a as $Te,at as Dm,dt as EM,pi as Wn,ro as he,sr as Or,va as cf,xa as cr}from"./chunk-b0nJCs5_.js";import{r as b,t as H}from"./chunk-CswnO8Ym.js";var O=class f{authHttp=g(Wn);serverService=g(Zt);restExtractor=g(er);confirmService=g(Bc);listCaptions(t,i){let r=b.buildVideoPasswordHeader(i);return this.authHttp.get(`${H.BASE_VIDEO_URL}/${t}/captions`,{headers:r}).pipe(je(e=>this.serverService.getServerLocale().pipe(G(a=>({captionsResult:e,translations:a})))),G(({captionsResult:e,translations:a})=>{for(let o of e.data)o.language.label=Dm(o.language.label,a);return e}),G(e=>(EM(e.data,`language`,`label`),e))).pipe(he(e=>this.restExtractor.handleError(e)))}removeCaption(t,i){return this.authHttp.delete(`${H.BASE_VIDEO_URL}/${t}/captions/${i}`).pipe(he(r=>this.restExtractor.handleError(r)))}addCaption(t,i,r){let a=wQ({captionfile:r});return this.authHttp.put(`${H.BASE_VIDEO_URL}/${t}/captions/${i}`,a).pipe(he(o=>this.restExtractor.handleError(o)))}updateCaptions(t,i){let r=M(void 0);for(let e of i)e.action===`CREATE`||e.action===`UPDATE`?r=r.pipe(je(()=>this.addCaption(t,e.language.id,e.captionfile))):e.action===`REMOVE`&&(r=r.pipe(je(()=>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 Se(i).pipe(cr(r=>this.generateCaptionOfSpecificVideo({video:r,forceTranscription:!1})),cf(),G(r=>r.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})),he(r=>this.restExtractor.handleError(r)))}generateCaptionOfSpecificVideo(t){let{video:i,forceTranscription:r}=t,e={forceTranscription:r};return this.authHttp.post(`${H.BASE_VIDEO_URL}/${i.id}/captions/generate`,e).pipe(G(()=>`success`),he(a=>{let o=a.error;if(o?.code===$Te.VIDEO_ALREADY_BEING_TRANSCRIBED&&!r){let R=`PeerTube indikerar att videon "${i.name}" redan har transkriberats.`+"Om du tycker att PeerTube är fel ute (video i trasigt tillstånd efter en krasch etcetera) kan du tvinga omtranskribering av den här videon."+` Do you still want to run transcription?`;return Se(this.confirmService.confirm(R,"Tvinga omtranskribering")).pipe(je(_=>_===!1?Or(()=>a):this.generateCaptionOfSpecificVideo({video:i,forceTranscription:!0})))}return o?.code===$Te.VIDEO_ALREADY_HAS_CAPTIONS?M(`already-has-captions`):o?.code===$Te.VIDEO_ALREADY_BEING_TRANSCRIBED?M(`already-being-transcribed`):Or(()=>a)}))}static ɵfac=function(i){return new(i||f)};static ɵprov=S({token:f,factory:f.ɵfac})};export{O as t};
//# debugId=8b852bd9-e9eb-5c50-8c95-ec2d9f6f99a9
//# sourceMappingURL=chunk-BdDU3qnh.js.map