Skip to content

Commit

Permalink
Fix ttml number format and remove spaces at the end or start of line
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Jun 26, 2023
1 parent f92309f commit 90dda54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Code/Converters/TtmlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ public static function ttmlTimeToInternal($ttml_time, $frame_rate = null)

protected static function internalTimeToTtml($internal_time)
{
return round($internal_time, 3);
$formatted_output = round($internal_time, 3);

if (strpos($formatted_output, '.') === false) {
$formatted_output .= ".0"; // Add at least one digit after decimal if there are no digits
}

return $formatted_output;
}

protected static function framesPerSecond($dom)
Expand Down
10 changes: 9 additions & 1 deletion src/Subtitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,15 @@ public static function loadFromString($text, $format = null)
} else {
$input_converter = Helpers::getConverterByFileContent($converter->input);
}
$converter->internal_format = $input_converter->fileContentToInternalFormat($converter->input);
$internal_format = $input_converter->fileContentToInternalFormat($converter->input);
foreach ($internal_format as &$row) {
foreach ($row['lines'] as &$line) {
$line = trim($line);
}
}
unset($row);
unset($line);
$converter->internal_format = $internal_format;

return $converter;
}
Expand Down

0 comments on commit 90dda54

Please sign in to comment.