From b7b1f0ceeebbf2c857c59a88e19e039a2ca9dce4 Mon Sep 17 00:00:00 2001 From: hexated Date: Thu, 2 Feb 2023 15:28:22 +0700 Subject: [PATCH] [Sora] fixed missing anime in Sorastream --- .../main/kotlin/com/hexated/SoraExtractor.kt | 21 +++++++++------- .../src/main/kotlin/com/hexated/SoraStream.kt | 2 ++ .../src/main/kotlin/com/hexated/SoraUtils.kt | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt index 555d5b8c..4a43cede 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt @@ -800,6 +800,7 @@ object SoraExtractor : SoraStream() { suspend fun invokeSoraStream( title: String? = null, + isAnime: Boolean = false, year: Int? = null, season: Int? = null, episode: Int? = null, @@ -845,10 +846,9 @@ object SoraExtractor : SoraStream() { ) && (it.second == year || it.first.contains("Season $season", true)) } else -> { - it.first.contains( - "$title", - true - ) && it.second == year && it.first.contains("Season $season", true) + (if (isAnime) it.first.contains(Regex("(?i)$title\\s?($season|${season.toRomanNumeral()})")) else it.first.contains( + Regex("(?i)$title\\s?Season\\s$season") + )) && it.second == year } } } @@ -2034,7 +2034,6 @@ object SoraExtractor : SoraStream() { episode: Int? = null, subtitleCallback: (SubtitleFile) -> Unit, ) { - val watchSomuchAPI = "https://watchsomuch.tv" val id = imdbId?.removePrefix("tt") val epsId = app.post( "$watchSomuchAPI/Watch/ajMovieTorrents.aspx", @@ -2089,7 +2088,10 @@ object SoraExtractor : SoraStream() { "cf_cache_token" to "UKsVpQqBMxB56gBfhYKbfCVkRIXMh42pk6G4DdkXXoVh7j4BjV" ) val query = getIndexQuery(title, year, season, episode) - val search = app.get("$baymoviesAPI/0:search?q=$query&page_token=&page_index=0", headers = headers).text + val search = app.get( + "$baymoviesAPI/0:search?q=$query&page_token=&page_index=0", + headers = headers + ).text val media = searchIndex(title, season, episode, year, search) ?: return media.apmap { file -> @@ -2101,8 +2103,9 @@ object SoraExtractor : SoraStream() { val encryptedExpiry = base64Encode(CryptoAES.encrypt(key, expiry).toByteArray()) val worker = getConfig().workers.randomOrNull() ?: return@apmap null - val link = "https://api.$worker.workers.dev/download.aspx?file=$encryptedId&expiry=$encryptedExpiry&mac=$hmacSign" - if(!app.get(link).isSuccessful) return@apmap null + val link = + "https://api.$worker.workers.dev/download.aspx?file=$encryptedId&expiry=$encryptedExpiry&mac=$hmacSign" + if (!app.get(link).isSuccessful) return@apmap null val size = file.size?.toDouble() ?: return@apmap null val sizeFile = "%.2f GB".format(bytesToGigaBytes(size)) val tags = Regex("\\d{3,4}[pP]\\.?(.*?)\\.(mkv|mp4)").find( @@ -2229,7 +2232,7 @@ object SoraExtractor : SoraStream() { }).text.let { fixUrl(it, apiUrl) }.encodeUrl() - if(!app.get(path).isSuccessful) return@apmap null + if (!app.get(path).isSuccessful) return@apmap null val size = file.size?.toDouble() ?: return@apmap null val sizeFile = "%.2f GB".format(bytesToGigaBytes(size)) val quality = diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraStream.kt b/SoraStream/src/main/kotlin/com/hexated/SoraStream.kt index 3188828b..8f28b7bd 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraStream.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraStream.kt @@ -116,6 +116,7 @@ open class SoraStream : TmdbProvider() { const val chillmovies0API = "https://chill.aicirou.workers.dev/0:" const val chillmovies1API = "https://chill.aicirou.workers.dev/1:" const val gamMoviesAPI = "https://drive.gamick.workers.dev/0:" + const val watchSomuchAPI = "https://watchsomuch.tv" // sub only fun getType(t: String?): TvType { return when (t) { @@ -331,6 +332,7 @@ open class SoraStream : TmdbProvider() { { invokeSoraStream( res.title, + res.isAnime, res.year, res.season, res.episode, diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt b/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt index 77de8efa..919a0dd8 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt @@ -847,4 +847,28 @@ suspend fun loadLinksWithWebView( true ) ) +} + +fun Int.toRomanNumeral(): String = Symbol.closestBelow(this) + .let { symbol -> + if (symbol != null) { + "$symbol${(this - symbol.decimalValue).toRomanNumeral()}" + } else { + "" + } + } + +private enum class Symbol(val decimalValue: Int) { + I(1), + IV(4), + V(5), + IX(9), + X(10); + + companion object { + fun closestBelow(value: Int) = + values() + .sortedByDescending { it.decimalValue } + .firstOrNull { value >= it.decimalValue } + } } \ No newline at end of file