Extracted quality from AllAnime m3u8 streams. (Untested)

This commit is contained in:
Arjix 2021-10-30 23:20:46 +03:00 committed by GitHub
parent 1252ad4531
commit 44100c4e09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
package com.lagradost.cloudstream3.animeproviders
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.network.get
import com.lagradost.cloudstream3.network.text
import com.lagradost.cloudstream3.utils.ExtractorLink
@ -27,6 +28,8 @@ class AllAnimeProvider : MainAPI() {
override val hasMainPage: Boolean
get() = false
private val hlsHelper = M3u8Helper()
private fun getStatus(t: String): ShowStatus {
return when (t) {
"Finished" -> ShowStatus.Completed
@ -244,6 +247,21 @@ class AllAnimeProvider : MainAPI() {
@JsonProperty("episodeIframeHead") val episodeIframeHead: String
)
private fun getM3u8Qualities(m3u8Link: String, referer: String): ArrayList<ExtractorLink> {
return ArrayList(hlsHelper.m3u8Generation(M3u8Helper.M3u8Stream(m3u8Link, null), true).map { stream ->
val qualityString = if ((stream.quality ?: 0) == 0) "" else "${stream.quality}p"
ExtractorLink(
this.name,
"${this.name} $qualityString",
stream.streamUrl,
referer,
getQualityFromName(stream.quality.toString()),
true,
stream.headers
)
})
}
override fun loadLinks(
data: String,
isCasting: Boolean,
@ -264,6 +282,9 @@ class AllAnimeProvider : MainAPI() {
if (Regex("""streaming\.php\?""").matches(link)) {
// for now ignore
} else if (!embedIsBlacklisted(link)) {
if (URI(link).path.contains(".m3u")) {
getM3u8Qualities(link, referer).forEach(callback)
} else {
callback(
ExtractorLink(
"AllAnime - " + URI(link).host,
@ -271,10 +292,11 @@ class AllAnimeProvider : MainAPI() {
link,
data,
getQualityFromName("1080"),
URI(link).path.contains(".m3u")
false
)
)
}
}
} else {
link = apiEndPoint + URI(link).path + ".json?" + URI(link).query
val response = get(link)
@ -282,18 +304,22 @@ class AllAnimeProvider : MainAPI() {
if (response.code < 400) {
val links = mapper.readValue<AllAnimeVideoApiResponse>(response.text).links
links.forEach { server ->
if (server.hls != null && server.hls) {
getM3u8Qualities(server.link, "$apiEndPoint/player?uri=" + (if (URI(server.link).host.isNotEmpty()) server.link else apiEndPoint + URI(server.link).path)).forEach(callback)
} else {
callback(ExtractorLink(
"AllAnime - " + URI(server.link).host,
server.resolutionStr,
server.link,
"$apiEndPoint/player?uri=" + (if (URI(server.link).host.isNotEmpty()) server.link else apiEndPoint + URI(server.link).path),
getQualityFromName("1080"),
server.hls != null && server.hls
false
))
}
}
}
}
}
return true
}