diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index d3049f35..5fa8514b 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -740,6 +740,21 @@ Ox.formatRoman = function(number) { return string; }; +/*@ +Ox.formatSRT Formats subtitles as SRT +@*/ +Ox.formatSRT = function(subtitles) { + return Ox.sortBy(subtitles, ['in', 'out']).map(function(subtitle, index) { + return [ + index + 1, + ['in', 'out'].map(function(key) { + return Ox.formatDuration(subtitle[key]).replace('.', ','); + }).join(' --> '), + subtitle['text'] + ].join('\n') + }).join('\n\n'); +}; + /*@ Ox.formatString Basic string formatting > Ox.formatString('{0}{1}', ['foo', 'bar'])