animepahe: fix getting details and links

This commit is contained in:
jmir1
2022-04-19 23:15:54 +02:00
parent 1146a8f0fd
commit 30454df548
3 changed files with 28 additions and 16 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'AnimePahe'
pkgNameSuffix = 'en.animepahe'
extClass = '.AnimePahe'
extVersionCode = 13
extVersionCode = 14
libVersion = '12'
}

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.animeextension.en.animepahe
import android.app.Application
import android.content.SharedPreferences
import android.util.Log
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
@ -76,16 +77,19 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
override val client: OkHttpClient = network.cloudflareClient
override fun animeDetailsRequest(anime: SAnime): Request {
val responseString = runBlocking {
val animeId = anime.url.substringAfterLast("?anime_id=")
val session = getSession(anime.title, animeId)
return GET("$baseUrl/anime/$session?anime_id=$animeId")
}
private fun getSession(title: String, animeId: String): String {
return runBlocking {
withContext(Dispatchers.IO) {
client.newCall(GET("$baseUrl/api?m=search&q=${anime.title}"))
client.newCall(GET("$baseUrl/api?m=search&q=$title"))
.execute().body!!.string()
}
}
val animeId = anime.url.substringAfterLast("?anime_id=")
val session = responseString.substringAfter("\"id\":$animeId")
}.substringAfter("\"id\":$animeId")
.substringAfter("\"session\":\"").substringBefore("\"")
return GET("$baseUrl/anime/$session?anime_id=$animeId")
}
override fun animeDetailsParse(response: Response): SAnime {
@ -170,7 +174,9 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
override fun episodeListRequest(anime: SAnime): Request {
val animeId = anime.url.substringAfterLast("?anime_id=")
return GET("$baseUrl/api?m=release&id=$animeId&sort=episode_desc&page=1")
val session = getSession(anime.title, animeId)
Log.i("bruh", session)
return GET("$baseUrl/api?m=release&id=$session&sort=episode_desc&page=1")
}
override fun episodeListParse(response: Response): List<SEpisode> {
@ -224,16 +230,16 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
val videos = mutableListOf<Video>()
for (item in array) {
val quality = item.jsonObject.keys.first()
val adflyLink = item.jsonObject[quality]!!.jsonObject["kwik_pahewin"]!!.jsonPrimitive.content
val paheWinLink = item.jsonObject[quality]!!.jsonObject["kwik_pahewin"]!!.jsonPrimitive.content
val kwikLink = item.jsonObject[quality]!!.jsonObject["kwik"]!!.jsonPrimitive.content
val audio = item.jsonObject[quality]!!.jsonObject["audio"]!!
val qualityString = if (audio is JsonNull) "${quality}p" else "${quality}p (" + audio.jsonPrimitive.content + " audio)"
videos.add(getVideo(adflyLink, kwikLink, qualityString))
videos.add(getVideo(paheWinLink, kwikLink, qualityString))
}
return videos
}
private fun getVideo(adflyUrl: String, kwikUrl: String, quality: String): Video {
private fun getVideo(paheUrl: String, kwikUrl: String, quality: String): Video {
return if (preferences.getBoolean("preferred_link_type", false)) {
val videoUrl = KwikExtractor(client).getHlsStreamUrl(kwikUrl, referer = baseUrl)
Video(
@ -241,7 +247,7 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
Headers.headersOf("referer", "https://kwik.cx")
)
} else {
val videoUrl = KwikExtractor(client).getStreamUrlFromKwik(adflyUrl)
val videoUrl = KwikExtractor(client).getStreamUrlFromKwik(paheUrl)
Video(videoUrl, quality, videoUrl, null)
}
}

View File

@ -53,13 +53,19 @@ class KwikExtractor(private val client: OkHttpClient) {
val urlParts = substring.split("|").reversed()
assert(urlParts.lastIndex == 8)
return urlParts[0] + "://" + urlParts[1] + "-" + urlParts[2] + "." + urlParts[3] + "." +
urlParts[4] + "." + urlParts[5] + "/" + urlParts[6] + "/" + urlParts[7] + "/" +
urlParts[8] + "/uwu.m3u8"
urlParts[4] + "." + urlParts[5] + "/" + urlParts[6] + "/" + urlParts[7] + "/" +
urlParts[8] + "/uwu.m3u8"
}
fun getStreamUrlFromKwik(adflyUri: String): String {
fun getStreamUrlFromKwik(paheUrl: String): String {
val noRedirects = client.newBuilder()
.followRedirects(false)
.followSslRedirects(false)
.build()
val kwikUrl = "https://" + noRedirects.newCall(GET("$paheUrl/i")).execute()
.header("location")!!.substringAfterLast("https://")
val fContent =
client.newCall(GET(adflyUri, Headers.headersOf("referer", "https://kwik.cx/"))).execute()
client.newCall(GET(kwikUrl, Headers.headersOf("referer", "https://kwik.cx/"))).execute()
cookies += (fContent.header("set-cookie")!!)
val fContentString = fContent.body!!.string()