Skip to content

Instantly share code, notes, and snippets.

@jmcclow
Created November 25, 2012 00:12
Show Gist options
  • Save jmcclow/4141897 to your computer and use it in GitHub Desktop.
Save jmcclow/4141897 to your computer and use it in GitHub Desktop.
Convert pidgin conversation to subtitle track
#!/usr/bin/python
from datetime import datetime
import time
import re
def repl(string):
substring = re.findall('(\d{2}:\d{2}:\d{2})', string)
for i in substring:
blah = i.split(':')
dt_obj = datetime(2012, 11, 23, int(blah[0]), int(blah[1]), int(blah[2]))
epoch_date = int(dt_obj.strftime("%s")) - 24867
begin = time.strftime("%H:%M:%S,000", time.localtime(epoch_date))
end = time.strftime("%H:%M:%S,000", time.localtime(epoch_date + 10))
stamp = begin + " --> " + end + "\n"
return stamp
#-------------------------------------------------
# conversions to strings
#-------------------------------------------------
# datetime object to string
inf = open('Subtitles.txt')
subtitle_num = 1
for line in inf:
print subtitle_num
print re.sub('\((\d{2}:\d{2}:\d{2})\)', repl(line), line)
subtitle_num += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment