Skip to content

Commit

Permalink
Merge pull request #2 from LunaTA001/LunaTA001-patch-1
Browse files Browse the repository at this point in the history
Update SrtWriter.hx
  • Loading branch information
Devyatyi9 authored Jul 8, 2023
2 parents e90c433 + d7c4f61 commit a69ede3
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/srt/SrtWriter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,58 @@ class SrtWriter {
while (it < usm.length) {
if (usm[it].isSbt == true) {
o.writeString((it + 1) + '\r\n'); // number

var startTime = Std.string(usm[it].startTime);
var padStartTime = startTime.lpad('0', 9);
var padstartTime = startTime.lpad('0', 9);
var startTimeInt = (usm[it].startTime); // creates an Int copy of the duration.

if(startTimeInt >= 100000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 200000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 300000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 400000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 500000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 600000) startTimeInt = (startTimeInt + 40000); // adds an additional 40 seconds every 100 seconds because a start time of 100 gets written as 1:00 in the srt file which is 60 seconds.
if(startTimeInt >= 700000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 800000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 900000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 1000000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 1100000) startTimeInt = (startTimeInt + 40000);
if(startTimeInt >= 1200000) startTimeInt = (startTimeInt + 40000);

var startTimeString = Std.string(startTimeInt); // converts the int to a string
var padStartTime = startTimeString.lpad('0', 9); // creates the array of endTimeString
o.writeString(padStartTime.substring(0, 2) + ':' + padStartTime.substring(2, 4) + ':' + padStartTime.substring(4, 6) + ','
+ padStartTime.substring(6, 9));
o.writeString(' --> ');

o.writeString(' --> ');

var endTime = Std.string(usm[it].endTime);
var padEndTime = endTime.lpad('0', 9);

var endTimeInt = (usm[it].endTime); // creates an Int copy of the duration.
var endTime; // Leaves endTime empty for now.
endTimeInt = (endTimeInt + startTimeInt); // adds the start time and the duration to get the new end time

if (startTimeInt < 100000 && endTimeInt >= 100000 ) endTimeInt = (endTimeInt + 40000);
if (startTimeInt < 200000 && endTimeInt >= 200000 ) endTimeInt = (endTimeInt + 40000);
if (startTimeInt < 300000 && endTimeInt >= 300000 ) endTimeInt = (endTimeInt + 40000);
if (startTimeInt < 400000 && endTimeInt >= 400000 ) endTimeInt = (endTimeInt + 40000);
if (startTimeInt < 500000 && endTimeInt >= 500000 ) endTimeInt = (endTimeInt + 40000); // adds an offset for if the start time is like 99 seconds and the end time is over 100 seconds
if (startTimeInt < 600000 && endTimeInt >= 600000 ) endTimeInt = (endTimeInt + 40000); // enabling the end time to correctly be written in the .srt file
if (startTimeInt < 700000 && endTimeInt >= 700000 ) endTimeInt = (endTimeInt + 40000);
if (startTimeInt < 800000 && endTimeInt >= 800000 ) endTimeInt = (endTimeInt + 40000);
if (startTimeInt < 900000 && endTimeInt >= 900000 ) endTimeInt = (endTimeInt + 40000);
if (startTimeInt < 1000000 && endTimeInt >= 1000000 ) endTimeInt = (endTimeInt + 40000);
if (startTimeInt < 1100000 && endTimeInt >= 1100000 ) endTimeInt = (endTimeInt + 40000);
if (startTimeInt < 1200000 && endTimeInt >= 1200000 ) endTimeInt = (endTimeInt + 40000);

var endTimeString = Std.string(endTimeInt); // converts the int to a string
var padEndTime = endTimeString.lpad('0', 9); // creates the array of endTimeString

o.writeString(padEndTime.substring(0, 2) + ':' + padEndTime.substring(2, 4) + ':' + padEndTime.substring(4, 6) + ','
+ padEndTime.substring(6, 9));
o.writeString('\r\n');

var newText = usm[it].text.replace('\x00', '');
newText = usm[it].text.replace('\\n', '\n');
o.writeString(newText + '\r\n\r\n');
Expand Down

0 comments on commit a69ede3

Please sign in to comment.