[NineManga] Fix favicons redirect
This commit is contained in:
@@ -112,7 +112,7 @@ abstract class MangaParser @InternalParsersApi constructor(val source: MangaSour
|
||||
)
|
||||
open fun getFaviconUrl() = "https://${getDomain()}/favicon.ico"
|
||||
|
||||
suspend fun parseFavicons(): Favicons {
|
||||
open suspend fun parseFavicons(): Favicons {
|
||||
return FaviconParser(context, getDomain()).parseFavicons()
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +171,10 @@ internal abstract class NineMangaParser(
|
||||
} ?: parseFailed("Root not found")
|
||||
}
|
||||
|
||||
override suspend fun parseFavicons(): Favicons {
|
||||
return FaviconParser(context, getDomain()).addHeaders(headers).parseFavicons()
|
||||
}
|
||||
|
||||
private fun parseStatus(status: String) = when {
|
||||
status.contains("Ongoing") -> MangaState.ONGOING
|
||||
status.contains("Completed") -> MangaState.FINISHED
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.parsers.util
|
||||
|
||||
import okhttp3.Headers
|
||||
import org.jsoup.nodes.Element
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.parsers.model.Favicon
|
||||
@@ -8,9 +9,16 @@ import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
||||
|
||||
class FaviconParser(private val context: MangaLoaderContext, private val domain: String) {
|
||||
|
||||
private val headers = Headers.Builder()
|
||||
|
||||
fun addHeaders(headers: Headers): FaviconParser {
|
||||
this.headers.addAll(headers)
|
||||
return this
|
||||
}
|
||||
|
||||
suspend fun parseFavicons(): Favicons {
|
||||
val url = "https://$domain"
|
||||
val doc = context.httpGet(url).parseHtml()
|
||||
val doc = context.httpGet(url, headers.build()).parseHtml()
|
||||
val result = HashSet<Favicon>()
|
||||
val manifestLink = doc.getElementsByAttributeValue("rel", "manifest").firstOrNull()
|
||||
?.attrAsAbsoluteUrlOrNull("href")
|
||||
@@ -51,7 +59,7 @@ class FaviconParser(private val context: MangaLoaderContext, private val domain:
|
||||
}
|
||||
|
||||
private suspend fun parseManifest(url: String): List<Favicon> {
|
||||
val json = context.httpGet(url).parseJson()
|
||||
val json = context.httpGet(url, headers.build()).parseJson()
|
||||
val icons = json.getJSONArray("icons")
|
||||
return icons.mapJSON { jo ->
|
||||
Favicon(
|
||||
|
||||
@@ -17,7 +17,7 @@ class CloudFlareInterceptor : Interceptor {
|
||||
if (response.code == HTTP_FORBIDDEN || response.code == HTTP_UNAVAILABLE) {
|
||||
if (response.header(HEADER_SERVER)?.startsWith(SERVER_CLOUDFLARE) == true) {
|
||||
response.closeQuietly()
|
||||
throw CloudFlareProtectedException(chain.request().url.toString())
|
||||
throw CloudFlareProtectedException(response.request.url.toString())
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user