From 65c3ff8d2e0c0f8953cb99d49e9f3c93ee1f4f4c Mon Sep 17 00:00:00 2001 From: hexated Date: Thu, 19 Jan 2023 09:51:04 +0700 Subject: [PATCH] [Sora] fixed Crunchyroll --- SoraStream/build.gradle.kts | 2 +- .../main/kotlin/com/hexated/SoraExtractor.kt | 44 +++++++++++-------- .../src/main/kotlin/com/hexated/SoraStream.kt | 2 +- .../src/main/kotlin/com/hexated/SoraUtils.kt | 22 ++++++++++ 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/SoraStream/build.gradle.kts b/SoraStream/build.gradle.kts index fff4c418..2c00a686 100644 --- a/SoraStream/build.gradle.kts +++ b/SoraStream/build.gradle.kts @@ -1,5 +1,5 @@ // use an integer for version numbers -version = 74 +version = 75 cloudstream { diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt index 6884be58..a7657482 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt @@ -1369,10 +1369,10 @@ object SoraExtractor : SoraStream() { } val videoQuality = - Regex("\\d{3,4}p\\.?(.*?)\\[").find(quality)?.groupValues?.getOrNull(1)?.trim() + Regex("\\d{3,4}[Pp]\\.?(.*?)\\[").find(quality)?.groupValues?.getOrNull(1)?.trim() ?: "" val qualities = - Regex("(\\d{3,4})p").find(quality)?.groupValues?.getOrNull(1)?.toIntOrNull() + Regex("(\\d{3,4})[Pp]").find(quality)?.groupValues?.getOrNull(1)?.toIntOrNull() ?: Qualities.Unknown.value val size = Regex("(?i)\\[(\\S+\\s?(gb|mb))[]/]").find(quality)?.groupValues?.getOrNull(1) @@ -1674,38 +1674,40 @@ object SoraExtractor : SoraStream() { } ?: return val detail = app.get("$consumetCrunchyrollAPI/info?id=${id.id}&mediaType=series").text - val episodeId = tryParseJson(detail)?.episodes?.filter { - (it.number == episode || it.title.equals(epsTitle, true)) - }?.let { eps -> - listOf(eps.filter { it.type == "Subbed" }.map { it.id } - .getOrNull(season?.minus(1) ?: 0) to "Subbed", - eps.filter { it.type == "English Dub" }.map { it.id } - .getOrNull(season?.minus(1) ?: 0) to "English Dub") - } + val epsId = tryParseJson(detail)?.findCrunchyrollId( + title, + season, + episode, + epsTitle + ) ?: return - episodeId?.apmap { (id, type) -> + epsId.apmap { val json = - app.get("$consumetCrunchyrollAPI/watch?episodeId=${id ?: return@apmap null}&format=srt") + app.get("$consumetCrunchyrollAPI/watch?episodeId=${it?.first ?: return@apmap null}") .parsedSafe() json?.sources?.map source@{ source -> - M3u8Helper.generateM3u8( - "Crunchyroll [$type]", - source.url ?: return@source null, - "", - ).forEach(callback) + callback.invoke( + ExtractorLink( + "Crunchyroll [${it.second ?: ""}]", + "Crunchyroll [${it.second ?: ""}]", + source.url ?: return@source null, + "https://static.crunchyroll.com/", + getQualityFromName(source.quality), + true + ) + ) } json?.subtitles?.map subtitle@{ sub -> subtitleCallback.invoke( SubtitleFile( - sub.lang?.replace(Regex("\\[\\S+]"), "")?.trim() ?: "", + sub.lang ?: "", sub.url ?: return@subtitle null ) ) } } - } suspend fun invokeMoviesbay( @@ -2151,6 +2153,10 @@ data class ConsumetDetails( @JsonProperty("episodes") val episodes: ArrayList? = arrayListOf(), ) +data class CrunchyrollDetails( + @JsonProperty("episodes") val episodes: HashMap>>? = hashMapOf(), +) + data class ConsumetResults( @JsonProperty("id") val id: String? = null, @JsonProperty("title") val title: String? = null, diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraStream.kt b/SoraStream/src/main/kotlin/com/hexated/SoraStream.kt index 679aeccb..62474e75 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraStream.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraStream.kt @@ -92,7 +92,7 @@ open class SoraStream : TmdbProvider() { const val uhdmoviesAPI = "https://uhdmovies.org.in" const val fwatayakoAPI = "https://5100.svetacdn.in" const val gMoviesAPI = "https://gdrivemovies.xyz" - const val fdMoviesAPI = "https://freedrivemovie.com" + const val fdMoviesAPI = "https://freedrivemovie.lol" const val m4uhdAPI = "https://m4uhd.tv" const val tvMoviesAPI = "https://www.tvseriesnmovies.com" const val moviezAddAPI = "https://m.bloginguru.info" diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt b/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt index ad49ba0b..af753ad7 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt @@ -468,6 +468,28 @@ fun Document.findTvMoviesIframe(): String? { ?.substringBefore("'>") } +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" + + return listOf(sub, dub) +} + +fun List>?.matchingEpisode(episode: Int?): String? { + return this?.find { + it["episode_number"] == "$episode" + }?.get("id") +} + fun String?.fixTitle(): String? { return this?.replace(Regex("[!%:'?]|( &)"), "")?.replace(" ", "-")?.lowercase() ?.replace("-–-", "-")