Fixed caption regex

This commit is contained in:
firelight
2025-04-27 21:28:52 +02:00
committed by GitHub
parent 3455a25469
commit 31ed9e9bf1
2 changed files with 7 additions and 5 deletions

View File

@ -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")

View File

@ -88,6 +88,7 @@ const val DEF_SUBS_ELEVATION = 20
class SubtitlesFragment : DialogFragment() {
companion object {
val applyStyleEvent = Event<SaveCaptionStyle>()
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
}