Skip to content

Commit

Permalink
Use YouTube timestamps in chapters summary
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Oct 12, 2024
1 parent c19564c commit b791d16
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions markut.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,35 @@ import (
"sort"
)

func millisToTs(millis Millis) string {
sign := ""
func decomposeMillis(millis Millis) (hh int64, mm int64, ss int64, ms int64, sign string) {
sign = ""
if millis < 0 {
sign = "-"
millis = -millis
}
hh := millis / 1000 / 60 / 60
mm := millis / 1000 / 60 % 60
ss := millis / 1000 % 60
ms := millis % 1000
hh = int64(millis / 1000 / 60 / 60)
mm = int64(millis / 1000 / 60 % 60)
ss = int64(millis / 1000 % 60)
ms = int64(millis % 1000)
return
}

// Timestamp format used by Markut Language
func millisToTs(millis Millis) string {
hh, mm, ss, ms, sign := decomposeMillis(millis)
return fmt.Sprintf("%s%02d:%02d:%02d.%03d", sign, hh, mm, ss, ms)
}

// Timestamp format used on YouTube
func millisToYouTubeTs(millis Millis) string {
hh, mm, ss, _, sign := decomposeMillis(millis)
return fmt.Sprintf("%s%02d:%02d:%02d", sign, hh, mm, ss)
}

// Timestamp format used by SubRip https://en.wikipedia.org/wiki/SubRip that we
// use for generating the chat in subtitles on YouTube
func millisToSubRipTs(millis Millis) string {
sign := ""
if millis < 0 {
sign = "-"
millis = -millis
}
hh := millis / 1000 / 60 / 60
mm := millis / 1000 / 60 % 60
ss := millis / 1000 % 60
ms := millis % 1000
hh, mm, ss, ms, sign := decomposeMillis(millis)
return fmt.Sprintf("%s%02d:%02d:%02d,%03d", sign, hh, mm, ss, ms)
}

Expand Down Expand Up @@ -210,7 +216,7 @@ func (context EvalContext) PrintSummary() {
fmt.Println()
fmt.Printf(">>> Chapters (%d):\n", len(context.chapters))
for _, chapter := range context.chapters {
fmt.Printf("- %s - %s\n", millisToTs(chapter.Timestamp), chapter.Label)
fmt.Printf("- %s - %s\n", millisToYouTubeTs(chapter.Timestamp), chapter.Label)
}
fmt.Println()
fmt.Printf(">>> Length:\n")
Expand Down

0 comments on commit b791d16

Please sign in to comment.