|
|
|
@ -7,18 +7,15 @@ import org.koitharu.kotatsu.parsers.model.Favicon
|
|
|
|
import org.koitharu.kotatsu.parsers.model.Favicons
|
|
|
|
import org.koitharu.kotatsu.parsers.model.Favicons
|
|
|
|
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
|
|
|
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
|
|
|
|
|
|
|
|
|
|
|
class FaviconParser(private val context: MangaLoaderContext, private val domain: String) {
|
|
|
|
class FaviconParser(
|
|
|
|
|
|
|
|
private val context: MangaLoaderContext,
|
|
|
|
private val headers = Headers.Builder()
|
|
|
|
private val domain: String,
|
|
|
|
|
|
|
|
private val headers: Headers?,
|
|
|
|
fun addHeaders(headers: Headers): FaviconParser {
|
|
|
|
) {
|
|
|
|
this.headers.addAll(headers)
|
|
|
|
|
|
|
|
return this
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
suspend fun parseFavicons(): Favicons {
|
|
|
|
suspend fun parseFavicons(): Favicons {
|
|
|
|
val url = "https://$domain"
|
|
|
|
val url = "https://$domain"
|
|
|
|
val doc = context.httpGet(url, headers.build()).parseHtml()
|
|
|
|
val doc = context.httpGet(url, headers).parseHtml()
|
|
|
|
val result = HashSet<Favicon>()
|
|
|
|
val result = HashSet<Favicon>()
|
|
|
|
val manifestLink = doc.getElementsByAttributeValue("rel", "manifest").firstOrNull()
|
|
|
|
val manifestLink = doc.getElementsByAttributeValue("rel", "manifest").firstOrNull()
|
|
|
|
?.attrAsAbsoluteUrlOrNull("href")
|
|
|
|
?.attrAsAbsoluteUrlOrNull("href")
|
|
|
|
@ -59,7 +56,7 @@ class FaviconParser(private val context: MangaLoaderContext, private val domain:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun parseManifest(url: String): List<Favicon> {
|
|
|
|
private suspend fun parseManifest(url: String): List<Favicon> {
|
|
|
|
val json = context.httpGet(url, headers.build()).parseJson()
|
|
|
|
val json = context.httpGet(url, headers).parseJson()
|
|
|
|
val icons = json.getJSONArray("icons")
|
|
|
|
val icons = json.getJSONArray("icons")
|
|
|
|
return icons.mapJSON { jo ->
|
|
|
|
return icons.mapJSON { jo ->
|
|
|
|
Favicon(
|
|
|
|
Favicon(
|
|
|
|
|