cloudinary-video-player
Version:
Cloudinary Video Player
6 lines • 2.22 kB
JavaScript
/*!
* Cloudinary Video Player v3.2.1
* Built on 2025-08-12T18:53:41.891Z
* https://github.com/cloudinary/cloudinary-video-player
*/
;(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),[s,d,a]=e.split(":").map((t=>parseInt(t))),n=.001*i+a+60*d+3600*s;return Math.round(1e3*n)/1e3}correctFormat(t){let e=t.replace(".",",");var r,[i,s]=e.split(",");r=this.fixed_str_digit(3,s);var[d,a,n]=i.split(":");return`${this.fixed_str_digit(2,d,!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=[],s=0;s<r.length;s+=4){const t=this.correctFormat(r[s+1].trim()),e=this.correctFormat(r[s+2].trim());var d={id:r[s].trim(),startTime:t,startSeconds:this.timestampToSeconds(t),endTime:e,endSeconds:this.timestampToSeconds(e),text:r[s+3].trim()};i.push(d)}return i}toSrt(t){var e="";const r="\r\n";for(var i=0;i<t.length;i++){var s=t[i];e+=s.id+r,e+=s.startTime+" --\x3e "+s.endTime+r,e+=s.text.replace("\n",r)+r+r}return e}};const s=t=>(new i).fromSrt(t).map((t=>({startTime:t.startSeconds,endTime:t.endSeconds,text:t.text}))),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 i=await r.text(),d=s(i),a=e.addRemoteTextTrack({kind:t.kind||"subtitles",label:t.label||"Subtitles",srclang:t.srclang,default:t.default,mode:t.default?"showing":"disabled"});d.forEach((t=>{t&&a.track.addCue(new VTTCue(t.startTime,t.endTime,t.text))}))})()}))}}}]);