fixed json pair and next episode

This commit is contained in:
LagradOst 2022-01-17 17:17:19 +01:00
parent 030f0e98c3
commit 9f9251108a
5 changed files with 44 additions and 33 deletions

View file

@ -172,7 +172,7 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
episodeTitle.removePrefix("Episode $episodeNum: "),
season + 1,
episodeNum,
"$url:::$episodeData",
Pair(url, episodeData).toJson(),
fixUrl(episodePosterUrl)
)
)
@ -249,9 +249,10 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
mapped.sources1 to "source 2",
mapped.sources2 to "source 3",
mapped.sourcesBackup to "source backup"
).forEach { subList ->
subList.first?.forEach {
it?.toExtractorLink(this, subList.second)?.forEach(callback)
).forEach { (sources, sourceName) ->
println("SOURCE:::: $sourceName $sources")
sources?.forEach {
it?.toExtractorLink(this, sourceName)?.forEach(callback)
}
}
}

View file

@ -50,9 +50,10 @@ class DownloadFileGenerator(
clearCache: Boolean,
isCasting: Boolean,
callback: (Pair<ExtractorLink?, ExtractorUri?>) -> Unit,
subtitleCallback: (SubtitleData) -> Unit
subtitleCallback: (SubtitleData) -> Unit,
offset: Int,
): Boolean {
val meta = episodes[currentIndex]
val meta = episodes[currentIndex + offset]
callback(Pair(null, meta))
context?.let { ctx ->

View file

@ -20,6 +20,7 @@ interface IGenerator {
clearCache: Boolean,
isCasting: Boolean,
callback: (Pair<ExtractorLink?, ExtractorUri?>) -> Unit,
subtitleCallback: (SubtitleData) -> Unit
subtitleCallback: (SubtitleData) -> Unit,
offset : Int = 0,
): Boolean
}

View file

@ -9,6 +9,7 @@ import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.mvvm.safeApiCall
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.ExtractorUri
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
class PlayerGeneratorViewModel : ViewModel() {
@ -50,12 +51,13 @@ class PlayerGeneratorViewModel : ViewModel() {
return generator?.hasNext()
}
fun preLoadNextLinks() = viewModelScope.launch {
safeApiCall {
fun preLoadNextLinks() {
currentJob?.cancel()
currentJob = viewModelScope.launch {
if (generator?.hasCache == true && generator?.hasNext() == true) {
generator?.next()
generator?.generateLinks(clearCache = false, isCasting = false, {}, {})
generator?.prev()
safeApiCall {
generator?.generateLinks(clearCache = false, isCasting = false, {}, {}, offset = 1)
}
}
}
}
@ -86,7 +88,11 @@ class PlayerGeneratorViewModel : ViewModel() {
_currentSubs.postValue(subs)
}
fun loadLinks(clearCache: Boolean = false, isCasting: Boolean = false) = viewModelScope.launch {
private var currentJob: Job? = null
fun loadLinks(clearCache: Boolean = false, isCasting: Boolean = false) {
currentJob?.cancel()
currentJob = viewModelScope.launch {
val currentLinks = mutableSetOf<Pair<ExtractorLink?, ExtractorUri?>>()
val currentSubs = mutableSetOf<SubtitleData>()
@ -107,3 +113,4 @@ class PlayerGeneratorViewModel : ViewModel() {
_currentSubs.postValue(currentSubs)
}
}
}

View file

@ -50,10 +50,11 @@ class RepoLinkGenerator(private val episodes: List<ResultEpisode>, private var c
clearCache: Boolean,
isCasting: Boolean,
callback: (Pair<ExtractorLink?, ExtractorUri?>) -> Unit,
subtitleCallback: (SubtitleData) -> Unit
subtitleCallback: (SubtitleData) -> Unit,
offset : Int,
): Boolean {
val index = currentIndex
val current = episodes[index]
val current = episodes[index + offset]
val currentLinkCache = if (clearCache) mutableSetOf() else linkCache[index].toMutableSet()
val currentSubsCache = if (clearCache) mutableSetOf() else subsCache[index].toMutableSet()