From 80cab8e4bb582ed9ff354d709c3a14a5d3b6436e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 3 Aug 2007 09:56:02 +0000 Subject: [PATCH] deal with funny srt mosters --- oxdbarchive/subtitles.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/oxdbarchive/subtitles.py b/oxdbarchive/subtitles.py index f1e8d9d..4022064 100644 --- a/oxdbarchive/subtitles.py +++ b/oxdbarchive/subtitles.py @@ -31,10 +31,15 @@ def srt2dict(srt, encoding = "utf-8"): subtitle = subtitle.strip().split('\n') if len(subtitle) > 2: start_stop = subtitle[1].split(' --> ') - subtitle[0] =u"%s" % int(subtitle[0]) + start_stop[0] = start_stop[0].split(' ')[-1] + start_stop[1] = start_stop[1].split(' ')[-1] + if start_stop[0][-4] == '.': + start_stop[0][:-4] + ',' + start_stop[0][-3:] + start_stop[1][:-4] + ',' + start_stop[1][-3:] + subtitle[0] ="%s" % int(subtitle[0]) subdict[subtitle[0]] = { - 'start': start_stop[0].replace('.', ','), - 'stop': start_stop[1].replace('.', ','), + 'start': start_stop[0], + 'stop': start_stop[1], 'text': u'\n'.join(subtitle[2:]), } return subdict