|
|
|
|
@ -10,33 +10,22 @@ import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
|
|
|
|
import org.koitharu.kotatsu.parsers.MangaSourceParser
|
|
|
|
|
import org.koitharu.kotatsu.parsers.PagedMangaParser
|
|
|
|
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.Manga
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaState
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.RATING_UNKNOWN
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.domain
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.generateUid
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.*
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.*
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.json.getStringOrNull
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.json.mapJSONIndexed
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.parseJson
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.parseJsonArray
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.removeSuffix
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.tryParse
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.urlEncoded
|
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
|
import java.util.EnumSet
|
|
|
|
|
import java.util.Locale
|
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private const val PAGE_SIZE = 20
|
|
|
|
|
private const val INFINITE = 999999
|
|
|
|
|
private const val HEADER_ENCODING = "Content-Encoding"
|
|
|
|
|
|
|
|
|
|
@MangaSourceParser("HONEYMANGA", "Honey Manga", "uk")
|
|
|
|
|
class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context, MangaSource.HONEYMANGA, PAGE_SIZE), Interceptor {
|
|
|
|
|
class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context, MangaSource.HONEYMANGA, PAGE_SIZE),
|
|
|
|
|
Interceptor {
|
|
|
|
|
|
|
|
|
|
private val urlApi get() = "https://data.api.$domain"
|
|
|
|
|
private val mangaApi get() = "$urlApi/v2/manga/cursor-list"
|
|
|
|
|
@ -64,7 +53,7 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
|
|
|
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US)
|
|
|
|
|
val body = JSONObject()
|
|
|
|
|
body.put("mangaId", manga.url)
|
|
|
|
|
body.put("pageSize", 999999) // Hack lol (no)
|
|
|
|
|
body.put("pageSize", INFINITE) // Hack lol (no)
|
|
|
|
|
body.put("page", 1)
|
|
|
|
|
body.put("sortOrder", "ASC")
|
|
|
|
|
val chapterRequest = webClient.httpPost(chapterApi, body).parseJson()
|
|
|
|
|
@ -88,9 +77,9 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
|
|
|
|
scanlator = null,
|
|
|
|
|
uploadDate = dateFormat.tryParse(jo.getString("lastUpdated")),
|
|
|
|
|
branch = null,
|
|
|
|
|
source = source
|
|
|
|
|
source = source,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -98,10 +87,9 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
|
|
|
|
page: Int,
|
|
|
|
|
query: String?,
|
|
|
|
|
tags: Set<MangaTag>?,
|
|
|
|
|
sortOrder: SortOrder
|
|
|
|
|
sortOrder: SortOrder,
|
|
|
|
|
): List<Manga> {
|
|
|
|
|
val body = JSONObject()
|
|
|
|
|
var content: JSONArray = JSONArray()
|
|
|
|
|
body.put("page", page)
|
|
|
|
|
body.put("pageSize", PAGE_SIZE)
|
|
|
|
|
val sort = JSONObject()
|
|
|
|
|
@ -109,33 +97,45 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
|
|
|
|
sort.put("sortOrder", "DESC")
|
|
|
|
|
body.put("sort", sort)
|
|
|
|
|
|
|
|
|
|
val content = when {
|
|
|
|
|
!tags.isNullOrEmpty() -> {
|
|
|
|
|
// Tags
|
|
|
|
|
content = if (!tags.isNullOrEmpty()) {
|
|
|
|
|
val filters: JSONArray = JSONArray()
|
|
|
|
|
val tag_filter = JSONObject()
|
|
|
|
|
tag_filter.put("filterBy", "genres")
|
|
|
|
|
tag_filter.put("filterOperator", "ALL")
|
|
|
|
|
val tag: JSONArray = JSONArray()
|
|
|
|
|
val filters = JSONArray()
|
|
|
|
|
val tagFilter = JSONObject()
|
|
|
|
|
tagFilter.put("filterBy", "genres")
|
|
|
|
|
tagFilter.put("filterOperator", "ALL")
|
|
|
|
|
val tag = JSONArray()
|
|
|
|
|
tags.forEach {
|
|
|
|
|
tag.put(it.title)
|
|
|
|
|
}
|
|
|
|
|
tag_filter.put("filterValue", tag)
|
|
|
|
|
filters.put(tag_filter)
|
|
|
|
|
tagFilter.put("filterValue", tag)
|
|
|
|
|
filters.put(tagFilter)
|
|
|
|
|
body.put("filters", filters)
|
|
|
|
|
webClient.httpPost(mangaApi, body).parseJson().getJSONArray("data")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
!query.isNullOrEmpty() -> {
|
|
|
|
|
// Search
|
|
|
|
|
} else if(!query.isNullOrEmpty()) {
|
|
|
|
|
if((query.length < 3)) throw IllegalArgumentException("Запит має містити щонайменше 3 символи / The query must contain at least 3 characters")
|
|
|
|
|
if(page == 1) {
|
|
|
|
|
webClient.httpGet(searchApi + query.urlEncoded()).parseJsonArray()
|
|
|
|
|
} else {
|
|
|
|
|
JSONArray()
|
|
|
|
|
when {
|
|
|
|
|
query.length < 3 -> throw IllegalArgumentException(
|
|
|
|
|
"The query must contain at least 3 characters (Запит має містити щонайменше 3 символи)",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
page == searchPaginator.firstPage -> webClient
|
|
|
|
|
.httpGet(searchApi + query.urlEncoded())
|
|
|
|
|
.parseJsonArray()
|
|
|
|
|
|
|
|
|
|
else -> JSONArray()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
|
// Popular/Newest
|
|
|
|
|
} else {
|
|
|
|
|
body.put("filters", JSONArray())
|
|
|
|
|
webClient.httpPost(mangaApi, body).parseJson().getJSONArray("data")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return content.mapJSON { jo ->
|
|
|
|
|
val id = jo.getString("id")
|
|
|
|
|
val posterUrl = jo.getString("posterUrl")
|
|
|
|
|
@ -166,32 +166,29 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
|
|
|
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
|
|
|
val body = JSONObject()
|
|
|
|
|
body.put("chapterId", chapter.url)
|
|
|
|
|
|
|
|
|
|
val content = webClient.httpPost(framesApi, body).parseJson().getJSONObject("resourceIds")
|
|
|
|
|
return List(content.length()) { i ->
|
|
|
|
|
val item = content.get(i.toString()).toString()
|
|
|
|
|
val item = content.getString(i.toString())
|
|
|
|
|
MangaPage(id = generateUid(item), "$imageStorageUrl/$item", getCoverUrl(item, 256), source)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getTags(): Set<MangaTag> {
|
|
|
|
|
// https://data.api.honey-manga.com.ua/genres-tags/genres-list
|
|
|
|
|
val tagsSet = mutableListOf<MangaTag>()
|
|
|
|
|
val content = webClient.httpGet(genresListApi).parseJsonArray()
|
|
|
|
|
(0 until content.length()).forEach { i ->
|
|
|
|
|
val item = content.get(i).toString()
|
|
|
|
|
|
|
|
|
|
val tagsSet = ArraySet<MangaTag>(content.length())
|
|
|
|
|
repeat(content.length()) { i ->
|
|
|
|
|
val item = content.getString(i)
|
|
|
|
|
tagsSet.add(MangaTag(item, item, source))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tagsSet.toSet()
|
|
|
|
|
return tagsSet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Need for disable encoding (with encoding not working)
|
|
|
|
|
override fun intercept(chain: Interceptor.Chain): Response {
|
|
|
|
|
val request = chain.request()
|
|
|
|
|
val newRequest = if (request.header("Content-Encoding") != null) {
|
|
|
|
|
request.newBuilder().removeHeader("Content-Encoding").build()
|
|
|
|
|
val newRequest = if (request.header(HEADER_ENCODING) != null) {
|
|
|
|
|
request.newBuilder().removeHeader(HEADER_ENCODING).build()
|
|
|
|
|
} else {
|
|
|
|
|
request
|
|
|
|
|
}
|
|
|
|
|
@ -216,12 +213,11 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
|
|
|
|
|
|
|
|
|
private fun getTitleTags(jsonTags: JSONArray): Set<MangaTag> {
|
|
|
|
|
val tagsSet = ArraySet<MangaTag>(jsonTags.length())
|
|
|
|
|
(0 until jsonTags.length()).forEach { i ->
|
|
|
|
|
val item = jsonTags.get(i)
|
|
|
|
|
repeat(jsonTags.length()) { i ->
|
|
|
|
|
val item = jsonTags.getString(i)
|
|
|
|
|
|
|
|
|
|
tagsSet.add(MangaTag(item.toString(), item.toString(), source))
|
|
|
|
|
tagsSet.add(MangaTag(title = item.toTitleCase(sourceLocale), key = item, source = source))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tagsSet.toSet()
|
|
|
|
|
return tagsSet
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|