mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-08 21:52:28 +05:30
Add method to convert chapters to vtt
This commit is contained in:
parent
98c6cee383
commit
39b0229835
@ -463,6 +463,10 @@ module Invidious::Routes::API::V1::Videos
|
||||
end
|
||||
|
||||
return response
|
||||
else
|
||||
env.response.content_type = "text/vtt; charset=UTF-8"
|
||||
|
||||
return Invidious::Videos::Chapters.chapters_to_vtt(chapters)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -46,4 +46,41 @@ module Invidious::Videos::Chapters
|
||||
|
||||
return segments
|
||||
end
|
||||
|
||||
# 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()
|
||||
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"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user