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는 "${i.name}" 영상의 전사가 이미 진행 중인 것으로 간주합니다`+"PeerTube에 문제가 있다고 판단되는 경우(크래시 후 영상이 손상된 상태 등) 이 영상을 강제로 전사할 수 있습니다"+` Do you still want to run transcription?`;return Se(this.confirmService.confirm(R,"강제 전사")).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=6f235a33-185e-5791-bece-40cd77ac5986
//# sourceMappingURL=chunk-BdDU3qnh.js.map