Use WebVTT.build for chapters vtt file

This commit is contained in:
syeopite 2023-10-21 12:21:23 -07:00
parent 310825997f
commit b0e0e19017
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A

View File

@ -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