forked from recloudstream/cloudstream
		
	fixed json pair and next episode
This commit is contained in:
		
							parent
							
								
									030f0e98c3
								
							
						
					
					
						commit
						9f9251108a
					
				
					 5 changed files with 44 additions and 33 deletions
				
			
		|  | @ -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) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  |  | |||
|  | @ -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 -> | ||||
|  |  | |||
|  | @ -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 | ||||
| } | ||||
|  | @ -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<Pair<ExtractorLink?, ExtractorUri?>>() | ||||
|         val currentSubs = mutableSetOf<SubtitleData>() | ||||
|     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<Pair<ExtractorLink?, ExtractorUri?>>() | ||||
|             val currentSubs = mutableSetOf<SubtitleData>() | ||||
| 
 | ||||
|             _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) | ||||
|     } | ||||
| } | ||||
|  | @ -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() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue