From 4cc2cf46aa94f8895fd1287d01614f7ed07348b5 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 29 Jul 2018 10:47:22 -0500 Subject: [PATCH] Add fix for subtitles without duration --- src/invidious.cr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/invidious.cr b/src/invidious.cr index 1c80022d..b1a59dcb 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -485,7 +485,9 @@ get "/api/v1/captions/:id" do |env| track_xml.xpath_nodes("//transcript/text").each do |node| start_time = node["start"].to_f.seconds - end_time = start_time + node["dur"].to_f.seconds + duration = node["dur"]?.try &.to_f.seconds + duration ||= start_time + end_time = start_time + duration start_time = "#{start_time.hours.to_s.rjust(2, '0')}:#{start_time.minutes.to_s.rjust(2, '0')}:#{start_time.seconds.to_s.rjust(2, '0')}.#{start_time.milliseconds.to_s.rjust(3, '0')}" end_time = "#{end_time.hours.to_s.rjust(2, '0')}:#{end_time.minutes.to_s.rjust(2, '0')}:#{end_time.seconds.to_s.rjust(2, '0')}.#{end_time.milliseconds.to_s.rjust(3, '0')}"