forked from recloudstream/cloudstream
remove bloat and cc from subtitles
This commit is contained in:
parent
b7b5c54c72
commit
3656c7ee11
5 changed files with 197 additions and 148 deletions
|
@ -38,6 +38,7 @@ class CustomDecoder : SubtitleDecoder {
|
|||
private const val TAG = "CustomDecoder"
|
||||
private var overrideEncoding: String? = null
|
||||
var regexSubtitlesToRemoveCaptions = false
|
||||
var regexSubtitlesToRemoveBloat = false
|
||||
val bloatRegex =
|
||||
listOf(
|
||||
Regex(
|
||||
|
@ -151,10 +152,12 @@ class CustomDecoder : SubtitleDecoder {
|
|||
)
|
||||
realDecoder?.let { decoder ->
|
||||
decoder.dequeueInputBuffer()?.let { buff ->
|
||||
if (regexSubtitlesToRemoveCaptions && decoder::class.java != SsaDecoder::class.java) {
|
||||
if (decoder::class.java != SsaDecoder::class.java) {
|
||||
if (regexSubtitlesToRemoveCaptions)
|
||||
captionRegex.forEach { rgx ->
|
||||
str = str.replace(rgx, "\n")
|
||||
}
|
||||
if (regexSubtitlesToRemoveBloat)
|
||||
bloatRegex.forEach { rgx ->
|
||||
str = str.replace(rgx, "\n")
|
||||
}
|
||||
|
@ -177,10 +180,12 @@ class CustomDecoder : SubtitleDecoder {
|
|||
|
||||
if (!inputString.isNullOrBlank()) {
|
||||
var str: String = inputString
|
||||
if (regexSubtitlesToRemoveCaptions && realDecoder!!::class.java != SsaDecoder::class.java) {
|
||||
if (realDecoder!!::class.java != SsaDecoder::class.java) {
|
||||
if (regexSubtitlesToRemoveCaptions)
|
||||
captionRegex.forEach { rgx ->
|
||||
str = str.replace(rgx, "\n")
|
||||
}
|
||||
if (regexSubtitlesToRemoveBloat)
|
||||
bloatRegex.forEach { rgx ->
|
||||
str = str.replace(rgx, "\n")
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import com.google.android.exoplayer2.ui.SubtitleView
|
|||
import com.google.android.exoplayer2.util.MimeTypes
|
||||
import com.hippo.unifile.UniFile
|
||||
import com.lagradost.cloudstream3.SubtitleFile
|
||||
import com.lagradost.cloudstream3.ui.player.CustomDecoder.Companion.regexSubtitlesToRemoveBloat
|
||||
import com.lagradost.cloudstream3.ui.player.CustomDecoder.Companion.regexSubtitlesToRemoveCaptions
|
||||
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
|
||||
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.fromSaveToStyle
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
||||
|
@ -109,6 +111,8 @@ class PlayerSubtitleHelper {
|
|||
}
|
||||
|
||||
fun setSubStyle(style: SaveCaptionStyle) {
|
||||
regexSubtitlesToRemoveBloat = style.removeBloat
|
||||
regexSubtitlesToRemoveCaptions = style.removeCaptions
|
||||
subtitleView?.context?.let { ctx ->
|
||||
subStyle = style
|
||||
subtitleView?.setStyle(ctx.fromSaveToStyle(style))
|
||||
|
|
|
@ -57,6 +57,8 @@ data class SaveCaptionStyle(
|
|||
@JsonProperty("elevation") var elevation: Int,
|
||||
/**in sp**/
|
||||
@JsonProperty("fixedTextSize") var fixedTextSize: Float?,
|
||||
@JsonProperty("removeCaptions") var removeCaptions: Boolean = false,
|
||||
@JsonProperty("removeBloat") var removeBloat: Boolean = true,
|
||||
)
|
||||
|
||||
const val DEF_SUBS_ELEVATION = 20
|
||||
|
@ -397,6 +399,15 @@ class SubtitlesFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
subtitles_remove_bloat?.isChecked = state.removeBloat
|
||||
subtitles_remove_bloat?.setOnCheckedChangeListener { _, b ->
|
||||
state.removeBloat = b
|
||||
}
|
||||
subtitles_remove_captions?.isChecked = state.removeCaptions
|
||||
subtitles_remove_captions?.setOnCheckedChangeListener { _, b ->
|
||||
state.removeCaptions = b
|
||||
}
|
||||
|
||||
subs_font_size.setOnLongClickListener { _ ->
|
||||
state.fixedTextSize = null
|
||||
//textView.context.updateState() // font size not changed
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/subs_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -139,9 +140,35 @@
|
|||
android:nextFocusRight="@id/cancel_btt"
|
||||
|
||||
android:nextFocusUp="@id/subs_auto_select_language"
|
||||
android:nextFocusDown="@id/apply_btt"
|
||||
android:nextFocusDown="@id/subtitles_remove_bloat"
|
||||
android:text="@string/subs_download_languages" />
|
||||
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:nextFocusUp="@id/subs_download_languages"
|
||||
android:nextFocusDown="@id/subtitles_remove_captions"
|
||||
android:nextFocusLeft="@id/apply_btt"
|
||||
android:nextFocusRight="@id/cancel_btt"
|
||||
android:fontFamily="@font/google_sans"
|
||||
style="@style/SettingsItem"
|
||||
app:drawableEndCompat="@null"
|
||||
android:id="@+id/subtitles_remove_bloat"
|
||||
android:text="@string/subtitles_remove_bloat"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:nextFocusUp="@id/subtitles_remove_bloat"
|
||||
android:nextFocusDown="@id/apply_btt"
|
||||
android:nextFocusLeft="@id/apply_btt"
|
||||
android:nextFocusRight="@id/cancel_btt"
|
||||
android:fontFamily="@font/google_sans"
|
||||
style="@style/SettingsItem"
|
||||
app:drawableEndCompat="@null"
|
||||
android:id="@+id/subtitles_remove_captions"
|
||||
android:text="@string/subtitles_remove_captions"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -175,7 +202,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:nextFocusRight="@id/cancel_btt"
|
||||
android:nextFocusUp="@id/subs_download_languages"
|
||||
android:nextFocusUp="@id/subtitles_remove_captions"
|
||||
android:text="@string/sort_apply"
|
||||
android:visibility="visible">
|
||||
|
||||
|
@ -188,7 +215,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:nextFocusLeft="@id/apply_btt"
|
||||
android:nextFocusUp="@id/subs_download_languages"
|
||||
android:nextFocusUp="@id/subtitles_remove_captions"
|
||||
android:text="@string/sort_cancel" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -523,4 +523,6 @@
|
|||
<string name="title">Title</string>
|
||||
<string name="resolution">Resolution</string>
|
||||
<string name="error_invalid_id">Invalid id</string>
|
||||
<string name="subtitles_remove_captions">Remove closed captions from subtitles</string>
|
||||
<string name="subtitles_remove_bloat">Remove bloat from subtitles</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue