9anime: fix vrf name and clean up code (#1396)
This commit is contained in:
@ -6,7 +6,7 @@ ext {
|
|||||||
extName = '9anime'
|
extName = '9anime'
|
||||||
pkgNameSuffix = 'en.nineanime'
|
pkgNameSuffix = 'en.nineanime'
|
||||||
extClass = '.NineAnime'
|
extClass = '.NineAnime'
|
||||||
extVersionCode = 36
|
extVersionCode = 37
|
||||||
libVersion = '13'
|
libVersion = '13'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,9 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
throw Exception("Not used")
|
throw Exception("Not used")
|
||||||
|
|
||||||
private fun searchAnimeRequest(page: Int, query: String, filters: NineAnimeFilters.FilterSearchParams): Request {
|
private fun searchAnimeRequest(page: Int, query: String, filters: NineAnimeFilters.FilterSearchParams): Request {
|
||||||
val vrf = if (query.isNotBlank()) vrfInterceptor.getVrf(query) else ""
|
val vrf = (if (query.isNotBlank()) vrfInterceptor.getVrf(query) else "").let {
|
||||||
|
java.net.URLEncoder.encode(it, "utf-8")
|
||||||
|
}
|
||||||
|
|
||||||
var url = "$baseUrl/filter?keyword=$query"
|
var url = "$baseUrl/filter?keyword=$query"
|
||||||
|
|
||||||
@ -119,7 +121,7 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
if (filters.rating.isNotBlank()) url += filters.rating
|
if (filters.rating.isNotBlank()) url += filters.rating
|
||||||
|
|
||||||
return GET(
|
return GET(
|
||||||
"$url&sort=${filters.sort}&vrf=${java.net.URLEncoder.encode(vrf, "utf-8")}&page=$page",
|
"$url&sort=${filters.sort}&$VRF_NAME=$vrf&page=$page",
|
||||||
headers = Headers.headersOf("Referer", "$baseUrl/"),
|
headers = Headers.headersOf("Referer", "$baseUrl/"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -160,9 +162,9 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
override fun episodeListRequest(anime: SAnime): Request {
|
override fun episodeListRequest(anime: SAnime): Request {
|
||||||
val id = client.newCall(GET(baseUrl + anime.url)).execute().asJsoup()
|
val id = client.newCall(GET(baseUrl + anime.url)).execute().asJsoup()
|
||||||
.selectFirst("div[data-id]")!!.attr("data-id")
|
.selectFirst("div[data-id]")!!.attr("data-id")
|
||||||
val vrf = getVrf(id)
|
val vrf = java.net.URLEncoder.encode(callConsumet(id, "vrf"), "utf-8")
|
||||||
return GET(
|
return GET(
|
||||||
"$baseUrl/ajax/episode/list/$id?vrf=${java.net.URLEncoder.encode(vrf, "utf-8")}",
|
"$baseUrl/ajax/episode/list/$id?$VRF_NAME=$vrf",
|
||||||
headers = Headers.headersOf("url", anime.url),
|
headers = Headers.headersOf("url", anime.url),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -199,8 +201,8 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
|
|
||||||
override fun videoListRequest(episode: SEpisode): Request {
|
override fun videoListRequest(episode: SEpisode): Request {
|
||||||
val ids = episode.url.substringBefore("&")
|
val ids = episode.url.substringBefore("&")
|
||||||
val vrf = getVrf(ids)
|
val vrf = java.net.URLEncoder.encode(callConsumet(ids, "vrf"), "utf-8")
|
||||||
val url = "/ajax/server/list/$ids?vrf=${java.net.URLEncoder.encode(vrf, "utf-8")}"
|
val url = "/ajax/server/list/$ids?$VRF_NAME=$vrf"
|
||||||
val epurl = episode.url.substringAfter("epurl=")
|
val epurl = episode.url.substringAfter("epurl=")
|
||||||
return GET(baseUrl + url, headers = Headers.headersOf("url", epurl))
|
return GET(baseUrl + url, headers = Headers.headersOf("url", epurl))
|
||||||
}
|
}
|
||||||
@ -262,26 +264,22 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun extractVideoConsumet(server: Triple<String, String, String>, epUrl: String): List<Video> {
|
private fun extractVideoConsumet(server: Triple<String, String, String>, epUrl: String): List<Video> {
|
||||||
val vrf = getVrf(server.second)
|
val vrf = java.net.URLEncoder.encode(callConsumet(server.second, "vrf"), "utf-8")
|
||||||
val referer = Headers.headersOf("referer", epUrl)
|
val referer = Headers.headersOf("referer", epUrl)
|
||||||
val response = client.newCall(
|
val response = client.newCall(
|
||||||
GET("$baseUrl/ajax/server/${server.second}?vrf=$vrf", headers = referer),
|
GET("$baseUrl/ajax/server/${server.second}?$VRF_NAME=$vrf", headers = referer),
|
||||||
).execute()
|
).execute()
|
||||||
if (response.code != 200) return emptyList()
|
if (response.code != 200) return emptyList()
|
||||||
val videoList = mutableListOf<Video>()
|
val videoList = mutableListOf<Video>()
|
||||||
|
runCatching {
|
||||||
val parsed = json.decodeFromString<ServerResponse>(response.body.string())
|
val parsed = json.decodeFromString<ServerResponse>(response.body.string())
|
||||||
val embedLink = client.newCall(
|
val embedLink = callConsumet(parsed.result.url, "decrypt")
|
||||||
GET("https://api.consumet.org/anime/9anime/helper?query=${parsed.result.url}&action=decrypt"),
|
|
||||||
).execute().body.string().substringAfter("vrf\":\"").substringBefore("\"")
|
|
||||||
|
|
||||||
val embedReferer = Headers.headersOf("Referer", embedLink)
|
val embedReferer = Headers.headersOf("Referer", embedLink)
|
||||||
runCatching {
|
|
||||||
when (server.third) {
|
when (server.third) {
|
||||||
"vidstream" -> {
|
"vidstream" -> {
|
||||||
val vizId = embedLink.substringAfter("embed/").substringBefore("?")
|
val vizId = embedLink.substringAfter("embed/").substringBefore("?")
|
||||||
val playlistUrl = client.newCall(
|
val playlistUrl = callConsumet(vizId, "vizcloud")
|
||||||
GET("https://api.consumet.org/anime/9anime/helper?query=$vizId&action=vizcloud"),
|
|
||||||
).execute().body.string().substringAfter("file\":\"").substringBefore("\"")
|
|
||||||
val playlist = client.newCall(GET(playlistUrl, embedReferer)).execute()
|
val playlist = client.newCall(GET(playlistUrl, embedReferer)).execute()
|
||||||
videoList.addAll(
|
videoList.addAll(
|
||||||
parseVizPlaylist(
|
parseVizPlaylist(
|
||||||
@ -320,10 +318,16 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getVrf(query: String): String {
|
private fun callConsumet(query: String, action: String): String {
|
||||||
return client.newCall(
|
return client.newCall(
|
||||||
GET("https://api.consumet.org/anime/9anime/helper?query=$query&action=vrf"),
|
GET("https://api.consumet.org/anime/9anime/helper?query=$query&action=$action"),
|
||||||
).execute().body.string().substringAfter("vrf\":\"").substringBefore("\"")
|
).execute().body.string().let {
|
||||||
|
if (action == "vizcloud") {
|
||||||
|
it.substringAfter("file\":\"").substringBefore("\"")
|
||||||
|
} else {
|
||||||
|
it.substringAfter("vrf\":\"").substringBefore("\"")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Int.toBoolean() = this == 1
|
private fun Int.toBoolean() = this == 1
|
||||||
@ -412,4 +416,8 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
private fun <A, B> Iterable<A>.parallelMap(f: suspend (A) -> B): List<B> = runBlocking {
|
private fun <A, B> Iterable<A>.parallelMap(f: suspend (A) -> B): List<B> = runBlocking {
|
||||||
map { async(Dispatchers.Default) { f(it) } }.awaitAll()
|
map { async(Dispatchers.Default) { f(it) } }.awaitAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val VRF_NAME = "vrf250"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user