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.DefaultMediaSourceFactory
import com.google.android.exoplayer2.source.MergingMediaSource import com.google.android.exoplayer2.source.MergingMediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource 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.text.SubtitleExtractor
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.trackselection.TrackSelector import com.google.android.exoplayer2.trackselection.TrackSelector
@ -598,11 +599,26 @@ class CS3IPlayer : IPlayer {
.setSelectionFlags(C.SELECTION_FLAG_DEFAULT) .setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
.build() .build()
val ownFactory = CustomSubtitleDecoderFactory()
val extractorFactory = ExtractorsFactory { val extractorFactory = ExtractorsFactory {
arrayOf( arrayOf(
SubtitleExtractor( if (ownFactory.supportsFormat(format)) {
CustomSubtitleDecoderFactory().createDecoder(format), 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.ttml.TtmlDecoder
import com.google.android.exoplayer2.text.webvtt.WebvttDecoder import com.google.android.exoplayer2.text.webvtt.WebvttDecoder
import com.google.android.exoplayer2.util.MimeTypes import com.google.android.exoplayer2.util.MimeTypes
import com.lagradost.cloudstream3.mvvm.logError
class CustomDecoder : SubtitleDecoder { class CustomDecoder : SubtitleDecoder {
@ -18,7 +19,7 @@ class CustomDecoder : SubtitleDecoder {
private const val TAG = "CustomDecoder" private const val TAG = "CustomDecoder"
} }
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::class.java.name
@ -31,36 +32,40 @@ class CustomDecoder : SubtitleDecoder {
override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) { override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) {
Log.i(TAG, "queueInputBuffer") 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) { val pos = data.position()
inputBuffer.data?.let { data -> data.position(0)
val arr = ByteArray(minOf(data.remaining(), 100))
data.get(arr)
data.position(pos)
val pos = data.position() val str = arr.decodeToString().trimStart()
data.position(0) Log.i(TAG, "Got data from queueInputBuffer")
val arr = ByteArray(minOf(data.remaining(), 100)) Log.i(TAG, "first string is $str")
data.get(arr)
data.position(pos)
val str = arr.decodeToString().trimStart() //https://github.com/LagradOst/CloudStream-2/blob/ddd774ee66810137ff7bd65dae70bcf3ba2d2489/CloudStreamForms/CloudStreamForms/Script/MainChrome.cs#L388
Log.i(TAG, "Got data from queueInputBuffer") realDecoder = when {
Log.i(TAG, "first string is $str") 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?.dequeueInputBuffer()?.let { buff ->
realDecoder = when { buff.data = data
str.startsWith("WEBVTT") -> WebvttDecoder() realDecoder?.queueInputBuffer(buff)
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)
} }
} else {
realDecoder?.dequeueInputBuffer()
} }
} else { } catch (e: Exception) {
realDecoder?.dequeueInputBuffer() logError(e)
} }
} }

View file

@ -103,9 +103,9 @@ class GeneratorPlayer : FullScreenPlayer() {
val (linkData, _) = it val (linkData, _) = it
var quality = linkData?.quality ?: Qualities.Unknown.value 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) { if (useQualitySettings && quality > currentPrefQuality) {
quality = currentPrefQuality - 1 quality = currentPrefQuality - quality - 1
} }
// negative because we want to sort highest quality first // negative because we want to sort highest quality first
-(quality) -(quality)