Skip to content

Commit

Permalink
Fix chapter splitting issue in timestamps.js if parts after splitting…
Browse files Browse the repository at this point in the history
… are too short
  • Loading branch information
woolfg committed Apr 23, 2024
1 parent 6706aba commit 28e55f1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions chapters/timestamps.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ function injectAd(adStartTime, adEndTime, adText, timestamps) {
timestamps.splice(adStartIndex, 0, [adStartTime, " " + adText])
// copy the topic before the ad to the end to specify the ongoing topic again
timestamps.splice(adStartIndex + 1, 0, [adEndTime, timestamps[adStartIndex - 1][1]])

// due to the splitting of the topic, one part might be too short
// make sure that the chapter before and after the ad have at least 5 seconds, otherwise delete it
const minChapterDuration = 5
if (timestamps[adStartIndex - 1][0] + minChapterDuration > adStartTime) {
timestamps.splice(adStartIndex - 1, 1)
}
if (timestamps[adStartIndex + 1][0] - minChapterDuration < adEndTime) {
timestamps.splice(adStartIndex + 2, 1)
}

}
return timestamps
}
Expand Down

0 comments on commit 28e55f1

Please sign in to comment.