forked from mirror/invidious
Use WebVTT.build for chapters vtt file
This commit is contained in:
parent
e638469352
commit
0bc058400d
1 changed files with 2 additions and 30 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue