diff --git a/src/invidious/videos/chapters.cr b/src/invidious/videos/chapters.cr index c51de450..8482545a 100644 --- a/src/invidious/videos/chapters.cr +++ b/src/invidious/videos/chapters.cr @@ -49,37 +49,9 @@ module Invidious::Videos::Chapters # Converts an array of Chapter objects to a webvtt file def self.chapters_to_vtt(chapters : Array(Chapter)) - vtt = String.build do |vtt| - vtt << <<-END_VTT - WEBVTT - - - END_VTT - - # Taken from Invidious::Videos::Caption.timedtext_to_vtt() + vtt = WebVTT.build do |build| chapters.each do |chapter| - start_time = chapter.start_ms.milliseconds - end_time = chapter.end_ms.milliseconds - - # start_time - vtt << start_time.hours.to_s.rjust(2, '0') - vtt << ':' << start_time.minutes.to_s.rjust(2, '0') - vtt << ':' << start_time.seconds.to_s.rjust(2, '0') - vtt << '.' << start_time.milliseconds.to_s.rjust(3, '0') - - vtt << " --> " - - # end_time - vtt << end_time.hours.to_s.rjust(2, '0') - vtt << ':' << end_time.minutes.to_s.rjust(2, '0') - vtt << ':' << end_time.seconds.to_s.rjust(2, '0') - vtt << '.' << end_time.milliseconds.to_s.rjust(3, '0') - - vtt << "\n" - vtt << chapter.title - - vtt << "\n" - vtt << "\n" + build.cue(chapter.start_ms.milliseconds, chapter.end_ms.milliseconds, chapter.title) end end end