[WpComics] Fix covers

master
Koitharu 1 year ago
parent 677afa9a41
commit 0456a92f15
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -1,4 +1,4 @@
package org.koitharu.kotatsu.parsers.site.mangareader.en package org.koitharu.kotatsu.parsers.site.en
import androidx.collection.ArraySet import androidx.collection.ArraySet
import okhttp3.HttpUrl import okhttp3.HttpUrl

@ -6,7 +6,9 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.koitharu.kotatsu.parsers.MangaLoaderContext import org.koitharu.kotatsu.parsers.MangaLoaderContext
import org.koitharu.kotatsu.parsers.PagedMangaParser import org.koitharu.kotatsu.parsers.PagedMangaParser
import org.koitharu.kotatsu.parsers.config.ConfigKey import org.koitharu.kotatsu.parsers.config.ConfigKey
@ -43,9 +45,6 @@ internal abstract class WpComicsParser(
isSearchSupported = true, isSearchSupported = true,
) )
@JvmField
protected val coverSrcAttrs = arrayOf("data-original", "src")
override suspend fun getFilterOptions() = MangaListFilterOptions( override suspend fun getFilterOptions() = MangaListFilterOptions(
availableTags = fetchAvailableTags(), availableTags = fetchAvailableTags(),
availableStates = EnumSet.of(MangaState.ONGOING, MangaState.FINISHED), availableStates = EnumSet.of(MangaState.ONGOING, MangaState.FINISHED),
@ -164,7 +163,7 @@ internal abstract class WpComicsParser(
publicUrl = absUrl, publicUrl = absUrl,
rating = RATING_UNKNOWN, rating = RATING_UNKNOWN,
isNsfw = false, isNsfw = false,
coverUrl = item.selectFirst("div.image a img")?.src(coverSrcAttrs).orEmpty(), coverUrl = item.selectFirst("div.image a img")?.findImageUrl().orEmpty(),
largeCoverUrl = null, largeCoverUrl = null,
tags = mangaTags, tags = mangaTags,
state = mangaState, state = mangaState,
@ -333,4 +332,12 @@ internal abstract class WpComicsParser(
else -> 0 else -> 0
} }
} }
protected fun Element.findImageUrl(): String? {
val attrs = attributes().filter { attr ->
attr.value.toHttpUrlOrNull() != null
}
// src attribute should have a lowest priority
return attrs.maxByOrNull { it.key != "src" }?.value
}
} }

@ -98,7 +98,7 @@ internal class DocTruyen3Q(context: MangaLoaderContext) :
id = generateUid(href), id = generateUid(href),
url = href, url = href,
publicUrl = href.toAbsoluteUrl(div.host ?: domain), publicUrl = href.toAbsoluteUrl(div.host ?: domain),
coverUrl = div.selectFirst("div.image-item img")?.src(coverSrcAttrs).orEmpty(), coverUrl = div.selectFirst("div.image-item img")?.findImageUrl().orEmpty(),
title = div.selectFirst("h3 a")?.text().orEmpty(), title = div.selectFirst("h3 a")?.text().orEmpty(),
altTitle = null, altTitle = null,
rating = RATING_UNKNOWN, rating = RATING_UNKNOWN,

@ -93,7 +93,7 @@ internal class TopTruyen(context: MangaLoaderContext) :
id = generateUid(href), id = generateUid(href),
url = href, url = href,
publicUrl = href.toAbsoluteUrl(div.host ?: domain), publicUrl = href.toAbsoluteUrl(div.host ?: domain),
coverUrl = div.selectFirst("div.image-item img")?.src(coverSrcAttrs).orEmpty(), coverUrl = div.selectFirst("div.image-item img")?.findImageUrl().orEmpty(),
title = div.selectFirst("h3 a")?.text().orEmpty(), title = div.selectFirst("h3 a")?.text().orEmpty(),
altTitle = null, altTitle = null,
rating = RATING_UNKNOWN, rating = RATING_UNKNOWN,

Loading…
Cancel
Save