2021-04-30 17:20:15 +00:00
|
|
|
package com.lagradost.cloudstream3
|
|
|
|
|
2021-05-15 23:37:42 +00:00
|
|
|
import android.app.Activity
|
|
|
|
import androidx.preference.PreferenceManager
|
2021-04-30 17:20:15 +00:00
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature
|
|
|
|
import com.fasterxml.jackson.databind.json.JsonMapper
|
|
|
|
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
2021-05-12 21:51:02 +00:00
|
|
|
import com.lagradost.cloudstream3.animeproviders.ShiroProvider
|
2021-05-20 15:22:28 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
2021-04-30 17:20:15 +00:00
|
|
|
import java.util.*
|
|
|
|
import kotlin.collections.ArrayList
|
|
|
|
|
|
|
|
const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0"
|
|
|
|
val baseHeader = mapOf("User-Agent" to USER_AGENT)
|
|
|
|
val mapper = JsonMapper.builder().addModule(KotlinModule())
|
|
|
|
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build()!!
|
|
|
|
|
2021-05-12 21:51:02 +00:00
|
|
|
object APIHolder {
|
2021-05-15 23:37:42 +00:00
|
|
|
val allApi = AllProvider()
|
|
|
|
|
|
|
|
private const val defProvider = 0
|
|
|
|
|
2021-05-12 21:51:02 +00:00
|
|
|
val apis = arrayListOf<MainAPI>(
|
|
|
|
ShiroProvider()
|
|
|
|
)
|
2021-05-15 23:37:42 +00:00
|
|
|
|
2021-05-22 22:25:56 +00:00
|
|
|
fun getApiFromName(apiName: String?): MainAPI {
|
2021-05-18 13:43:32 +00:00
|
|
|
for (api in apis) {
|
|
|
|
if (apiName == api.name)
|
|
|
|
return api
|
|
|
|
}
|
|
|
|
return apis[defProvider]
|
|
|
|
}
|
|
|
|
|
2021-05-15 23:37:42 +00:00
|
|
|
fun Activity.getApiSettings(): HashSet<String> {
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
|
|
|
|
return settingsManager.getStringSet(this.getString(R.string.search_providers_list_key),
|
|
|
|
setOf(apis[defProvider].name))?.toHashSet() ?: hashSetOf(apis[defProvider].name)
|
|
|
|
}
|
2021-05-12 21:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
abstract class MainAPI {
|
2021-04-30 17:20:15 +00:00
|
|
|
open val name = "NONE"
|
|
|
|
open val mainUrl = "NONE"
|
|
|
|
open fun search(query: String): ArrayList<Any>? { // SearchResponse
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2021-05-18 13:43:32 +00:00
|
|
|
open fun load(slug: String): Any? { //LoadResponse
|
2021-04-30 17:20:15 +00:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2021-05-20 15:22:28 +00:00
|
|
|
// callback is fired once a link is found, will return true if method is executed successfully
|
2021-06-14 16:58:43 +00:00
|
|
|
open fun loadLinks(data: String, isCasting: Boolean, callback: (ExtractorLink) -> Unit): Boolean {
|
2021-04-30 17:20:15 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-15 23:37:42 +00:00
|
|
|
fun MainAPI.fixUrl(url: String): String {
|
|
|
|
if (url.startsWith('/')) {
|
|
|
|
return mainUrl + url
|
2021-05-18 13:43:32 +00:00
|
|
|
} else if (!url.startsWith("http") && !url.startsWith("//")) {
|
2021-05-15 23:37:42 +00:00
|
|
|
return "$mainUrl/$url"
|
|
|
|
}
|
|
|
|
return url
|
|
|
|
}
|
|
|
|
|
2021-06-10 19:43:05 +00:00
|
|
|
fun sortUrls(urls: List<ExtractorLink>): List<ExtractorLink> {
|
|
|
|
return urls.sortedBy { t -> -t.quality }
|
|
|
|
}
|
2021-05-15 23:37:42 +00:00
|
|
|
|
2021-04-30 17:20:15 +00:00
|
|
|
data class Link(
|
|
|
|
val name: String,
|
2021-05-12 21:51:02 +00:00
|
|
|
val url: String,
|
2021-04-30 17:20:15 +00:00
|
|
|
val quality: Int?,
|
2021-05-12 21:51:02 +00:00
|
|
|
val referer: String?,
|
2021-04-30 17:20:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
enum class ShowStatus {
|
|
|
|
Completed,
|
|
|
|
Ongoing,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum class DubStatus {
|
2021-05-22 22:25:56 +00:00
|
|
|
Dubbed,
|
|
|
|
Subbed,
|
2021-04-30 17:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum class TvType {
|
|
|
|
Movie,
|
|
|
|
TvSeries,
|
|
|
|
Anime,
|
|
|
|
ONA,
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SearchResponse {
|
|
|
|
val name: String
|
2021-05-18 13:43:32 +00:00
|
|
|
val url: String // PUBLIC URL FOR OPEN IN APP
|
|
|
|
val slug: String // USED FOR INTERNAL DATA
|
2021-04-30 17:20:15 +00:00
|
|
|
val apiName: String
|
|
|
|
val type: TvType
|
|
|
|
val posterUrl: String?
|
|
|
|
val year: Int?
|
|
|
|
}
|
|
|
|
|
|
|
|
data class AnimeSearchResponse(
|
|
|
|
override val name: String,
|
|
|
|
override val url: String,
|
2021-05-18 13:43:32 +00:00
|
|
|
override val slug: String,
|
2021-04-30 17:20:15 +00:00
|
|
|
override val apiName: String,
|
|
|
|
override val type: TvType,
|
|
|
|
|
|
|
|
override val posterUrl: String?,
|
|
|
|
override val year: Int?,
|
|
|
|
|
|
|
|
val otherName: String?,
|
|
|
|
val dubStatus: EnumSet<DubStatus>?,
|
|
|
|
val dubEpisodes: Int?,
|
|
|
|
val subEpisodes: Int?,
|
|
|
|
) : SearchResponse
|
|
|
|
|
|
|
|
data class MovieSearchResponse(
|
|
|
|
override val name: String,
|
|
|
|
override val url: String,
|
2021-05-18 13:43:32 +00:00
|
|
|
override val slug: String,
|
2021-04-30 17:20:15 +00:00
|
|
|
override val apiName: String,
|
|
|
|
override val type: TvType,
|
|
|
|
|
|
|
|
override val posterUrl: String?,
|
|
|
|
override val year: Int?,
|
|
|
|
) : SearchResponse
|
|
|
|
|
|
|
|
data class TvSeriesSearchResponse(
|
|
|
|
override val name: String,
|
|
|
|
override val url: String,
|
2021-05-18 13:43:32 +00:00
|
|
|
override val slug: String,
|
2021-04-30 17:20:15 +00:00
|
|
|
override val apiName: String,
|
|
|
|
override val type: TvType,
|
|
|
|
|
|
|
|
override val posterUrl: String?,
|
|
|
|
override val year: Int?,
|
|
|
|
val episodes: Int?,
|
|
|
|
) : SearchResponse
|
|
|
|
|
|
|
|
interface LoadResponse {
|
|
|
|
val name: String
|
|
|
|
val url: String
|
|
|
|
val apiName: String
|
|
|
|
val type: TvType
|
|
|
|
val posterUrl: String?
|
|
|
|
val year: Int?
|
2021-05-22 22:25:56 +00:00
|
|
|
val plot: String?
|
2021-04-30 17:20:15 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:38:06 +00:00
|
|
|
fun LoadResponse.isEpisodeBased(): Boolean {
|
|
|
|
return this is AnimeLoadResponse || this is TvSeriesLoadResponse
|
|
|
|
}
|
|
|
|
|
2021-04-30 17:20:15 +00:00
|
|
|
data class AnimeLoadResponse(
|
2021-05-16 18:28:00 +00:00
|
|
|
val engName: String?,
|
|
|
|
val japName: String?,
|
2021-04-30 17:20:15 +00:00
|
|
|
override val name: String,
|
|
|
|
override val url: String,
|
|
|
|
override val apiName: String,
|
|
|
|
override val type: TvType,
|
|
|
|
|
|
|
|
override val posterUrl: String?,
|
|
|
|
override val year: Int?,
|
|
|
|
|
2021-06-14 16:58:43 +00:00
|
|
|
val dubEpisodes: ArrayList<String>?,
|
|
|
|
val subEpisodes: ArrayList<String>?,
|
2021-04-30 17:20:15 +00:00
|
|
|
val showStatus: ShowStatus?,
|
|
|
|
|
2021-05-22 22:25:56 +00:00
|
|
|
override val plot: String?,
|
2021-04-30 17:20:15 +00:00
|
|
|
val tags: ArrayList<String>?,
|
|
|
|
val synonyms: ArrayList<String>?,
|
|
|
|
|
|
|
|
val malId: Int?,
|
|
|
|
val anilistId: Int?,
|
|
|
|
) : LoadResponse
|
|
|
|
|
|
|
|
data class MovieLoadResponse(
|
|
|
|
override val name: String,
|
|
|
|
override val url: String,
|
|
|
|
override val apiName: String,
|
|
|
|
override val type: TvType,
|
|
|
|
val movieUrl: String,
|
|
|
|
|
|
|
|
override val posterUrl: String?,
|
|
|
|
override val year: Int?,
|
2021-05-22 22:25:56 +00:00
|
|
|
override val plot: String?,
|
2021-04-30 17:20:15 +00:00
|
|
|
|
|
|
|
val imdbId: Int?,
|
|
|
|
) : LoadResponse
|
|
|
|
|
|
|
|
data class TvSeriesLoadResponse(
|
|
|
|
override val name: String,
|
|
|
|
override val url: String,
|
|
|
|
override val apiName: String,
|
|
|
|
override val type: TvType,
|
|
|
|
val episodes: ArrayList<String>,
|
|
|
|
|
|
|
|
override val posterUrl: String?,
|
|
|
|
override val year: Int?,
|
2021-05-22 22:25:56 +00:00
|
|
|
override val plot: String?,
|
2021-04-30 17:20:15 +00:00
|
|
|
|
|
|
|
val showStatus: ShowStatus?,
|
|
|
|
val imdbId: Int?,
|
|
|
|
) : LoadResponse
|