Skip to content

Commit

Permalink
Use Time::Span for timestamps in chapter struct
Browse files Browse the repository at this point in the history
  • Loading branch information
syeopite committed Jan 5, 2024
1 parent 27a0823 commit 443b4ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/invidious/videos/chapters.cr
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down Expand Up @@ -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,
)
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="description-chapters-content-container">
<% 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 %>
<a href="/watch?v=<%-= video.id %>&t=<%=start_in_seconds %>">
<div class="chapter" data-onclick="jump_to_time" data-jump-time="<%=start_in_seconds%>">
<div class="thumbnail">
Expand Down

0 comments on commit 443b4ce

Please sign in to comment.