import{Bc as zn,Gi as ar,H as Dm,Ko as mM,Ln as Or,Nn as OTe,Oi as Zt,Wa as g,Wt as Jn,_r as Se,fr as S,gt as G,ha as cf,no as hQ,ro as he,sn as M,v as Bc,y as Be}from"./chunk-B_pj7Jpm.js";import{r as b,t as H}from"./chunk-CagJEiiY.js";var O=class f{authHttp=g(zn);serverService=g(Zt);restExtractor=g(Jn);confirmService=g(Bc);listCaptions(t,i){let r=b.buildVideoPasswordHeader(i);return this.authHttp.get(`${H.BASE_VIDEO_URL}/${t}/captions`,{headers:r}).pipe(Be(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=>(mM(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=hQ({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(Be(()=>this.addCaption(t,e.language.id,e.captionfile))):e.action===`REMOVE`&&(r=r.pipe(Be(()=>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(ar(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===OTe.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(Be(_=>_===!1?Or(()=>a):this.generateCaptionOfSpecificVideo({video:i,forceTranscription:!0})))}return o?.code===OTe.VIDEO_ALREADY_HAS_CAPTIONS?M(`already-has-captions`):o?.code===OTe.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=6ff200a7-83ab-5441-b6d1-b29c34bec990
//# sourceMappingURL=chunk-CX0pAEF-.js.map