cloudstream/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt

95 lines
2.3 KiB
Kotlin
Raw Normal View History

2021-05-19 18:44:02 +00:00
package com.lagradost.cloudstream3.utils
import com.lagradost.cloudstream3.extractors.*
2021-07-23 16:41:37 +00:00
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
2021-05-19 18:44:02 +00:00
data class ExtractorLink(
2021-05-20 15:22:28 +00:00
val source: String,
2021-05-19 18:44:02 +00:00
val name: String,
val url: String,
val referer: String,
val quality: Int,
val isM3u8: Boolean = false,
)
fun ExtractorLink.getId(): Int {
2021-05-28 13:38:06 +00:00
return url.hashCode()
}
2021-05-19 18:44:02 +00:00
enum class Qualities(var value: Int) {
Unknown(0),
SD(-1), // 360p - 480p
HD(1), // 720p
FullHd(2), // 1080p
UHD(3) // 4k
}
fun getQualityFromName(qualityName: String): Int {
return when (qualityName.replace("p", "").replace("P", "")) {
"360" -> Qualities.SD
"480" -> Qualities.SD
"720" -> Qualities.HD
"1080" -> Qualities.FullHd
"1440" -> Qualities.UHD // I KNOW KINDA MISLEADING
"2160" -> Qualities.UHD
"4k" -> Qualities.UHD
"4K" -> Qualities.UHD
else -> Qualities.Unknown
}.value
}
2021-05-19 18:44:02 +00:00
private val packedRegex = Regex("""eval\(function\(p,a,c,k,e,.*\)\)""")
fun getPacked(string: String): String? {
return packedRegex.find(string)?.value
}
fun getAndUnpack(string: String): String? {
val packedText = getPacked(string)
return JsUnpacker(packedText).unpack()
}
2021-05-20 15:22:28 +00:00
val extractorApis: Array<ExtractorApi> = arrayOf(
2021-05-19 18:44:02 +00:00
//AllProvider(),
Shiro(),
2021-07-23 11:59:41 +00:00
WcoStream(),
2021-05-19 18:44:02 +00:00
Mp4Upload(),
StreamTape(),
MixDrop(),
2021-07-23 16:41:37 +00:00
XStreamCdn(),
StreamSB(),
2021-05-19 18:44:02 +00:00
)
2021-05-20 15:22:28 +00:00
fun getExtractorApiFromName(name: String): ExtractorApi {
for (api in extractorApis) {
if (api.name == name) return api
}
return extractorApis[0]
}
fun requireReferer(name: String): Boolean {
return getExtractorApiFromName(name).requiresReferer
}
2021-05-19 18:44:02 +00:00
fun httpsify(url: String): String {
return if (url.startsWith("//")) "https:$url" else url
}
abstract class ExtractorApi {
abstract val name: String
abstract val mainUrl: String
abstract val requiresReferer: Boolean
2021-07-23 16:41:37 +00:00
fun getSafeUrl(url: String, referer: String? = null): List<ExtractorLink>? {
return normalSafeApiCall { getUrl(url, referer) }
}
/**
* Will throw errors, use getSafeUrl if you don't want to handle the exception yourself
*/
2021-05-19 18:44:02 +00:00
abstract fun getUrl(url: String, referer: String? = null): List<ExtractorLink>?
2021-05-20 15:22:28 +00:00
open fun getExtractorUrl(id: String): String {
2021-05-19 18:44:02 +00:00
return id
}
2021-07-23 11:59:41 +00:00
}