forked from recloudstream/cloudstream
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())
|
||||
}
|
||||
|
@ -392,11 +413,14 @@ 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
|
||||
|
||||
/** 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
|
||||
|
||||
/** in milliseconds, this can be used to add more delay between homepage requests when scrolling */
|
||||
open var sequentialMainPageScrollDelay: Long = 0L
|
||||
|
||||
/** used to keep track when last homepage request was in unixtime ms */
|
||||
var lastHomepageRequest: Long = 0L
|
||||
|
||||
|
@ -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(
|
||||
|
|
|
@ -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