Skip to content

Commit

Permalink
Support decimal part in seconds in the subtitles
Browse files Browse the repository at this point in the history
  • Loading branch information
joedicastro committed Mar 19, 2013
1 parent fa54a9e commit fff16c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/TEDSubs.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ def get_sub(tt_id, tt_intro, sub):
def srt_time(tst):
"""Format Time from TED Subtitles format to SRT time Format."""
secs, mins, hours = ((tst / 1000) % 60), (tst / 60000), (tst / 3600000)
right_srt_time = "{0:02d}:{1:02d}:{2:02d},000".format(hours, mins,
secs)
right_srt_time = ("{0:02d}:{1:02d}:{2:02d},{3:3.0f}".
format(int(hours), int(mins), int(secs),
divmod(secs, 1)[1] * 1000))
return right_srt_time

srt_content = ''
Expand Down Expand Up @@ -178,7 +179,7 @@ def main():
(opts, args) = options().parse_args()

# regex expressions to search into the webpage
regex_intro = re.compile('introDuration%22%3A(\d+)%2C')
regex_intro = re.compile('introDuration%22%3A(\d+\.?\d+)%2C')
regex_id = re.compile('talkId%22%3A(\d+)%2C')
regex_url = re.compile('id="no-flash-video-download" href="(.+)"')
regex_vid = re.compile('http://.+\/(.*\.mp4)')
Expand All @@ -199,8 +200,8 @@ def main():
tedtalk_webpage).read()
if ttalk_webpage:
try:
ttalk_intro = ((int(regex_intro.findall(ttalk_webpage)[0]) + 1)
* 1000)
ttalk_intro = ((float(regex_intro.findall(ttalk_webpage)[0])
+ 1) * 1000)
ttalk_id = int(regex_id.findall(ttalk_webpage)[0])
ttalk_url = regex_url.findall(ttalk_webpage)[0]
ttalk_url = ttalk_url.replace('.mp4', '-480p.mp4')
Expand Down
9 changes: 5 additions & 4 deletions src/TEDTalks.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ def get_sub(tt_id, tt_intro, sub):
def srt_time(tst):
"""Format Time from TED Subtitles format to SRT time Format."""
secs, mins, hours = ((tst / 1000) % 60), (tst / 60000), (tst / 3600000)
right_srt_time = "{0:02d}:{1:02d}:{2:02d},000".format(hours, mins,
secs)
right_srt_time = ("{0:02d}:{1:02d}:{2:02d},{3:3.0f}".
format(int(hours), int(mins), int(secs),
divmod(secs, 1)[1] * 1000))
return right_srt_time

srt_content = ''
Expand Down Expand Up @@ -397,8 +398,8 @@ def check_subs(ttalk, v_name):
stdout=PIPE).stdout.read()
else:
tt_webpage = urllib2.urlopen(ttalk.feedburner_origlink).read()
regex = re.compile('introDuration%22%3A(\d+)%2C')
tt_intro = (int(regex.findall(tt_webpage)[0]) + 1) * 1000
regex = re.compile('introDuration%22%3A(\d+\.?\d+)%2C')
tt_intro = (float(regex.findall(tt_webpage)[0]) + 1) * 1000
subtitle, get_log = get_sub(ttalk.id.split(':')[-1], tt_intro, sub)
s_log += get_log
if subtitle:
Expand Down

0 comments on commit fff16c3

Please sign in to comment.