Skip to content

Commit

Permalink
feat: even if there's no second caption language setup, einkbro can s…
Browse files Browse the repository at this point in the history
…till save current caption in youtube as epub
  • Loading branch information
plateaukao committed Nov 17, 2024
1 parent 19d6620 commit eaec5ce
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.serialization.json.Json
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

class DualCaptionProcessor:KoinComponent {
class DualCaptionProcessor : KoinComponent {
private val config: ConfigManager by inject()
private val serializer = TimedText.serializer()

Expand All @@ -16,9 +16,10 @@ class DualCaptionProcessor:KoinComponent {
}

fun processUrl(url: String): String? {
if (config.dualCaptionLocale.isEmpty()) return null
if (!url.contains(urlWithCaption)) return null

if (config.dualCaptionLocale.isEmpty()) return runBlocking { String(BrowserUnit.getResourceFromUrl(url)) }


try {
val newUrl = "$url&tlang=${config.dualCaptionLocale}"
Expand All @@ -37,7 +38,7 @@ class DualCaptionProcessor:KoinComponent {
}

oldCaptionJson.events.forEach { event ->
if (event.segs != null && event.segs.size > 0) {
if (event.segs != null && event.segs.isNotEmpty()) {
val first = event.segs.first()
first.utf8 = event.segs.map { it.utf8 }.reduce { acc, s -> acc + s }

Expand Down

0 comments on commit eaec5ce

Please sign in to comment.