Merge pull request #1 from KotatsuApp/master

[pull] master from KotatsuApp:master
Naga 2 years ago committed by GitHub
commit 986e4d8fcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -25,4 +25,8 @@ sealed class ConfigKey<T>(
class UserAgent( class UserAgent(
override val defaultValue: String, override val defaultValue: String,
) : ConfigKey<String>("user_agent") ) : ConfigKey<String>("user_agent")
class SplitByTranslations(
override val defaultValue: Boolean,
) : ConfigKey<Boolean>("split_translations")
} }

@ -45,6 +45,7 @@ internal abstract class GroupleParser(
private val userAgentKey = ConfigKey.UserAgent( private val userAgentKey = ConfigKey.UserAgent(
"Mozilla/5.0 (X11; U; UNICOS lcLinux; en-US) Gecko/20140730 (KHTML, like Gecko, Safari/419.3) Arora/0.8.0", "Mozilla/5.0 (X11; U; UNICOS lcLinux; en-US) Gecko/20140730 (KHTML, like Gecko, Safari/419.3) Arora/0.8.0",
) )
private val splitTranslationsKey = ConfigKey.SplitByTranslations(false)
override val headers: Headers = Headers.Builder().add("User-Agent", config[userAgentKey]).build() override val headers: Headers = Headers.Builder().add("User-Agent", config[userAgentKey]).build()
@ -115,11 +116,15 @@ internal abstract class GroupleParser(
val root = doc.body().requireElementById("mangaBox").selectFirstOrThrow("div.leftContent") val root = doc.body().requireElementById("mangaBox").selectFirstOrThrow("div.leftContent")
val dateFormat = SimpleDateFormat("dd.MM.yy", Locale.US) val dateFormat = SimpleDateFormat("dd.MM.yy", Locale.US)
val coverImg = root.selectFirst("div.subject-cover")?.selectFirst("img") val coverImg = root.selectFirst("div.subject-cover")?.selectFirst("img")
val translations = root.selectFirst("div.translator-selection") val translations = if (config[splitTranslationsKey]) {
root.selectFirst("div.translator-selection")
?.select(".translator-selection-item") ?.select(".translator-selection-item")
?.associate { ?.associate {
it.id().removePrefix("tr-").toLong() to it.selectFirst(".translator-selection-name")?.textOrNull() it.id().removePrefix("tr-").toLong() to it.selectFirst(".translator-selection-name")?.textOrNull()
} }
} else {
null
}
return manga.copy( return manga.copy(
description = root.selectFirst("div.manga-description")?.html(), description = root.selectFirst("div.manga-description")?.html(),
largeCoverUrl = coverImg?.attr("data-full"), largeCoverUrl = coverImg?.attr("data-full"),
@ -277,6 +282,7 @@ internal abstract class GroupleParser(
override fun onCreateConfig(keys: MutableCollection<ConfigKey<*>>) { override fun onCreateConfig(keys: MutableCollection<ConfigKey<*>>) {
super.onCreateConfig(keys) super.onCreateConfig(keys)
keys.add(userAgentKey) keys.add(userAgentKey)
keys.add(splitTranslationsKey)
} }
override suspend fun getRelatedManga(seed: Manga): List<Manga> { override suspend fun getRelatedManga(seed: Manga): List<Manga> {

Loading…
Cancel
Save