2021-05-19 18:44:02 +00:00
|
|
|
package com.lagradost.cloudstream3.utils
|
|
|
|
|
2021-08-25 22:16:20 +00:00
|
|
|
import com.lagradost.cloudstream3.SubtitleFile
|
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),
|
2021-08-24 21:06:40 +00:00
|
|
|
P360(-2), // 360p
|
|
|
|
P480(-1), // 480p
|
|
|
|
P720(1), // 720p
|
|
|
|
P1080(2), // 1080p
|
|
|
|
P1440(3), // 1440p
|
|
|
|
P2160(4) // 4k or 2160p
|
2021-05-19 18:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 22:31:41 +00:00
|
|
|
fun getQualityFromName(qualityName: String): Int {
|
|
|
|
return when (qualityName.replace("p", "").replace("P", "")) {
|
2021-08-24 21:06:40 +00:00
|
|
|
"360" -> Qualities.P360
|
|
|
|
"480" -> Qualities.P480
|
|
|
|
"720" -> Qualities.P720
|
|
|
|
"1080" -> Qualities.P1080
|
|
|
|
"1440" -> Qualities.P1440
|
|
|
|
"2160" -> Qualities.P2160
|
|
|
|
"4k" -> Qualities.P2160
|
|
|
|
"4K" -> Qualities.P2160
|
2021-06-16 22:31:41 +00:00
|
|
|
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-08-25 22:16:20 +00:00
|
|
|
fun loadExtractor(url: String, referer: String?, callback: (ExtractorLink) -> Unit) {
|
|
|
|
for (extractor in extractorApis) {
|
|
|
|
if (url.startsWith(extractor.mainUrl)) {
|
|
|
|
extractor.getSafeUrl(url, referer)?.forEach(callback)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-08-25 22:16:20 +00:00
|
|
|
Streamhub(),
|
2021-08-29 11:45:58 +00:00
|
|
|
DoodLaExtractor(),
|
|
|
|
DoodToExtractor(),
|
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
|
|
|
}
|