Improve some parsers
parent
c294f5bb61
commit
e874837efb
@ -1,160 +1,160 @@
|
|||||||
package org.koitharu.kotatsu.parsers.site.vi
|
package org.koitharu.kotatsu.parsers.site.vi
|
||||||
|
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.parsers.MangaSourceParser
|
import org.koitharu.kotatsu.parsers.MangaSourceParser
|
||||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
import org.koitharu.kotatsu.parsers.core.LegacyPagedMangaParser
|
import org.koitharu.kotatsu.parsers.core.LegacyPagedMangaParser
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.*
|
||||||
import org.koitharu.kotatsu.parsers.util.suspendlazy.suspendLazy
|
|
||||||
import org.koitharu.kotatsu.parsers.util.*
|
import org.koitharu.kotatsu.parsers.util.*
|
||||||
import org.koitharu.kotatsu.parsers.util.json.*
|
import org.koitharu.kotatsu.parsers.util.json.*
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@MangaSourceParser("MIMIHENTAI", "MimiHentai", "vi", type = ContentType.HENTAI)
|
@MangaSourceParser("MIMIHENTAI", "MimiHentai", "vi", type = ContentType.HENTAI)
|
||||||
internal class MimiHentai(context: MangaLoaderContext) :
|
internal class MimiHentai(context: MangaLoaderContext) :
|
||||||
LegacyPagedMangaParser(context, MangaParserSource.MIMIHENTAI, 18) {
|
LegacyPagedMangaParser(context, MangaParserSource.MIMIHENTAI, 18) {
|
||||||
|
|
||||||
private val apiSuffix = "api/v1/manga"
|
private val apiSuffix = "api/v1/manga"
|
||||||
override val configKeyDomain = ConfigKey.Domain("mimihentai.com")
|
override val configKeyDomain = ConfigKey.Domain("mimihentai.com")
|
||||||
|
|
||||||
override val availableSortOrders: Set<SortOrder> = EnumSet.of(SortOrder.UPDATED)
|
override val availableSortOrders: Set<SortOrder> = EnumSet.of(SortOrder.UPDATED)
|
||||||
|
|
||||||
override suspend fun getFilterOptions() = MangaListFilterOptions(availableTags = fetchTags())
|
override val filterCapabilities: MangaListFilterCapabilities
|
||||||
override val filterCapabilities: MangaListFilterCapabilities
|
get() = MangaListFilterCapabilities(
|
||||||
get() = MangaListFilterCapabilities(
|
isSearchSupported = true,
|
||||||
isSearchSupported = true,
|
isSearchWithFiltersSupported = true,
|
||||||
isSearchWithFiltersSupported = true,
|
isMultipleTagsSupported = true,
|
||||||
isMultipleTagsSupported = true,
|
isAuthorSearchSupported = true,
|
||||||
isAuthorSearchSupported = true
|
)
|
||||||
)
|
|
||||||
|
init {
|
||||||
override suspend fun getListPage(page: Int, order: SortOrder, filter: MangaListFilter): List<Manga> {
|
setFirstPage(0)
|
||||||
val url = buildString {
|
}
|
||||||
append("https://")
|
|
||||||
append(domain)
|
override suspend fun getFilterOptions() = MangaListFilterOptions(availableTags = fetchTags())
|
||||||
append("/$apiSuffix/advance-search?page=")
|
|
||||||
append(page - 1) // first page is 0, not 1
|
override suspend fun getListPage(page: Int, order: SortOrder, filter: MangaListFilter): List<Manga> {
|
||||||
append("&max=18") // page size, avoid rate limit
|
val url = buildString {
|
||||||
when {
|
append("https://")
|
||||||
!filter.query.isNullOrEmpty() -> {
|
append(domain)
|
||||||
append("&name=")
|
append("/$apiSuffix/advance-search?page=")
|
||||||
append(filter.query.urlEncoded())
|
append(page)
|
||||||
}
|
append("&max=18") // page size, avoid rate limit
|
||||||
|
when {
|
||||||
!filter.author.isNullOrEmpty() -> {
|
!filter.query.isNullOrEmpty() -> {
|
||||||
append("&author=")
|
append("&name=")
|
||||||
append(filter.author.urlEncoded())
|
append(filter.query.urlEncoded())
|
||||||
}
|
}
|
||||||
|
|
||||||
filter.tags.isNotEmpty() -> {
|
!filter.author.isNullOrEmpty() -> {
|
||||||
append("&genre=")
|
append("&author=")
|
||||||
append(filter.tags.joinToString(",") { it.key })
|
append(filter.author.urlEncoded())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
filter.tags.isNotEmpty() -> {
|
||||||
|
append("&genre=")
|
||||||
val json = webClient.httpGet(url).parseJson()
|
append(filter.tags.joinToString(",") { it.key })
|
||||||
val data = json.getJSONArray("data")
|
}
|
||||||
return parseMangaList(data)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun parseMangaList(data: JSONArray): List<Manga> {
|
val json = webClient.httpGet(url).parseJson()
|
||||||
return data.mapJSON { jo ->
|
val data = json.getJSONArray("data")
|
||||||
val id = jo.getLong("id")
|
return parseMangaList(data)
|
||||||
val title = jo.getString("title")
|
}
|
||||||
val description = jo.getString("description")
|
|
||||||
val authors = jo.getJSONArray("authors").asTypedList<String>().mapToSet { it }
|
private fun parseMangaList(data: JSONArray): List<Manga> {
|
||||||
val differentNames = jo.getJSONArray("differentNames").asTypedList<String>().mapToSet { it }
|
return data.mapJSON { jo ->
|
||||||
val state = when(description) {
|
val id = jo.getLong("id")
|
||||||
"Đang Tiến Hành" -> MangaState.ONGOING
|
val title = jo.getString("title")
|
||||||
"Hoàn Thành" -> MangaState.FINISHED
|
val description = jo.getStringOrNull("description")
|
||||||
else -> null
|
val authors = jo.getJSONArray("authors").asTypedList<String>().toSet()
|
||||||
}
|
val differentNames = jo.getJSONArray("differentNames").asTypedList<String>().toSet()
|
||||||
|
val state = when (description) {
|
||||||
Manga(
|
"Đang Tiến Hành" -> MangaState.ONGOING
|
||||||
id = generateUid(id),
|
"Hoàn Thành" -> MangaState.FINISHED
|
||||||
title = title,
|
else -> null
|
||||||
altTitles = differentNames,
|
}
|
||||||
url = "/$apiSuffix/info/$id",
|
|
||||||
publicUrl = "https://$domain/g/$id",
|
Manga(
|
||||||
rating = RATING_UNKNOWN,
|
id = generateUid(id),
|
||||||
contentRating = ContentRating.ADULT,
|
title = title,
|
||||||
coverUrl = jo.getString("coverUrl"),
|
altTitles = differentNames,
|
||||||
tags = emptySet(),
|
url = "/$apiSuffix/info/$id",
|
||||||
state = state,
|
publicUrl = "https://$domain/g/$id",
|
||||||
authors = authors,
|
rating = RATING_UNKNOWN,
|
||||||
source = source,
|
contentRating = ContentRating.ADULT,
|
||||||
)
|
coverUrl = jo.getString("coverUrl"),
|
||||||
}
|
tags = emptySet(),
|
||||||
}
|
state = state,
|
||||||
|
authors = authors,
|
||||||
override suspend fun getDetails(manga: Manga): Manga = coroutineScope {
|
source = source,
|
||||||
val url = "https://" + domain + manga.url
|
)
|
||||||
val json = webClient.httpGet(url).parseJson()
|
}
|
||||||
|
}
|
||||||
val relationInfo = json.getJSONObject("relationInfo")
|
|
||||||
val tags = relationInfo.getJSONArray("genres").mapJSON { jo ->
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
MangaTag(
|
val url = manga.url.toAbsoluteUrl(domain)
|
||||||
title = jo.getString("name"),
|
val json = webClient.httpGet(url).parseJson()
|
||||||
key = jo.getLong("id").toString(),
|
|
||||||
source = source,
|
val relationInfo = json.getJSONObject("relationInfo")
|
||||||
)
|
val tags = relationInfo.getJSONArray("genres").mapJSONToSet { jo ->
|
||||||
}.toSet()
|
MangaTag(
|
||||||
|
title = jo.getString("name").toTitleCase(sourceLocale),
|
||||||
val basicInfo = json.getJSONObject("basicInfo")
|
key = jo.getLong("id").toString(),
|
||||||
val id = basicInfo.getLong("id")
|
source = source,
|
||||||
val description = basicInfo.optString("fdescription").takeUnless { it.isNullOrEmpty() }
|
)
|
||||||
val uploaderName = json.getString("uploaderName")
|
}
|
||||||
val urlChaps = "https://$domain/$apiSuffix/gallery/$id"
|
|
||||||
val parseUrlChaps = async { JSONArray(webClient.httpGet(urlChaps).parseHtml().text()) }
|
val basicInfo = json.getJSONObject("basicInfo")
|
||||||
val chapters = parseUrlChaps.await().mapJSON { jo ->
|
val id = basicInfo.getLong("id")
|
||||||
MangaChapter(
|
val description = basicInfo.getStringOrNull("fdescription")
|
||||||
id = generateUid(jo.getLong("id")),
|
val uploaderName = json.getStringOrNull("uploaderName")
|
||||||
title = jo.getString("title"),
|
val urlChaps = "https://$domain/$apiSuffix/gallery/$id"
|
||||||
number = jo.getInt("number").toFloat(),
|
val parsedChapters = webClient.httpGet(urlChaps).parseJsonArray()
|
||||||
url = "/$apiSuffix/chapter?id=${jo.getLong("id")}",
|
val chapters = parsedChapters.mapJSON { jo ->
|
||||||
uploadDate = 0L,
|
MangaChapter(
|
||||||
source = source,
|
id = generateUid(jo.getLong("id")),
|
||||||
scanlator = uploaderName,
|
title = jo.getStringOrNull("title"),
|
||||||
branch = null,
|
number = jo.getFloatOrDefault("number", 0f),
|
||||||
volume = 0
|
url = "/$apiSuffix/chapter?id=${jo.getLong("id")}",
|
||||||
)
|
uploadDate = 0L,
|
||||||
}
|
source = source,
|
||||||
|
scanlator = uploaderName,
|
||||||
manga.copy(
|
branch = null,
|
||||||
tags = tags,
|
volume = 0,
|
||||||
description = description,
|
)
|
||||||
chapters = chapters
|
}
|
||||||
)
|
|
||||||
}
|
return manga.copy(
|
||||||
|
tags = tags,
|
||||||
|
description = description,
|
||||||
|
chapters = chapters,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||||
val json = webClient.httpGet("https://$domain${chapter.url}").parseJson()
|
val json = webClient.httpGet(chapter.url.toAbsoluteUrl(domain)).parseJson()
|
||||||
val imageUrls = json.getJSONArray("pages").asTypedList<String>()
|
val imageUrls = json.getJSONArray("pages").asTypedList<String>()
|
||||||
return imageUrls.map { url ->
|
return imageUrls.map { url ->
|
||||||
MangaPage(
|
MangaPage(
|
||||||
id = generateUid(url),
|
id = generateUid(url),
|
||||||
url = url,
|
url = url,
|
||||||
preview = null,
|
preview = null,
|
||||||
source = source,
|
source = source,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun fetchTags(): Set<MangaTag> {
|
private suspend fun fetchTags(): Set<MangaTag> {
|
||||||
val url = "https://$domain/$apiSuffix/genres"
|
val url = "https://$domain/$apiSuffix/genres"
|
||||||
val response = JSONArray(webClient.httpGet(url).parseHtml().text())
|
val response = webClient.httpGet(url).parseJsonArray()
|
||||||
return response.mapJSON { jo ->
|
return response.mapJSONToSet { jo ->
|
||||||
MangaTag(
|
MangaTag(
|
||||||
title = jo.getString("name"),
|
title = jo.getString("name").toTitleCase(sourceLocale),
|
||||||
key = jo.getLong("id").toString(),
|
key = jo.getLong("id").toString(),
|
||||||
source = source,
|
source = source,
|
||||||
)
|
)
|
||||||
}.toSet()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue