sora: fix Crunchyroll

This commit is contained in:
hexated 2023-03-14 23:13:42 +07:00
parent 1677f754d0
commit d9cec35f8a
3 changed files with 31 additions and 22 deletions

View File

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

View File

@ -1504,17 +1504,17 @@ object SoraExtractor : SoraStream() {
callback: (ExtractorLink) -> Unit
) {
val id = searchCrunchyrollAnimeId(title ?: return) ?: return
val detail = app.get("$consumetCrunchyrollAPI/info/$id?fetchAllSeasons=true",timeout = 600L).text
val detail = app.get("$consumetCrunchyrollAPI/info/$id?fetchAllSeasons=true", timeout = 600L).text
val epsId = tryParseJson<CrunchyrollDetails>(detail)?.findCrunchyrollId(
title,
season,
episode,
epsTitle
) ?: return
)
epsId.apmap {
epsId?.apmap {
delay(2000)
val json =
app.get("$consumetCrunchyrollAPI/watch/${it?.first ?: return@apmap null}",timeout = 600L)
app.get("$consumetCrunchyrollAPI/watch/${it?.first?.id ?: return@apmap null}", timeout = 600L)
.parsedSafe<ConsumetSourcesResponse>()
json?.sources?.map source@{ source ->
@ -1533,7 +1533,7 @@ object SoraExtractor : SoraStream() {
json?.subtitles?.map subtitle@{ sub ->
subtitleCallback.invoke(
SubtitleFile(
fixCrunchyrollLang(sub.lang ?: return@subtitle null) ?: sub.lang,
"${fixCrunchyrollLang(sub.lang ?: return@subtitle null) ?: sub.lang} [ass]",
sub.url ?: return@subtitle null
)
)
@ -2927,8 +2927,15 @@ data class ConsumetDetails(
@JsonProperty("episodes") val episodes: ArrayList<ConsumetEpisodes>? = arrayListOf(),
)
data class CrunchyrollEpisodes(
@JsonProperty("id") val id: String? = null,
@JsonProperty("title") val title: String? = null,
@JsonProperty("episode_number") val episode_number: Int? = null,
@JsonProperty("season_number") val season_number: Int? = null,
)
data class CrunchyrollDetails(
@JsonProperty("episodes") val episodes: HashMap<String, List<HashMap<String, String>>>? = hashMapOf(),
@JsonProperty("episodes") val episodes: HashMap<String, List<CrunchyrollEpisodes>>? = hashMapOf(),
)
data class ConsumetResults(

View File

@ -38,7 +38,6 @@ import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.min
val soraAPI = base64DecodeAPI("cA==YXA=cy8=Y20=di8=LnQ=b2s=a2w=bG8=aS4=YXA=ZS0=aWw=b2I=LW0=Z2E=Ly8=czo=dHA=aHQ=")
@ -742,25 +741,28 @@ suspend fun searchCrunchyrollAnimeId(title: String): String? {
}
fun CrunchyrollDetails.findCrunchyrollId(
title: String?,
season: Int?,
episode: Int?,
epsTitle: String?
): List<Pair<String?, String?>?> {
val sub = when (title) {
"One Piece" -> this.episodes?.get("subbed13")?.matchingEpisode(episode) to "Raw"
"Hunter x Hunter" -> this.episodes?.get("subbed5")?.matchingEpisode(episode) to "Raw"
else -> this.episodes?.get("subbed$season")?.matchingEpisode(episode) to "Raw"
}
val dub = this.episodes?.get("English Dub$season")?.matchingEpisode(episode) to "English Dub"
): List<Pair<CrunchyrollEpisodes?, String?>?> {
val sub = this.episodes?.filterKeys { it.contains("subbed") }.matchingEpisode(epsTitle, season, episode) to "Raw"
val dub = this.episodes?.filterKeys { it.contains("English Dub") }.matchingEpisode(epsTitle, season, episode) to "English Dub"
return listOf(sub, dub)
}
fun List<HashMap<String, String>>?.matchingEpisode(episode: Int?): String? {
return this?.find {
it["episode_number"] == "$episode" || indexOf(it).plus(1) == episode
}?.get("id")
fun Map<String, List<CrunchyrollEpisodes>>?.matchingEpisode(
epsTitle: String?,
season: Int?,
episode: Int?
): CrunchyrollEpisodes? {
return this?.mapNotNull { eps ->
eps.value.find {
(it.episode_number == episode && it.season_number == season) || it.title.equals(
epsTitle,
true
)
} ?: eps.value.find { it.episode_number == episode }
}?.firstOrNull()
}
fun getEpisodeSlug(