minor fix

This commit is contained in:
LagradOst 2022-01-12 18:32:03 +01:00
parent 3f1e398ae8
commit 48c786a5b8
3 changed files with 51 additions and 30 deletions

View file

@ -11,6 +11,7 @@ import com.google.android.exoplayer2.extractor.ExtractorsFactory
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
import com.google.android.exoplayer2.source.MergingMediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.text.SubtitleDecoderFactory
import com.google.android.exoplayer2.text.SubtitleExtractor
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.trackselection.TrackSelector
@ -598,11 +599,26 @@ class CS3IPlayer : IPlayer {
.setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
.build()
val ownFactory = CustomSubtitleDecoderFactory()
val extractorFactory = ExtractorsFactory {
arrayOf(
SubtitleExtractor(
CustomSubtitleDecoderFactory().createDecoder(format), format
)
if (ownFactory.supportsFormat(format)) {
SubtitleExtractor(
ownFactory.createDecoder(format), format
)
} else {
if (SubtitleDecoderFactory.DEFAULT.supportsFormat(format)) {
SubtitleExtractor(
SubtitleDecoderFactory.DEFAULT.createDecoder(format), format
)
} else {
// ye we guess if not found instead of using UnknownSubtitlesExtractor,
// this way you can hopefully load a .txt file that is an srt and it will work
SubtitleExtractor(
ownFactory.createDecoder(format), format
)
}
}
)
}

View file

@ -11,6 +11,7 @@ import com.google.android.exoplayer2.text.subrip.SubripDecoder
import com.google.android.exoplayer2.text.ttml.TtmlDecoder
import com.google.android.exoplayer2.text.webvtt.WebvttDecoder
import com.google.android.exoplayer2.util.MimeTypes
import com.lagradost.cloudstream3.mvvm.logError
class CustomDecoder : SubtitleDecoder {
@ -18,7 +19,7 @@ class CustomDecoder : SubtitleDecoder {
private const val TAG = "CustomDecoder"
}
var realDecoder: SubtitleDecoder? = null
private var realDecoder: SubtitleDecoder? = null
override fun getName(): String {
return realDecoder?.name ?: this::class.java.name
@ -31,36 +32,40 @@ class CustomDecoder : SubtitleDecoder {
override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) {
Log.i(TAG, "queueInputBuffer")
try {
if (realDecoder == null) {
inputBuffer.data?.let { data ->
// this way we read the subtitle file and decide what decoder to use instead of relying on mimetype
if (realDecoder == null) {
inputBuffer.data?.let { data ->
val pos = data.position()
data.position(0)
val arr = ByteArray(minOf(data.remaining(), 100))
data.get(arr)
data.position(pos)
val pos = data.position()
data.position(0)
val arr = ByteArray(minOf(data.remaining(), 100))
data.get(arr)
data.position(pos)
val str = arr.decodeToString().trimStart()
Log.i(TAG, "Got data from queueInputBuffer")
Log.i(TAG, "first string is $str")
val str = arr.decodeToString().trimStart()
Log.i(TAG, "Got data from queueInputBuffer")
Log.i(TAG, "first string is $str")
//https://github.com/LagradOst/CloudStream-2/blob/ddd774ee66810137ff7bd65dae70bcf3ba2d2489/CloudStreamForms/CloudStreamForms/Script/MainChrome.cs#L388
realDecoder = when {
str.startsWith("WEBVTT") -> WebvttDecoder()
str.startsWith("<?xml version=\"") -> TtmlDecoder()
str.startsWith("[Script Info]") || str.startsWith("Title:") -> SsaDecoder()
str.startsWith("1") -> SubripDecoder()
else -> null
}
//https://github.com/LagradOst/CloudStream-2/blob/ddd774ee66810137ff7bd65dae70bcf3ba2d2489/CloudStreamForms/CloudStreamForms/Script/MainChrome.cs#L388
realDecoder = when {
str.startsWith("WEBVTT") -> WebvttDecoder()
str.startsWith("<?xml version=\"") -> TtmlDecoder()
str.startsWith("[Script Info]") || str.startsWith("Title:") -> SsaDecoder()
str.startsWith("1") -> SubripDecoder()
else -> null
}
realDecoder?.dequeueInputBuffer()?.let { buff ->
buff.data = data
realDecoder?.queueInputBuffer(buff)
realDecoder?.dequeueInputBuffer()?.let { buff ->
buff.data = data
realDecoder?.queueInputBuffer(buff)
}
}
} else {
realDecoder?.dequeueInputBuffer()
}
} else {
realDecoder?.dequeueInputBuffer()
} catch (e: Exception) {
logError(e)
}
}

View file

@ -103,9 +103,9 @@ class GeneratorPlayer : FullScreenPlayer() {
val (linkData, _) = it
var quality = linkData?.quality ?: Qualities.Unknown.value
// we set all qualities above current max as max -1
// we set all qualities above current max as reverse
if (useQualitySettings && quality > currentPrefQuality) {
quality = currentPrefQuality - 1
quality = currentPrefQuality - quality - 1
}
// negative because we want to sort highest quality first
-(quality)