aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2015-05-12 13:04:54 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2015-05-12 13:04:54 +0800
commitc1c924abfeda45f29b991bb74f315f0e79dcf126 (patch)
treef29b6ae2baa7db6397a429c530a81c9ff744fd0f /youtube_dl/utils.py
parent1c7e2e64f6328024711d5fa999d4498396f4cb5c (diff)
downloadyoutube-dl-c1c924abfeda45f29b991bb74f315f0e79dcf126.tar.xz
[utils,common] Merge format_srt_time and _subtitles_timecode
format_srt_time uses a comma as the delimiter between seconds and milliseconds while _subtitles_timecode uses a dot. All .srt examples I found on the Internet uses a comma, so I use a comma in the merged version. See http://matroska.org/technical/specs/subtitles/srt.html and http://devel.aegisub.org/wiki/SubtitleFormats/SRT
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 5439fcb35..ed9ed9ed6 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1835,12 +1835,8 @@ def parse_dfxp_time_expr(time_expr):
return 3600 * int(mobj.group(1)) + 60 * int(mobj.group(2)) + float(mobj.group(3))
-def format_srt_time(seconds):
- (mins, secs) = divmod(seconds, 60)
- (hours, mins) = divmod(mins, 60)
- millisecs = (secs - int(secs)) * 1000
- secs = int(secs)
- return '%02d:%02d:%02d,%03d' % (hours, mins, secs, millisecs)
+def srt_subtitles_timecode(seconds):
+ return '%02d:%02d:%02d,%03d' % (seconds / 3600, (seconds % 3600) / 60, seconds % 60, (seconds % 1) * 1000)
def dfxp2srt(dfxp_data):
@@ -1872,8 +1868,8 @@ def dfxp2srt(dfxp_data):
end_time = begin_time + parse_dfxp_time_expr(para.attrib['dur'])
out.append('%d\n%s --> %s\n%s\n\n' % (
index,
- format_srt_time(begin_time),
- format_srt_time(end_time),
+ srt_subtitles_timecode(begin_time),
+ srt_subtitles_timecode(end_time),
parse_node(para)))
return ''.join(out)