9Anime: Json error fix & http error fix (#1150)

http error depends on how good your network is but with the new js it should be fixed for the most people
This commit is contained in:
LuftVerbot
2023-01-09 23:55:40 +01:00
committed by GitHub
parent 31f2f4a98c
commit aec31b2889
4 changed files with 28 additions and 19 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = '9anime' extName = '9anime'
pkgNameSuffix = 'en.nineanime' pkgNameSuffix = 'en.nineanime'
extClass = '.NineAnime' extClass = '.NineAnime'
extVersionCode = 24 extVersionCode = 25
libVersion = '13' libVersion = '13'
} }

View File

@ -52,7 +52,7 @@ class JsInterceptor(private val lang: String) : Interceptor {
// JavaSrcipt gets the Dub or Sub link of vidstream // JavaSrcipt gets the Dub or Sub link of vidstream
val jsScript = """ val jsScript = """
(function(){ (function(){
setTimeout(function(){ window.onload = (function() {
let el = document.querySelector('div[data-type="$lang"] ul li[data-sv-id="41"]'); let el = document.querySelector('div[data-type="$lang"] ul li[data-sv-id="41"]');
let e = document.createEvent('HTMLEvents'); let e = document.createEvent('HTMLEvents');
e.initEvent('click',true,true); e.initEvent('click',true,true);
@ -64,8 +64,8 @@ class JsInterceptor(private val lang: String) : Interceptor {
window.android.passPayload(entry.name); window.android.passPayload(entry.name);
} }
}); });
}, 2000); }, 5000);
}, 1000); })();
})();""" })();"""
val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap() val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap()

View File

@ -52,19 +52,28 @@ class JsVizInterceptor(private val embedLink: String) : Interceptor {
// JavaSrcipt creates Iframe on vidstream page to bypass iframe-cors and gets the sourceUrl // JavaSrcipt creates Iframe on vidstream page to bypass iframe-cors and gets the sourceUrl
val jsScript = """ val jsScript = """
(function(){ (function(){
const html = '<iframe src="$embedLink" allow="autoplay; fullscreen" allowfullscreen="yes" scrolling="no" style="width: 100%; height: 100%; overflow: hidden;" frameborder="no"></iframe>'; const html = '<iframe src="$embedLink" allow="autoplay; fullscreen" allowfullscreen="yes" scrolling="no" style="width: 100%; height: 100%; overflow: hidden;" frameborder="no" onload="handleIframeLoad()"></iframe>';
document.body.innerHTML += html; document.body.innerHTML += html;
setTimeout(function() { const iframe = document.querySelector('iframe');
const iframe = document.querySelector('iframe');
const entries = iframe.contentWindow.performance.getEntries(); const originalOpen = iframe.contentWindow.XMLHttpRequest.prototype.open;
entries.forEach((entry) => { iframe.contentWindow.XMLHttpRequest.prototype.open = function(method, url, async) {
if(entry.initiatorType.includes("xmlhttprequest")){ if (!url.includes("ping") && !url.includes("/assets/") && !url.includes("thumbnails") && !url.includes("jpg") && !url.includes("m3u8")) {
if(!entry.name.includes("/ping/") && !entry.name.includes("/assets/")){ if (url == null) {
window.android.passPayload(entry.name); const entries = iframe.contentWindow.performance.getEntries();
} entries.forEach((entry) => {
if (entry.initiatorType.includes("xmlhttprequest")) {
if (!entry.name.includes("/ping/") && !entry.name.includes("/assets/") && !entry.name.includes("thumbnails")) {
window.android.passPayload(entry.name);
}
}
});
} else {
window.android.passPayload("https://" + document.domain + "/" + url);
} }
}); }
}, 2000); originalOpen.apply(this, arguments);
}
})(); })();
""" """

View File

@ -71,7 +71,7 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val id = client.newCall(GET(baseUrl + anime.url)).execute().asJsoup().selectFirst("div[data-id]").attr("data-id") val id = client.newCall(GET(baseUrl + anime.url)).execute().asJsoup().selectFirst("div[data-id]").attr("data-id")
val jsVrfInterceptor = client.newBuilder().addInterceptor(JsVrfInterceptor(id, baseUrl)).build() val jsVrfInterceptor = client.newBuilder().addInterceptor(JsVrfInterceptor(id, baseUrl)).build()
val vrf = jsVrfInterceptor.newCall(GET("$baseUrl/filter")).execute().request.header("url").toString() val vrf = jsVrfInterceptor.newCall(GET("$baseUrl/filter")).execute().request.header("url").toString()
return GET("$baseUrl/ajax/episode/list/$id?vrf=$vrf", headers = Headers.headersOf("url", anime.url)) return GET("$baseUrl/ajax/episode/list/$id?vrf=${java.net.URLEncoder.encode(vrf, "utf-8")}", headers = Headers.headersOf("url", anime.url))
} }
private fun <A, B> Iterable<A>.parallelMap(f: suspend (A) -> B): List<B> = private fun <A, B> Iterable<A>.parallelMap(f: suspend (A) -> B): List<B> =
@ -128,7 +128,7 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val ids = episode.url.substringAfter("list/").substringBefore("?vrf") val ids = episode.url.substringAfter("list/").substringBefore("?vrf")
val jsVrfInterceptor = client.newBuilder().addInterceptor(JsVrfInterceptor(ids, baseUrl)).build() val jsVrfInterceptor = client.newBuilder().addInterceptor(JsVrfInterceptor(ids, baseUrl)).build()
val vrf = jsVrfInterceptor.newCall(GET("$baseUrl/filter")).execute().request.header("url").toString() val vrf = jsVrfInterceptor.newCall(GET("$baseUrl/filter")).execute().request.header("url").toString()
val url = "/ajax/server/list/$ids?vrf=$vrf" val url = "/ajax/server/list/$ids?vrf=${java.net.URLEncoder.encode(vrf, "utf-8")}"
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))
} }
@ -222,7 +222,7 @@ class NineAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request { override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
val jsVrfInterceptor = client.newBuilder().addInterceptor(JsVrfInterceptor(query, baseUrl)).build() val jsVrfInterceptor = client.newBuilder().addInterceptor(JsVrfInterceptor(query, baseUrl)).build()
val vrf = jsVrfInterceptor.newCall(GET("$baseUrl/filter")).execute().request.header("url").toString() val vrf = jsVrfInterceptor.newCall(GET("$baseUrl/filter")).execute().request.header("url").toString()
return GET("$baseUrl/filter?keyword=$query&vrf=$vrf&page=$page", headers = Headers.headersOf("Referer", "$baseUrl/")) return GET("$baseUrl/filter?keyword=$query&vrf=${java.net.URLEncoder.encode(vrf, "utf-8")}&page=$page", headers = Headers.headersOf("Referer", "$baseUrl/"))
} }
override fun animeDetailsParse(document: Document): SAnime { override fun animeDetailsParse(document: Document): SAnime {