From eaec5cea23a56b930689211c619191858d65caf4 Mon Sep 17 00:00:00 2001 From: Daniel Kao Date: Mon, 18 Nov 2024 00:43:18 +0800 Subject: [PATCH] feat: even if there's no second caption language setup, einkbro can still save current caption in youtube as epub --- .../plateaukao/einkbro/caption/DualCaptionProcessor.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/plateaukao/einkbro/caption/DualCaptionProcessor.kt b/app/src/main/java/info/plateaukao/einkbro/caption/DualCaptionProcessor.kt index 926bcd53..fb0972cd 100644 --- a/app/src/main/java/info/plateaukao/einkbro/caption/DualCaptionProcessor.kt +++ b/app/src/main/java/info/plateaukao/einkbro/caption/DualCaptionProcessor.kt @@ -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() @@ -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}" @@ -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 }