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

@ -127,7 +127,7 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
// Supported streams, they're identical // Supported streams, they're identical
val sourceIds = Jsoup.parse(episodes).select("a").mapNotNull { element -> val sourceIds = Jsoup.parse(episodes).select("a").mapNotNull { element ->
val sourceId = element.attr("data-id") ?: return@mapNotNull null val sourceId = element.attr("data-id") ?: return@mapNotNull null
if(element.select("span")?.text()?.trim()?.isValidServer() == true) { if (element.select("span")?.text()?.trim()?.isValidServer() == true) {
"$url.$sourceId".replace("/movie/", "/watch-movie/") "$url.$sourceId".replace("/movie/", "/watch-movie/")
} else { } else {
null null
@ -172,7 +172,7 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
episodeTitle.removePrefix("Episode $episodeNum: "), episodeTitle.removePrefix("Episode $episodeNum: "),
season + 1, season + 1,
episodeNum, episodeNum,
"$url:::$episodeData", Pair(url, episodeData).toJson(),
fixUrl(episodePosterUrl) fixUrl(episodePosterUrl)
) )
) )
@ -220,7 +220,7 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
// Supported streams, they're identical // Supported streams, they're identical
Jsoup.parse(episodes).select("a").mapNotNull { element -> Jsoup.parse(episodes).select("a").mapNotNull { element ->
val id = element?.attr("data-id") ?: return@mapNotNull null val id = element?.attr("data-id") ?: return@mapNotNull null
if(element.select("span")?.text()?.trim()?.isValidServer() == true) { if (element.select("span")?.text()?.trim()?.isValidServer() == true) {
"$prefix.$id".replace("/tv/", "/watch-tv/") "$prefix.$id".replace("/tv/", "/watch-tv/")
} else { } else {
null null
@ -249,9 +249,10 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
mapped.sources1 to "source 2", mapped.sources1 to "source 2",
mapped.sources2 to "source 3", mapped.sources2 to "source 3",
mapped.sourcesBackup to "source backup" mapped.sourcesBackup to "source backup"
).forEach { subList -> ).forEach { (sources, sourceName) ->
subList.first?.forEach { println("SOURCE:::: $sourceName $sources")
it?.toExtractorLink(this, subList.second)?.forEach(callback) sources?.forEach {
it?.toExtractorLink(this, sourceName)?.forEach(callback)
} }
} }
} }

View file

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

View file

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

View file

@ -9,6 +9,7 @@ import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.mvvm.safeApiCall import com.lagradost.cloudstream3.mvvm.safeApiCall
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.ExtractorUri import com.lagradost.cloudstream3.utils.ExtractorUri
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class PlayerGeneratorViewModel : ViewModel() { class PlayerGeneratorViewModel : ViewModel() {
@ -50,12 +51,13 @@ class PlayerGeneratorViewModel : ViewModel() {
return generator?.hasNext() return generator?.hasNext()
} }
fun preLoadNextLinks() = viewModelScope.launch { fun preLoadNextLinks() {
safeApiCall { currentJob?.cancel()
currentJob = viewModelScope.launch {
if (generator?.hasCache == true && generator?.hasNext() == true) { if (generator?.hasCache == true && generator?.hasNext() == true) {
generator?.next() safeApiCall {
generator?.generateLinks(clearCache = false, isCasting = false, {}, {}) generator?.generateLinks(clearCache = false, isCasting = false, {}, {}, offset = 1)
generator?.prev() }
} }
} }
} }
@ -86,24 +88,29 @@ class PlayerGeneratorViewModel : ViewModel() {
_currentSubs.postValue(subs) _currentSubs.postValue(subs)
} }
fun loadLinks(clearCache: Boolean = false, isCasting: Boolean = false) = viewModelScope.launch { private var currentJob: Job? = null
val currentLinks = mutableSetOf<Pair<ExtractorLink?, ExtractorUri?>>()
val currentSubs = mutableSetOf<SubtitleData>()
_loadingLinks.postValue(Resource.Loading()) fun loadLinks(clearCache: Boolean = false, isCasting: Boolean = false) {
val loadingState = safeApiCall { currentJob?.cancel()
generator?.generateLinks(clearCache = clearCache, isCasting = isCasting, { currentJob = viewModelScope.launch {
currentLinks.add(it) val currentLinks = mutableSetOf<Pair<ExtractorLink?, ExtractorUri?>>()
_currentLinks.postValue(currentLinks) val currentSubs = mutableSetOf<SubtitleData>()
}, {
currentSubs.add(it) _loadingLinks.postValue(Resource.Loading())
// _currentSubs.postValue(currentSubs) // this causes ConcurrentModificationException, so fuck it val loadingState = safeApiCall {
}) generator?.generateLinks(clearCache = clearCache, isCasting = isCasting, {
currentLinks.add(it)
_currentLinks.postValue(currentLinks)
}, {
currentSubs.add(it)
// _currentSubs.postValue(currentSubs) // this causes ConcurrentModificationException, so fuck it
})
}
_loadingLinks.postValue(loadingState)
_currentLinks.postValue(currentLinks)
_currentSubs.postValue(currentSubs)
} }
_loadingLinks.postValue(loadingState)
_currentLinks.postValue(currentLinks)
_currentSubs.postValue(currentSubs)
} }
} }

View file

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