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 // use an integer for version numbers
version = 8 version = 9
cloudstream { cloudstream {

View File

@ -360,11 +360,23 @@ class AllAnimeProvider : MainAPI() {
return false 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( private data class Links(
@JsonProperty("link") val link: String, @JsonProperty("link") val link: String,
@JsonProperty("hls") val hls: Boolean?, @JsonProperty("hls") val hls: Boolean?,
@JsonProperty("resolutionStr") val resolutionStr: String, @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( private data class AllAnimeVideoApiResponse(
@ -394,6 +406,16 @@ class AllAnimeProvider : MainAPI() {
val episode: Int 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( override suspend fun loadLinks(
data: String, data: String,
isCasting: Boolean, isCasting: Boolean,
@ -436,7 +458,11 @@ class AllAnimeProvider : MainAPI() {
val links = app.get(fixedLink).parsedSafe<AllAnimeVideoApiResponse>()?.links val links = app.get(fixedLink).parsedSafe<AllAnimeVideoApiResponse>()?.links
?: emptyList() ?: emptyList()
links.forEach { server -> links.forEach { server ->
if (server.hls != null && server.hls) { when {
source.sourceName == "Ac" -> {
server.portData?.extractAcSources(callback)
}
server.hls != null && server.hls -> {
getM3u8Qualities( getM3u8Qualities(
server.link, server.link,
"$apiEndPoint/player?uri=" + (if (URI(server.link).host.isNotEmpty()) server.link else apiEndPoint + URI( "$apiEndPoint/player?uri=" + (if (URI(server.link).host.isNotEmpty()) server.link else apiEndPoint + URI(
@ -444,7 +470,8 @@ class AllAnimeProvider : MainAPI() {
).path), ).path),
server.resolutionStr server.resolutionStr
).forEach(callback) ).forEach(callback)
} else { }
else -> {
callback( callback(
ExtractorLink( ExtractorLink(
"AllAnime - " + URI(server.link).host, "AllAnime - " + URI(server.link).host,
@ -462,6 +489,7 @@ class AllAnimeProvider : MainAPI() {
} }
} }
} }
}
return true return true
} }