UNPKG

cloudinary-video-player

Version:

Cloudinary Video Player

1 lines 2.07 kB
(self.cloudinaryVideoPlayerChunkLoading=self.cloudinaryVideoPlayerChunkLoading||[]).push([[6],{3565:(t,e,r)=>{r.d(e,{default:()=>d});const i=class{seperator=",";timestampToSeconds(t){const[e,r]=t.split(","),i=parseInt(r),[d,s,a]=e.split(":").map((t=>parseInt(t))),n=.001*i+a+60*s+3600*d;return Math.round(1e3*n)/1e3}correctFormat(t){let e=t.replace(".",",");var r,[i,d]=e.split(",");r=this.fixed_str_digit(3,d);var[s,a,n]=i.split(":");return`${this.fixed_str_digit(2,s,!1)}:${this.fixed_str_digit(2,a,!1)}:${this.fixed_str_digit(2,n,!1)},${r}`}fixed_str_digit(t,e,r=!0){return e.length==t?e:e.length>t?e.slice(0,t):e.length<t?r?e.padEnd(t,"0"):e.padStart(t,"0"):void 0}tryComma(t){let e=(t=t.replace(/\r/g,"")).split(/(\d+)\n(\d{1,2}:\d{2}:\d{2},\d{1,3}) --> (\d{1,2}:\d{2}:\d{2},\d{1,3})/g);return e.shift(),e}tryDot(t){let e=(t=t.replace(/\r/g,"")).split(/(\d+)\n(\d{1,2}:\d{2}:\d{2}\.\d{1,3}) --> (\d{1,2}:\d{2}:\d{2}\.\d{1,3})/g);return e.shift(),this.seperator=".",e}fromSrt(t){var e=t,r=this.tryComma(e);0==r.length&&(r=this.tryDot(e));for(var i=[],d=0;d<r.length;d+=4){const t=this.correctFormat(r[d+1].trim()),e=this.correctFormat(r[d+2].trim());var s={id:r[d].trim(),startTime:t,startSeconds:this.timestampToSeconds(t),endTime:e,endSeconds:this.timestampToSeconds(e),text:r[d+3].trim()};i.push(s)}return i}toSrt(t){var e="";const r="\r\n";for(var i=0;i<t.length;i++){var d=t[i];e+=d.id+r,e+=d.startTime+" --\x3e "+d.endTime+r,e+=d.text.replace("\n",r)+r+r}return e}},d=function(t,e){e.one("loadedmetadata",(()=>{(async()=>{let r;if(t.src)try{if(r=await fetch(t.src),!r.ok)throw new Error(`Failed fetching from ${t.src} with status code ${r.status}`)}catch(t){console.error(t)}if(!r.ok)return;const d=await r.text(),s=(n=d,(new i).fromSrt(n).map((t=>({startTime:t.startSeconds,endTime:t.endSeconds,text:t.text})))),a=e.addRemoteTextTrack({kind:t.kind||"subtitles",label:t.label||"Subtitles",srclang:t.srclang,default:t.default,mode:t.default?"showing":"disabled"});var n;s.forEach((t=>{t&&a.track.addCue(new VTTCue(t.startTime,t.endTime,t.text))}))})()}))}}}]);