feat : invalidate link cache after 20 mins

- additionaly clear cache if there is player errors or no links found
This commit is contained in:
coxju 2024-01-10 16:59:49 +05:30
parent 42fd0b5c76
commit f8be0ffa38
6 changed files with 33 additions and 2 deletions

View file

@ -102,6 +102,10 @@ abstract class AbstractPlayerFragment(
throw NotImplementedError()
}
open fun playerStatusChanged(){
throw NotImplementedError()
}
open fun playerDimensionsLoaded(width: Int, height: Int) {
throw NotImplementedError()
}
@ -431,6 +435,7 @@ abstract class AbstractPlayerFragment(
is StatusEvent -> {
updateIsPlaying(wasPlaying = event.wasPlaying, isPlaying = event.isPlaying)
playerStatusChanged()
}
is PositionEvent -> {

View file

@ -146,6 +146,12 @@ class GeneratorPlayer : FullScreenPlayer() {
}
}
override fun playerStatusChanged() {
if(player.getIsPlaying()){
viewModel.clearCache = false
}
}
private fun noSubtitles(): Boolean {
return setSubtitles(null)
}
@ -913,10 +919,15 @@ class GeneratorPlayer : FullScreenPlayer() {
override fun playerError(exception: Throwable) {
Log.i(TAG, "playerError = $currentSelectedLink")
if(!hasNextMirror()){
viewModel.clearCache = true
}
super.playerError(exception)
}
private fun noLinksFound() {
viewModel.clearCache = true
showToast(R.string.no_links_found_toast, Toast.LENGTH_SHORT)
activity?.popCurrentPage()
}

View file

@ -45,6 +45,8 @@ class PlayerGeneratorViewModel : ViewModel() {
*/
private var currentLoadingEpisodeId: Int? = null
var clearCache = false
fun setSubtitleYear(year: Int?) {
_currentSubtitleYear.postValue(year)
}
@ -168,7 +170,7 @@ class PlayerGeneratorViewModel : ViewModel() {
}
}
fun loadLinks(clearCache: Boolean = false, type: LoadType = LoadType.InApp) {
fun loadLinks(type: LoadType = LoadType.InApp) {
Log.i(TAG, "loadLinks")
currentJob?.cancel()

View file

@ -6,6 +6,7 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.media3.common.MimeTypes
import androidx.media3.ui.SubtitleView
import com.lagradost.cloudstream3.APIHolder
import com.lagradost.cloudstream3.SubtitleFile
import com.lagradost.cloudstream3.ui.player.CustomDecoder.Companion.regexSubtitlesToRemoveBloat
import com.lagradost.cloudstream3.ui.player.CustomDecoder.Companion.regexSubtitlesToRemoveCaptions
@ -38,7 +39,8 @@ data class SubtitleData(
val origin: SubtitleOrigin,
val mimeType: String,
val headers: Map<String, String>,
val languageCode: String?
val languageCode: String?,
val createdTime: Long = APIHolder.unixTime
) {
/** Internal ID for exoplayer, unique for each link*/
fun getId(): String {

View file

@ -2,6 +2,7 @@ package com.lagradost.cloudstream3.ui.player
import android.util.Log
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
import com.lagradost.cloudstream3.APIHolder.unixTime
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.ui.APIRepository
import com.lagradost.cloudstream3.ui.result.ResultEpisode
@ -89,6 +90,14 @@ class RepoLinkGenerator(
val currentSubsUrls = mutableSetOf<String>() // makes all subs urls unique
val currentSubsNames = mutableSetOf<String>() // makes all subs names unique
val invalidateCache = currentLinkCache.size - currentLinkCache.filter { link -> unixTime-link.createdTime < 60 * 20 }.size !=0 // 20 minutes
if(invalidateCache)
currentLinkCache.clear()
val invalidateSubtitleCache = currentSubsCache.size - currentSubsCache.filter { link -> unixTime-link.createdTime < 60 * 20 }.size !=0 // 20 minutes
if(invalidateSubtitleCache)
currentSubsCache.clear()
currentLinkCache.filter { allowedTypes.contains(it.type) }.forEach { link ->
currentLinks.add(link.url)
callback(link to null)

View file

@ -2,6 +2,7 @@ package com.lagradost.cloudstream3.utils
import android.net.Uri
import com.fasterxml.jackson.annotation.JsonIgnore
import com.lagradost.cloudstream3.APIHolder
import com.lagradost.cloudstream3.SubtitleFile
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.USER_AGENT
@ -394,6 +395,7 @@ open class ExtractorLink constructor(
/** Used for getExtractorVerifierJob() */
open val extractorData: String? = null,
open val type: ExtractorLinkType,
open val createdTime: Long = APIHolder.unixTime
) : VideoDownloadManager.IDownloadableMinimum {
val isM3u8 : Boolean get() = type == ExtractorLinkType.M3U8
val isDash : Boolean get() = type == ExtractorLinkType.DASH