From ceca50ae5912f86f03cad9ca2fb3a9ce0bc3c733 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Thu, 18 Sep 2014 16:42:19 +0200 Subject: [PATCH] add Ox.formatSRT --- source/Ox/js/Format.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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'])