Skip to content

Commit

Permalink
Hotfix/youtube (#12)
Browse files Browse the repository at this point in the history
* Fix deserialization of TextBlock

* Fix wrong duration calculation
  • Loading branch information
DRSchlaubi authored Oct 29, 2023
1 parent 8e9ec8c commit a15cbd8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ data class MacroMarkersListItemRenderer(
)

@Serializable
data class TextBlock(val simpleText: String) {
override fun toString(): String = simpleText
data class TextBlock(val runs: List<Run> = emptyList()) {
@Serializable
data class Run(val text: String, val bold: Boolean = false)

fun joinRuns() = runs.joinToString("", transform = Run::text)

override fun toString(): String = joinRuns()
}

Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ fun HttpInterface.requestVideoChaptersById(id: String, trackLength: Long): List<
val all = content.horizontalCardListRenderer.cards
return (all.zipWithNext() + (all.last() to null)).map { (now, next) ->
val renderer = now.macroMarkersListItemRenderer
val start = renderer.timeDescription.simpleText.parseDuration()
val end = next?.macroMarkersListItemRenderer?.timeDescription?.simpleText?.parseDuration() ?: trackLength.toDuration(DurationUnit.MILLISECONDS)
val start = renderer.timeDescription.joinRuns().parseDuration()
val end = next?.macroMarkersListItemRenderer?.timeDescription?.joinRuns()?.parseDuration() ?: trackLength.toDuration(DurationUnit.MILLISECONDS)

Chapter(
renderer.title.simpleText,
renderer.title.joinRuns(),
start.inWholeMilliseconds,
end.inWholeMilliseconds,
start + end
end - start
)
}
}
Expand Down

0 comments on commit a15cbd8

Please sign in to comment.