From c4d80675ae53b9ca322160ff4da50d271a466c31 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 2 Jan 2012 22:37:17 +0530 Subject: [PATCH] add srt.encode --- ox/srt.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ox/srt.py b/ox/srt.py index c43a966..e0260f2 100644 --- a/ox/srt.py +++ b/ox/srt.py @@ -80,3 +80,21 @@ def load(filename, offset=0): srt.append(_s) i += 1 return srt + +def encode(data): + ''' + encodes list of objects with in,out,value into srt + result is utf-8 encoded bytestring + ''' + srt = u'' + i = 1 + for s in data: + srt += '%d\r\n%s --> %s\r\n%s\r\n\r\n' % ( + i, + ox.formatDuration(s['in']*1000, years=False).replace('.', ','), + ox.formatDuration(s['out']*1000, years=False).replace('.', ','), + s['value'].replace('\n', '\r\n').strip() + ) + i += 1 + return srt.encode('utf-8') +