mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
parent
cc7d7ec478
commit
f5545a10f5
2 changed files with 24 additions and 7 deletions
|
@ -73,7 +73,7 @@ class CustomDecoder : SubtitleDecoder {
|
||||||
private var realDecoder: SubtitleDecoder? = null
|
private var realDecoder: SubtitleDecoder? = null
|
||||||
|
|
||||||
override fun getName(): String {
|
override fun getName(): String {
|
||||||
return realDecoder?.name ?: this::class.java.name
|
return realDecoder?.name ?: this::javaClass.name
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dequeueInputBuffer(): SubtitleInputBuffer {
|
override fun dequeueInputBuffer(): SubtitleInputBuffer {
|
||||||
|
@ -127,6 +127,11 @@ class CustomDecoder : SubtitleDecoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun SubtitleInputBuffer.setSubtitleText(text: String) {
|
||||||
|
// println("Set subtitle text -----\n$text\n-----")
|
||||||
|
this.data = ByteBuffer.wrap(text.toByteArray(charset(UTF_8)))
|
||||||
|
}
|
||||||
|
|
||||||
override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) {
|
override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) {
|
||||||
Log.i(TAG, "queueInputBuffer")
|
Log.i(TAG, "queueInputBuffer")
|
||||||
try {
|
try {
|
||||||
|
@ -152,7 +157,7 @@ class CustomDecoder : SubtitleDecoder {
|
||||||
)
|
)
|
||||||
realDecoder?.let { decoder ->
|
realDecoder?.let { decoder ->
|
||||||
decoder.dequeueInputBuffer()?.let { buff ->
|
decoder.dequeueInputBuffer()?.let { buff ->
|
||||||
if (decoder::class.java != SsaDecoder::class.java) {
|
if (decoder !is SsaDecoder) {
|
||||||
if (regexSubtitlesToRemoveCaptions)
|
if (regexSubtitlesToRemoveCaptions)
|
||||||
captionRegex.forEach { rgx ->
|
captionRegex.forEach { rgx ->
|
||||||
str = str.replace(rgx, "\n")
|
str = str.replace(rgx, "\n")
|
||||||
|
@ -162,8 +167,7 @@ class CustomDecoder : SubtitleDecoder {
|
||||||
str = str.replace(rgx, "\n")
|
str = str.replace(rgx, "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buff.data = ByteBuffer.wrap(str.toByteArray(charset(UTF_8)))
|
buff.setSubtitleText(str)
|
||||||
|
|
||||||
decoder.queueInputBuffer(buff)
|
decoder.queueInputBuffer(buff)
|
||||||
Log.i(
|
Log.i(
|
||||||
TAG,
|
TAG,
|
||||||
|
@ -180,7 +184,7 @@ class CustomDecoder : SubtitleDecoder {
|
||||||
|
|
||||||
if (!inputString.isNullOrBlank()) {
|
if (!inputString.isNullOrBlank()) {
|
||||||
var str: String = inputString
|
var str: String = inputString
|
||||||
if (realDecoder!!::class.java != SsaDecoder::class.java) {
|
if (realDecoder !is SsaDecoder) {
|
||||||
if (regexSubtitlesToRemoveCaptions)
|
if (regexSubtitlesToRemoveCaptions)
|
||||||
captionRegex.forEach { rgx ->
|
captionRegex.forEach { rgx ->
|
||||||
str = str.replace(rgx, "\n")
|
str = str.replace(rgx, "\n")
|
||||||
|
@ -190,7 +194,7 @@ class CustomDecoder : SubtitleDecoder {
|
||||||
str = str.replace(rgx, "\n")
|
str = str.replace(rgx, "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inputBuffer.data = ByteBuffer.wrap(str.toByteArray(charset(UTF_8)))
|
inputBuffer.setSubtitleText(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
realDecoder?.queueInputBuffer(inputBuffer)
|
realDecoder?.queueInputBuffer(inputBuffer)
|
||||||
|
|
|
@ -22,6 +22,8 @@ import androidx.annotation.IntDef
|
||||||
import com.google.android.exoplayer2.*
|
import com.google.android.exoplayer2.*
|
||||||
import com.google.android.exoplayer2.source.SampleStream.ReadDataResult
|
import com.google.android.exoplayer2.source.SampleStream.ReadDataResult
|
||||||
import com.google.android.exoplayer2.text.*
|
import com.google.android.exoplayer2.text.*
|
||||||
|
import com.google.android.exoplayer2.text.Cue.DIMEN_UNSET
|
||||||
|
import com.google.android.exoplayer2.text.Cue.LINE_TYPE_NUMBER
|
||||||
import com.google.android.exoplayer2.util.Assertions
|
import com.google.android.exoplayer2.util.Assertions
|
||||||
import com.google.android.exoplayer2.util.Log
|
import com.google.android.exoplayer2.util.Log
|
||||||
import com.google.android.exoplayer2.util.MimeTypes
|
import com.google.android.exoplayer2.util.MimeTypes
|
||||||
|
@ -308,7 +310,18 @@ open class NonFinalTextRenderer @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun invokeUpdateOutputInternal(cues: List<Cue>) {
|
private fun invokeUpdateOutputInternal(cues: List<Cue>) {
|
||||||
output.onCues(cues.map { cue -> cue.buildUpon().setSize(Cue.DIMEN_UNSET).build() }) // this fixes https://github.com/LagradOst/CloudStream-3/issues/717
|
output.onCues(cues.map { cue ->
|
||||||
|
val builder = cue.buildUpon()
|
||||||
|
|
||||||
|
// See https://github.com/google/ExoPlayer/issues/7934
|
||||||
|
// SubripDecoder texts tend to be DIMEN_UNSET which pushes up the
|
||||||
|
// subs unlike WEBVTT which creates an inconsistency
|
||||||
|
if (cue.line == DIMEN_UNSET)
|
||||||
|
builder.setLine(-1f, LINE_TYPE_NUMBER)
|
||||||
|
|
||||||
|
// this fixes https://github.com/LagradOst/CloudStream-3/issues/717
|
||||||
|
builder.setSize(DIMEN_UNSET).build()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue