From 9f9251108a14affff04d2758043fca4ef48594ed Mon Sep 17 00:00:00 2001 From: LagradOst Date: Mon, 17 Jan 2022 17:17:19 +0100 Subject: [PATCH] fixed json pair and next episode --- .../movieproviders/SflixProvider.kt | 13 ++--- .../ui/player/DownloadFileGenerator.kt | 5 +- .../cloudstream3/ui/player/IGenerator.kt | 3 +- .../ui/player/PlayerGeneratorViewModel.kt | 51 +++++++++++-------- .../ui/player/RepoLinkGenerator.kt | 5 +- 5 files changed, 44 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt index 5e3eeaee..c5964bb9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt @@ -127,7 +127,7 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() { // Supported streams, they're identical val sourceIds = Jsoup.parse(episodes).select("a").mapNotNull { element -> 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/") } else { null @@ -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) ) ) @@ -220,7 +220,7 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() { // Supported streams, they're identical Jsoup.parse(episodes).select("a").mapNotNull { element -> 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/") } else { null @@ -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) } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadFileGenerator.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadFileGenerator.kt index bd1f9550..0a84668e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadFileGenerator.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadFileGenerator.kt @@ -50,9 +50,10 @@ class DownloadFileGenerator( clearCache: Boolean, isCasting: Boolean, callback: (Pair) -> 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 -> diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/IGenerator.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/IGenerator.kt index 820f6555..40f99372 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/IGenerator.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/IGenerator.kt @@ -20,6 +20,7 @@ interface IGenerator { clearCache: Boolean, isCasting: Boolean, callback: (Pair) -> Unit, - subtitleCallback: (SubtitleData) -> Unit + subtitleCallback: (SubtitleData) -> Unit, + offset : Int = 0, ): Boolean } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerGeneratorViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerGeneratorViewModel.kt index 9297896c..7bece164 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerGeneratorViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerGeneratorViewModel.kt @@ -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,24 +88,29 @@ class PlayerGeneratorViewModel : ViewModel() { _currentSubs.postValue(subs) } - fun loadLinks(clearCache: Boolean = false, isCasting: Boolean = false) = viewModelScope.launch { - val currentLinks = mutableSetOf>() - val currentSubs = mutableSetOf() + private var currentJob: Job? = null - _loadingLinks.postValue(Resource.Loading()) - 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 - }) + fun loadLinks(clearCache: Boolean = false, isCasting: Boolean = false) { + currentJob?.cancel() + currentJob = viewModelScope.launch { + val currentLinks = mutableSetOf>() + val currentSubs = mutableSetOf() + + _loadingLinks.postValue(Resource.Loading()) + 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) } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/RepoLinkGenerator.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/RepoLinkGenerator.kt index bcf565a0..62242b4e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/RepoLinkGenerator.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/RepoLinkGenerator.kt @@ -50,10 +50,11 @@ class RepoLinkGenerator(private val episodes: List, private var c clearCache: Boolean, isCasting: Boolean, callback: (Pair) -> 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()