2021-05-19 18:44:02 +00:00
|
|
|
package com.lagradost.cloudstream3.utils
|
|
|
|
|
2021-07-30 01:14:53 +00:00
|
|
|
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,
|
2021-08-22 17:14:48 +00:00
|
|
|
override val url: String,
|
|
|
|
override val referer: String,
|
2021-05-19 18:44:02 +00:00
|
|
|
val quality: Int,
|
|
|
|
val isM3u8: Boolean = false,
|
2021-08-22 17:14:48 +00:00
|
|
|
) : VideoDownloadManager.IDownloadableMinimum
|
2021-05-19 18:44:02 +00:00
|
|
|
|
2021-08-22 17:14:48 +00:00
|
|
|
data class ExtractorSubtitleLink(
|
|
|
|
val name: String,
|
|
|
|
override val url: String,
|
|
|
|
override val referer: String,
|
|
|
|
) : VideoDownloadManager.IDownloadableMinimum
|
2021-05-28 13:38:06 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-06-16 22:31:41 +00:00
|
|
|
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
|
|
|
}
|