From 2744ea22442dca1575274d4f04aafe2d2f4b6446 Mon Sep 17 00:00:00 2001 From: syeopite Date: Sat, 21 Oct 2023 12:45:05 -0700 Subject: [PATCH] Use Time::Span for timestamps in chapter struct --- src/invidious/videos/chapters.cr | 12 ++++++------ .../views/components/description_chapters_widget.ecr | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/invidious/videos/chapters.cr b/src/invidious/videos/chapters.cr index 8482545a..24a50628 100644 --- a/src/invidious/videos/chapters.cr +++ b/src/invidious/videos/chapters.cr @@ -1,6 +1,6 @@ # Namespace for methods and objects relating to chapters module Invidious::Videos::Chapters - record Chapter, start_ms : Int32, end_ms : Int32, title : String, thumbnails : Array(Hash(String, Int32 | String)) + record Chapter, start_ms : Time::Span, end_ms : Time::Span, title : String, thumbnails : Array(Hash(String, Int32 | String)) # Parse raw chapters data into an array of Chapter structs # @@ -37,8 +37,8 @@ module Invidious::Videos::Chapters end segments << Chapter.new( - start_ms: start_ms, - end_ms: end_ms, + start_ms: start_ms.milliseconds, + end_ms: end_ms.milliseconds, title: title, thumbnails: thumbnails, ) @@ -51,7 +51,7 @@ module Invidious::Videos::Chapters def self.chapters_to_vtt(chapters : Array(Chapter)) vtt = WebVTT.build do |build| chapters.each do |chapter| - build.cue(chapter.start_ms.milliseconds, chapter.end_ms.milliseconds, chapter.title) + build.cue(chapter.start_ms, chapter.end_ms, chapter.title) end end end @@ -63,8 +63,8 @@ module Invidious::Videos::Chapters chapters.each do |chapter| json.object do json.field "title", chapter.title - json.field "startMs", chapter.start_ms - json.field "endMs", chapter.end_ms + json.field "startMs", chapter.start_ms.total_milliseconds + json.field "endMs", chapter.end_ms.total_milliseconds json.field "thumbnails" do json.array do diff --git a/src/invidious/views/components/description_chapters_widget.ecr b/src/invidious/views/components/description_chapters_widget.ecr index 2f7217de..daf37ed0 100644 --- a/src/invidious/views/components/description_chapters_widget.ecr +++ b/src/invidious/views/components/description_chapters_widget.ecr @@ -9,7 +9,7 @@
<% chapters.each do | chapter | %> - <%- start_in_seconds = chapter.start_ms.milliseconds.total_seconds.to_i %> + <%- start_in_seconds = chapter.start_ms.total_seconds.to_i %>