Added Crunchyroll in Allanime (#41)

* Added Crunchyroll in Allanime
This commit is contained in:
PokerFace 2023-03-14 19:33:31 +07:00 committed by GitHub
parent 97a17c0729
commit b1a9851fc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 20 deletions

View file

@ -1,5 +1,5 @@
// use an integer for version numbers
version = 8
version = 9
cloudstream {

View file

@ -360,11 +360,23 @@ class AllAnimeProvider : MainAPI() {
return false
}
private data class Stream(
@JsonProperty("format") val format: String? = null,
@JsonProperty("audio_lang") val audio_lang: String? = null,
@JsonProperty("hardsub_lang") val hardsub_lang: String? = null,
@JsonProperty("url") val url: String? = null,
)
private data class PortData(
@JsonProperty("streams") val streams: ArrayList<Stream>? = arrayListOf(),
)
private data class Links(
@JsonProperty("link") val link: String,
@JsonProperty("hls") val hls: Boolean?,
@JsonProperty("resolutionStr") val resolutionStr: String,
@JsonProperty("src") val src: String?
@JsonProperty("src") val src: String?,
@JsonProperty("portData") val portData: PortData? = null,
)
private data class AllAnimeVideoApiResponse(
@ -394,6 +406,16 @@ class AllAnimeProvider : MainAPI() {
val episode: Int
)
private suspend fun PortData.extractAcSources(callback: (ExtractorLink) -> Unit) {
this.streams?.filter { it.format == "adaptive_hls" && it.hardsub_lang == "en-US" }?.map { source ->
M3u8Helper.generateM3u8(
"Crunchyroll",
source.url ?: return@map,
"https://static.crunchyroll.com/",
).forEach(callback)
}
}
override suspend fun loadLinks(
data: String,
isCasting: Boolean,
@ -436,7 +458,11 @@ class AllAnimeProvider : MainAPI() {
val links = app.get(fixedLink).parsedSafe<AllAnimeVideoApiResponse>()?.links
?: emptyList()
links.forEach { server ->
if (server.hls != null && server.hls) {
when {
source.sourceName == "Ac" -> {
server.portData?.extractAcSources(callback)
}
server.hls != null && server.hls -> {
getM3u8Qualities(
server.link,
"$apiEndPoint/player?uri=" + (if (URI(server.link).host.isNotEmpty()) server.link else apiEndPoint + URI(
@ -444,7 +470,8 @@ class AllAnimeProvider : MainAPI() {
).path),
server.resolutionStr
).forEach(callback)
} else {
}
else -> {
callback(
ExtractorLink(
"AllAnime - " + URI(server.link).host,
@ -462,6 +489,7 @@ class AllAnimeProvider : MainAPI() {
}
}
}
}
return true
}