mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
mini api fix
This commit is contained in:
parent
af4d57e842
commit
661f8c3c4e
2 changed files with 42 additions and 11 deletions
|
@ -22,7 +22,6 @@ import okhttp3.Interceptor
|
|||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.collections.MutableList
|
||||
|
||||
const val USER_AGENT =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
||||
|
@ -332,13 +331,24 @@ data class SettingsJson(
|
|||
data class MainPageData(
|
||||
val name: String,
|
||||
val data: String,
|
||||
val horizontalImages: Boolean = false
|
||||
)
|
||||
|
||||
data class MainPageRequest(
|
||||
val name: String,
|
||||
val data: String,
|
||||
val horizontalImages: Boolean,
|
||||
//TODO genre selection or smth
|
||||
)
|
||||
|
||||
fun mainPage(url: String, name: String, horizontalImages: Boolean = false): MainPageData {
|
||||
return MainPageData(name = name, data = url, horizontalImages = horizontalImages)
|
||||
}
|
||||
|
||||
fun mainPageOf(vararg elements: MainPageData): List<MainPageData> {
|
||||
return elements.toList()
|
||||
}
|
||||
|
||||
/** return list of MainPageData with url to name, make for more readable code */
|
||||
fun mainPageOf(vararg elements: Pair<String, String>): List<MainPageData> {
|
||||
return elements.map { (url, name) -> MainPageData(name = name, data = url) }
|
||||
|
@ -347,7 +357,7 @@ fun mainPageOf(vararg elements: Pair<String, String>): List<MainPageData> {
|
|||
fun newHomePageResponse(
|
||||
name: String,
|
||||
list: List<SearchResponse>,
|
||||
hasNext: Boolean? = null
|
||||
hasNext: Boolean? = null,
|
||||
): HomePageResponse {
|
||||
return HomePageResponse(
|
||||
listOf(HomePageList(name, list)),
|
||||
|
@ -355,6 +365,17 @@ fun newHomePageResponse(
|
|||
)
|
||||
}
|
||||
|
||||
fun newHomePageResponse(
|
||||
data: MainPageRequest,
|
||||
list: List<SearchResponse>,
|
||||
hasNext: Boolean? = null,
|
||||
): HomePageResponse {
|
||||
return HomePageResponse(
|
||||
listOf(HomePageList(data.name, list, data.horizontalImages)),
|
||||
hasNext = hasNext ?: list.isNotEmpty()
|
||||
)
|
||||
}
|
||||
|
||||
fun newHomePageResponse(list: HomePageList, hasNext: Boolean? = null): HomePageResponse {
|
||||
return HomePageResponse(listOf(list), hasNext = hasNext ?: list.list.isNotEmpty())
|
||||
}
|
||||
|
@ -391,14 +412,17 @@ abstract class MainAPI {
|
|||
|
||||
/** if this is turned on then it will request the homepage one after the other,
|
||||
used to delay if they block many request at the same time*/
|
||||
open var sequentialMainPage : Boolean = false
|
||||
open var sequentialMainPage: Boolean = false
|
||||
|
||||
/** in milliseconds, this can be used to add more delay between homepage requests
|
||||
* on first load if sequentialMainPage is turned on */
|
||||
open var sequentialMainPageDelay : Long = 0L
|
||||
open var sequentialMainPageDelay: Long = 0L
|
||||
|
||||
/** in milliseconds, this can be used to add more delay between homepage requests when scrolling */
|
||||
open var sequentialMainPageScrollDelay : Long = 0L
|
||||
open var sequentialMainPageScrollDelay: Long = 0L
|
||||
|
||||
/** used to keep track when last homepage request was in unixtime ms */
|
||||
var lastHomepageRequest : Long = 0L
|
||||
var lastHomepageRequest: Long = 0L
|
||||
|
||||
open var lang = "en" // ISO_639_1 check SubtitleHelper
|
||||
|
||||
|
@ -431,7 +455,8 @@ abstract class MainAPI {
|
|||
open val vpnStatus = VPNStatus.None
|
||||
open val providerType = ProviderType.DirectProvider
|
||||
|
||||
open val mainPage = listOf(MainPageData("", ""))
|
||||
//emptyList<MainPageData>() //
|
||||
open val mainPage = listOf(MainPageData("", "", false))
|
||||
|
||||
@WorkerThread
|
||||
open suspend fun getMainPage(
|
||||
|
|
|
@ -66,7 +66,7 @@ class APIRepository(val api: MainAPI) {
|
|||
|
||||
suspend fun waitForHomeDelay() {
|
||||
val delta = api.sequentialMainPageScrollDelay + api.lastHomepageRequest - unixTimeMS
|
||||
if(delta < 0) return
|
||||
if (delta < 0) return
|
||||
delay(delta)
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ class APIRepository(val api: MainAPI) {
|
|||
api.lastHomepageRequest = unixTimeMS
|
||||
|
||||
nameIndex?.let { api.mainPage.getOrNull(it) }?.let { data ->
|
||||
listOf(api.getMainPage(page, MainPageRequest(data.name, data.data)))
|
||||
listOf(api.getMainPage(page, MainPageRequest(data.name, data.data, data.horizontalImages)))
|
||||
} ?: run {
|
||||
if (api.sequentialMainPage) {
|
||||
var first = true
|
||||
|
@ -84,11 +84,17 @@ class APIRepository(val api: MainAPI) {
|
|||
delay(api.sequentialMainPageDelay)
|
||||
first = false
|
||||
|
||||
api.getMainPage(page, MainPageRequest(data.name, data.data))
|
||||
api.getMainPage(
|
||||
page,
|
||||
MainPageRequest(data.name, data.data, data.horizontalImages)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
api.mainPage.apmap { data ->
|
||||
api.getMainPage(page, MainPageRequest(data.name, data.data))
|
||||
api.getMainPage(
|
||||
page,
|
||||
MainPageRequest(data.name, data.data, data.horizontalImages)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue