might have fixed #1031

This commit is contained in:
LagradOst 2022-05-07 13:37:35 +02:00
parent c573deb09c
commit ad64cb3f86
2 changed files with 26 additions and 22 deletions

View file

@ -18,6 +18,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelector
import com.google.android.exoplayer2.ui.SubtitleView
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.upstream.cache.CacheDataSource
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor
import com.google.android.exoplayer2.upstream.cache.SimpleCache
@ -313,17 +314,15 @@ class CS3IPlayer : IPlayer {
val provider = getApiFromName(link.source)
val interceptor = provider.getVideoInterceptor(link)
val client = app.baseClient
.let {
if (interceptor != null)
it.newBuilder()
val source = if (interceptor == null) {
DefaultHttpDataSource.Factory().setUserAgent(USER_AGENT)
} else {
val client = app.baseClient.newBuilder()
.addInterceptor(interceptor)
.build()
else it
OkHttpDataSource.Factory(client).setUserAgent(USER_AGENT)
}
return OkHttpDataSource.Factory(client).apply {
setUserAgent(USER_AGENT)
val headers = mapOf(
"referer" to link.referer,
"accept" to "*/*",
@ -333,6 +332,8 @@ class CS3IPlayer : IPlayer {
"sec-fetch-mode" to "navigate",
"sec-fetch-dest" to "video"
) + link.headers // Adds the headers from the provider, e.g Authorization
return source.apply {
setDefaultRequestProperties(headers)
//https://stackoverflow.com/questions/69040127/error-code-io-bad-http-status-exoplayer-android
@ -468,7 +469,7 @@ class CS3IPlayer : IPlayer {
.setLoadControl(
DefaultLoadControl.Builder()
.setTargetBufferBytes(
if(cacheSize <= 0) {
if (cacheSize <= 0) {
DefaultLoadControl.DEFAULT_TARGET_BUFFER_BYTES
} else {
if (cacheSize > Int.MAX_VALUE) Int.MAX_VALUE else cacheSize.toInt()
@ -476,7 +477,7 @@ class CS3IPlayer : IPlayer {
)
.setBufferDurationsMs(
DefaultLoadControl.DEFAULT_MIN_BUFFER_MS,
if(videoBufferMs <= 0) {
if (videoBufferMs <= 0) {
DefaultLoadControl.DEFAULT_MAX_BUFFER_MS
} else {
videoBufferMs.toInt()

View file

@ -12,6 +12,7 @@ import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey
import com.lagradost.cloudstream3.USER_AGENT
import com.lagradost.cloudstream3.network.DdosGuardKiller
import com.lagradost.cloudstream3.network.initClient
import com.lagradost.nicehttp.Requests
@ -33,7 +34,9 @@ class GlideModule : AppGlideModule() {
// https://stackoverflow.com/a/61634041
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
val client =
Requests().initClient(context)
Requests().apply {
defaultHeaders = mapOf("user-agent" to USER_AGENT)
}.initClient(context)
.newBuilder()
.addInterceptor(DdosGuardKiller(false))
.build()