From d9cec35f8af5b099d7b6d6f9558601970e840f6b Mon Sep 17 00:00:00 2001 From: hexated Date: Tue, 14 Mar 2023 23:13:42 +0700 Subject: [PATCH] sora: fix Crunchyroll --- SoraStream/build.gradle.kts | 2 +- .../main/kotlin/com/hexated/SoraExtractor.kt | 21 ++++++++----- .../src/main/kotlin/com/hexated/SoraUtils.kt | 30 ++++++++++--------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/SoraStream/build.gradle.kts b/SoraStream/build.gradle.kts index b88310a1..606e959b 100644 --- a/SoraStream/build.gradle.kts +++ b/SoraStream/build.gradle.kts @@ -1,5 +1,5 @@ // use an integer for version numbers -version = 104 +version = 105 cloudstream { diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt index e2def0eb..2108a0ba 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt @@ -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(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() 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? = 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>>? = hashMapOf(), + @JsonProperty("episodes") val episodes: HashMap>? = hashMapOf(), ) data class ConsumetResults( diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt b/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt index 63ea8381..0b5548b0 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt @@ -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?> { - 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?> { + 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>?.matchingEpisode(episode: Int?): String? { - return this?.find { - it["episode_number"] == "$episode" || indexOf(it).plus(1) == episode - }?.get("id") +fun Map>?.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(