Multiple bugfixes for mangadex delegation

Chapters should be sorted
Multiple language fixes
Multiple empty result fixes
This commit is contained in:
Jobobby04 2021-05-09 22:10:22 -04:00
parent 09802c3609
commit 1f9b69fc07
6 changed files with 125 additions and 61 deletions

View File

@ -5,7 +5,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.await
import eu.kanade.tachiyomi.network.parseAs
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import exh.log.xLogE
import exh.md.handlers.serializers.AuthorResponseList
@ -95,12 +94,21 @@ class ApiMangaParser(val client: OkHttpClient, private val lang: String) {
// get author/artist map ignore if they error
val authorMap = runCatching {
val ids = (authorIds + artistIds).joinToString("&ids[]=", "?ids[]=")
val response = client.newCall(GET("${MdUtil.authorUrl}$ids")).await()
.parseAs<AuthorResponseList>()
response.results.map {
it.data.id to MdUtil.cleanString(it.data.attributes.name)
}.toMap()
(authorIds + artistIds).chunked(10)
.flatMap { idList ->
val ids = idList.joinToString("&ids[]=", "?ids[]=")
val response = client.newCall(GET("${MdUtil.authorUrl}$ids")).await()
if (response.code != 204) {
response
.parseAs<AuthorResponseList>()
.results.map {
it.data.id to MdUtil.cleanString(it.data.attributes.name)
}
} else {
emptyList()
}
}
.toMap()
}.getOrNull() ?: emptyMap()
authors = authorIds.mapNotNull { authorMap[it] }.dropEmpty()
@ -133,7 +141,6 @@ class ApiMangaParser(val client: OkHttpClient, private val lang: String) {
cover = "https://i.imgur.com/6TrIues.jpg"
}
// val filteredChapters = filterChapterForChecking(networkApiManga)
val tempStatus = parseStatus(networkManga.status ?: "")

View File

@ -43,7 +43,7 @@ class FilterHandler(private val preferencesHelper: PreferencesHelper) {
Filter.Group<Status>("Status", status)
private fun getStatus() = listOf(
Status("Onging"),
Status("Ongoing"),
Status("Completed"),
Status("Hiatus"),
Status("Abandoned"),
@ -65,9 +65,9 @@ class FilterHandler(private val preferencesHelper: PreferencesHelper) {
Filter.Group<OriginalLanguage>("Original language", originalLanguage)
private fun getOriginalLanguage() = listOf(
OriginalLanguage("Japanese (Manga)", "jp"),
OriginalLanguage("Chinese (Manhua)", "cn"),
OriginalLanguage("Korean (Manhwa)", "kr"),
OriginalLanguage("Japanese (Manga)", "ja"),
OriginalLanguage("Chinese (Manhua)", "zh"),
OriginalLanguage("Korean (Manhwa)", "ko"),
)
internal class Tag(val id: String, name: String) : Filter.TriState(name)
@ -180,6 +180,12 @@ class FilterHandler(private val preferencesHelper: PreferencesHelper) {
lang.isoCode
)
}
if (lang.isoCode == "zh") {
addQueryParameter(
"originalLanguage[]",
"zh-hk"
)
}
}
}
is ContentRatingList -> {

View File

@ -47,6 +47,10 @@ class FollowsHandler(
suspend fun fetchFollows(page: Int): MetadataMangasPage {
return withIOContext {
val response = client.newCall(followsListRequest(MdUtil.mangaLimit * page - 1)).await()
if (response.code == 204) {
return@withIOContext MetadataMangasPage(emptyList(), false, emptyList())
}
val mangaListResponse = response.parseAs<MangaListResponse>(MdUtil.jsonParser)
if (mangaListResponse.results.isEmpty()) {
@ -195,6 +199,10 @@ class FollowsHandler(
return withIOContext {
val response = client.newCall(followsListRequest(0)).await()
if (response.code == 204) {
return@withIOContext emptyList()
}
val mangaListResponse = response.parseAs<MangaListResponse>(MdUtil.jsonParser)
val results = mangaListResponse.results.toMutableList()
@ -207,11 +215,15 @@ class FollowsHandler(
while (hasMoreResults) {
val offset = lastOffset + mangaListResponse.limit
val newMangaListResponse = client.newCall(followsListRequest(offset)).await()
.parseAs<MangaListResponse>(MdUtil.jsonParser)
results.addAll(newMangaListResponse.results)
hasMoreResults = newMangaListResponse.limit + newMangaListResponse.offset under newMangaListResponse.total
lastOffset = newMangaListResponse.offset
val newResponse = client.newCall(followsListRequest(offset)).await()
if (newResponse.code != 204) {
val newMangaListResponse = newResponse.parseAs<MangaListResponse>(MdUtil.jsonParser)
results.addAll(newMangaListResponse.results)
hasMoreResults = newMangaListResponse.limit + newMangaListResponse.offset under newMangaListResponse.total
lastOffset = newMangaListResponse.offset
} else {
hasMoreResults = false
}
}
val statusListResponse = client.newCall(mangaStatusListRequest(results)).await().parseAs<MangaStatusListResponse>()
followsParseMangaPage(results, statusListResponse)

View File

@ -81,6 +81,10 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, private val l
return client.newCall(mangaFeedRequest(manga.toMangaInfo(), 0, lang))
.asObservableSuccess()
.map { response ->
if (response.code == 204) {
return@map emptyList()
}
val chapterListResponse = response.parseAs<ChapterListResponse>(MdUtil.jsonParser)
val results = chapterListResponse.results.toMutableList()
@ -89,11 +93,16 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, private val l
while (hasMoreResults) {
val offset = lastOffset + chapterListResponse.limit
val newChapterListResponse = client.newCall(mangaFeedRequest(manga.toMangaInfo(), offset, lang)).execute()
.parseAs<ChapterListResponse>(MdUtil.jsonParser)
results.addAll(newChapterListResponse.results)
hasMoreResults = newChapterListResponse.limit + newChapterListResponse.offset under newChapterListResponse.total
lastOffset = newChapterListResponse.offset
val newResponse = client.newCall(mangaFeedRequest(manga.toMangaInfo(), offset, lang)).execute()
if (newResponse.code != 204) {
val newChapterListResponse = newResponse
.parseAs<ChapterListResponse>(MdUtil.jsonParser)
results.addAll(newChapterListResponse.results)
hasMoreResults = newChapterListResponse.limit + newChapterListResponse.offset under newChapterListResponse.total
lastOffset = newChapterListResponse.offset
} else {
hasMoreResults = false
}
}
val groupIds =
results.asSequence()
@ -105,11 +114,17 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, private val l
.toList()
val groupMap = runCatching {
groupIds.chunked(100).mapIndexed { index, ids ->
val groupList = client.newCall(groupIdRequest(ids, 100 * index)).execute()
.parseAs<GroupListResponse>(MdUtil.jsonParser)
groupList.results.map { group -> Pair(group.data.id, group.data.attributes.name) }
}.flatten().toMap()
groupIds.chunked(100).flatMapIndexed { index, ids ->
val groupResponse = client.newCall(groupIdRequest(ids, 100 * index)).execute()
if (groupResponse.code != 204) {
groupResponse
.parseAs<GroupListResponse>(MdUtil.jsonParser)
.results
.map { group -> Pair(group.data.id, group.data.attributes.name) }
} else {
emptyList()
}
}.toMap()
}.getOrNull() ?: emptyMap()
ApiMangaParser(client, lang).chapterListParse(results, groupMap).map { it.toSChapter() }
@ -118,7 +133,13 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, private val l
suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
return withIOContext {
val chapterListResponse = client.newCall(mangaFeedRequest(manga, 0, lang)).await().parseAs<ChapterListResponse>(MdUtil.jsonParser)
val response = client.newCall(mangaFeedRequest(manga, 0, lang)).await()
if (response.code == 204) {
return@withIOContext emptyList()
}
val chapterListResponse = response.parseAs<ChapterListResponse>(MdUtil.jsonParser)
val results = chapterListResponse.results
var hasMoreResults = chapterListResponse.limit + chapterListResponse.offset under chapterListResponse.total
@ -126,10 +147,15 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, private val l
while (hasMoreResults) {
val offset = lastOffset + chapterListResponse.limit
val newChapterListResponse = client.newCall(mangaFeedRequest(manga, offset, lang)).await()
.parseAs<ChapterListResponse>(MdUtil.jsonParser)
hasMoreResults = newChapterListResponse.limit + newChapterListResponse.offset under newChapterListResponse.total
lastOffset = newChapterListResponse.offset
val newResponse = client.newCall(mangaFeedRequest(manga, offset, lang)).await()
if (newResponse.code != 204) {
val newChapterListResponse = newResponse
.parseAs<ChapterListResponse>(MdUtil.jsonParser)
hasMoreResults = newChapterListResponse.limit + newChapterListResponse.offset under newChapterListResponse.total
lastOffset = newChapterListResponse.offset
} else {
hasMoreResults = false
}
}
val groupMap = getGroupMap(results)
@ -139,16 +165,26 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, private val l
}
private suspend fun getGroupMap(results: List<ChapterResponse>): Map<String, String> {
val groupIds = results.map { chapter -> chapter.relationships }.flatten().filter { it.type == "scanlation_group" }.map { it.id }.distinct()
val groupMap = runCatching {
groupIds.chunked(100).mapIndexed { index, ids ->
client.newCall(groupIdRequest(ids, 100 * index)).await()
.parseAs<GroupListResponse>(MdUtil.jsonParser)
.results.map { group -> Pair(group.data.id, group.data.attributes.name) }
}.flatten().toMap()
}.getOrNull() ?: emptyMap()
val groupIds = results.asSequence()
.map { chapter -> chapter.relationships }
.flatten()
.filter { it.type == "scanlation_group" }
.map { it.id }
.distinct()
.toList()
return groupMap
return runCatching {
groupIds.chunked(100).flatMapIndexed { index, ids ->
val response = client.newCall(groupIdRequest(ids, 100 * index)).await()
if (response.code != 204) {
response
.parseAs<GroupListResponse>(MdUtil.jsonParser)
.results.map { group -> Pair(group.data.id, group.data.attributes.name) }
} else {
emptyList()
}
}.toMap()
}.getOrNull() ?: emptyMap()
}
suspend fun fetchRandomMangaId(): String {

View File

@ -1,8 +1,9 @@
package exh.md.utils
@Suppress("unused")
enum class MdLang(val lang: String, val prettyPrint: String, val extLang: String = lang) {
ENGLISH("en", "English"),
JAPANESE("jp", "Japanese", "ja"),
JAPANESE("ja", "Japanese"),
POLISH("pl", "Polish"),
SERBO_CROATIAN("rs", "Serbo-Croatian", "sh"),
DUTCH("nl", "Dutch"),
@ -12,35 +13,35 @@ enum class MdLang(val lang: String, val prettyPrint: String, val extLang: String
HUNGARIAN("hu", "Hungarian"),
FRENCH("fr", "French"),
FINNISH("fi", "Finnish"),
VIETNAMESE("vn", "Vietnamese", "vi"),
GREEK("gr", "Greek", "el"),
VIETNAMESE("vi", "Vietnamese"),
GREEK("el", "Greek"),
BULGARIAN("bg", "BULGARIN"),
SPANISH_ES("es", "Spanish (Es)"),
PORTUGUESE_BR("br", "Portuguese (Br)", "pt-BR"),
PORTUGUESE_BR("pt-br", "Portuguese (Br)", "pt-BR"),
PORTUGUESE("pt", "Portuguese (Pt)"),
SWEDISH("se", "Swedish", "sv"),
ARABIC("sa", "Arabic", "ar"),
DANISH("dk", "Danish", "da"),
CHINESE_SIMPLIFIED("cn", "Chinese (Simp)", "zh"),
BENGALI("bd", "Bengali", "bn"),
SWEDISH("sv", "Swedish"),
ARABIC("ar", "Arabic"),
DANISH("da", "Danish"),
CHINESE_SIMPLIFIED("zh", "Chinese (Simp)", "zh-Hans"),
BENGALI("bn", "Bengali"),
ROMANIAN("ro", "Romanian"),
CZECH("cz", "Czech", "cs"),
CZECH("cs", "Czech"),
MONGOLIAN("mn", "Mongolian"),
TURKISH("tr", "Turkish"),
INDONESIAN("id", "Indonesian"),
KOREAN("kr", "Korean", "ko"),
SPANISH_LATAM("mx", "Spanish (LATAM)", "es-la"),
PERSIAN("ir", "Persian", "fa"),
MALAY("my", "Malay", "ms"),
SPANISH_LATAM("es-la", "Spanish (LATAM)", "es-419"),
PERSIAN("fa", "Persian"),
MALAY("ms", "Malay"),
THAI("th", "Thai"),
CATALAN("ct", "Catalan", "ca"),
FILIPINO("ph", "Filipino", "fi"),
CHINESE_TRAD("hk", "Chinese (Trad)", "zh-hk"),
UKRAINIAN("ua", "Ukrainian", "uk"),
BURMESE("mm", "Burmese", "my"),
CATALAN("ca", "Catalan"),
FILIPINO("tl", "Filipino", "fil"),
CHINESE_TRAD("zh-hk", "Chinese (Trad)", "zh-Hant"),
UKRAINIAN("uk", "Ukrainian"),
BURMESE("my", "Burmese"),
LINTHUANIAN("lt", "Lithuanian"),
HEBREW("il", "Hebrew", "he"),
HINDI("in", "Hindi", "hi"),
HEBREW("he", "Hebrew"),
HINDI("hi", "Hindi"),
NORWEGIAN("no", "Norwegian")
;

View File

@ -61,6 +61,8 @@ class MdUtil {
addQueryParameter("limit", "500")
addQueryParameter("offset", offset.toString())
addQueryParameter("locales[]", language)
addQueryParameter("order[volume]", "desc")
addQueryParameter("order[chapter]", "desc")
}.build().toString()
}