Skip to content

Commit

Permalink
Use WebVTT.build for chapters vtt file
Browse files Browse the repository at this point in the history
  • Loading branch information
syeopite committed Jan 5, 2024
1 parent f8b45b5 commit 27a0823
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions src/invidious/videos/chapters.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 27a0823

Please sign in to comment.