From 31ed9e9bf1fb1025aa3bea5ff8f16a78bc53ab7d Mon Sep 17 00:00:00 2001 From: firelight <147925818+fire-light42@users.noreply.github.com> Date: Sun, 27 Apr 2025 21:28:52 +0200 Subject: [PATCH] Fixed caption regex --- .../cloudstream3/ui/player/CustomSubtitleDecoderFactory.kt | 5 ----- .../cloudstream3/ui/subtitles/SubtitlesFragment.kt | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CustomSubtitleDecoderFactory.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CustomSubtitleDecoderFactory.kt index 1e5483f0b..20127295c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CustomSubtitleDecoderFactory.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CustomSubtitleDecoderFactory.kt @@ -89,7 +89,6 @@ class CustomDecoder(private val fallbackFormat: Format?) : SubtitleParser { RegexOption.IGNORE_CASE ), ) - val captionRegex = listOf(Regex("""(-\s?|)[\[({][\w\s]*?[])}]\s*""")) //https://emptycharacter.com/ //https://www.fileformat.info/info/unicode/char/200b/index.htm @@ -279,10 +278,6 @@ class CustomDecoder(private val fallbackFormat: Format?) : SubtitleParser { ) realDecoder?.let { decoder -> if (decoder !is SsaParser) { - if (currentStyle.removeCaptions) - captionRegex.forEach { rgx -> - str = str.replace(rgx, "\n") - } if (currentStyle.removeBloat) bloatRegex.forEach { rgx -> str = str.replace(rgx, "\n") diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt index 22958f3a8..84bba1d56 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt @@ -88,6 +88,7 @@ const val DEF_SUBS_ELEVATION = 20 class SubtitlesFragment : DialogFragment() { companion object { val applyStyleEvent = Event() + private val captionRegex = Regex("""(-\s?|)[\[({][\S\s]*?[])}]\s*""") fun setSubtitleViewStyle(view: SubtitleView?, data: SaveCaptionStyle) { if (view == null) return @@ -179,6 +180,12 @@ class SubtitlesFragment : DialogFragment() { setText(customSpan) } + // 5. remove captions + text?.let { text -> + if (style.removeCaptions) { + setText(text.replace(captionRegex, "")) + } + } return this }