Multiple bugfixes for mangadex delegation
Chapters should be sorted Multiple language fixes Multiple empty result fixes
This commit is contained in:
parent
09802c3609
commit
1f9b69fc07
@ -5,7 +5,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import eu.kanade.tachiyomi.network.await
|
import eu.kanade.tachiyomi.network.await
|
||||||
import eu.kanade.tachiyomi.network.parseAs
|
import eu.kanade.tachiyomi.network.parseAs
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import exh.log.xLogE
|
import exh.log.xLogE
|
||||||
import exh.md.handlers.serializers.AuthorResponseList
|
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
|
// get author/artist map ignore if they error
|
||||||
val authorMap = runCatching {
|
val authorMap = runCatching {
|
||||||
val ids = (authorIds + artistIds).joinToString("&ids[]=", "?ids[]=")
|
(authorIds + artistIds).chunked(10)
|
||||||
val response = client.newCall(GET("${MdUtil.authorUrl}$ids")).await()
|
.flatMap { idList ->
|
||||||
.parseAs<AuthorResponseList>()
|
val ids = idList.joinToString("&ids[]=", "?ids[]=")
|
||||||
response.results.map {
|
val response = client.newCall(GET("${MdUtil.authorUrl}$ids")).await()
|
||||||
it.data.id to MdUtil.cleanString(it.data.attributes.name)
|
if (response.code != 204) {
|
||||||
}.toMap()
|
response
|
||||||
|
.parseAs<AuthorResponseList>()
|
||||||
|
.results.map {
|
||||||
|
it.data.id to MdUtil.cleanString(it.data.attributes.name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.toMap()
|
||||||
}.getOrNull() ?: emptyMap()
|
}.getOrNull() ?: emptyMap()
|
||||||
|
|
||||||
authors = authorIds.mapNotNull { authorMap[it] }.dropEmpty()
|
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"
|
cover = "https://i.imgur.com/6TrIues.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// val filteredChapters = filterChapterForChecking(networkApiManga)
|
// val filteredChapters = filterChapterForChecking(networkApiManga)
|
||||||
|
|
||||||
val tempStatus = parseStatus(networkManga.status ?: "")
|
val tempStatus = parseStatus(networkManga.status ?: "")
|
||||||
|
@ -43,7 +43,7 @@ class FilterHandler(private val preferencesHelper: PreferencesHelper) {
|
|||||||
Filter.Group<Status>("Status", status)
|
Filter.Group<Status>("Status", status)
|
||||||
|
|
||||||
private fun getStatus() = listOf(
|
private fun getStatus() = listOf(
|
||||||
Status("Onging"),
|
Status("Ongoing"),
|
||||||
Status("Completed"),
|
Status("Completed"),
|
||||||
Status("Hiatus"),
|
Status("Hiatus"),
|
||||||
Status("Abandoned"),
|
Status("Abandoned"),
|
||||||
@ -65,9 +65,9 @@ class FilterHandler(private val preferencesHelper: PreferencesHelper) {
|
|||||||
Filter.Group<OriginalLanguage>("Original language", originalLanguage)
|
Filter.Group<OriginalLanguage>("Original language", originalLanguage)
|
||||||
|
|
||||||
private fun getOriginalLanguage() = listOf(
|
private fun getOriginalLanguage() = listOf(
|
||||||
OriginalLanguage("Japanese (Manga)", "jp"),
|
OriginalLanguage("Japanese (Manga)", "ja"),
|
||||||
OriginalLanguage("Chinese (Manhua)", "cn"),
|
OriginalLanguage("Chinese (Manhua)", "zh"),
|
||||||
OriginalLanguage("Korean (Manhwa)", "kr"),
|
OriginalLanguage("Korean (Manhwa)", "ko"),
|
||||||
)
|
)
|
||||||
|
|
||||||
internal class Tag(val id: String, name: String) : Filter.TriState(name)
|
internal class Tag(val id: String, name: String) : Filter.TriState(name)
|
||||||
@ -180,6 +180,12 @@ class FilterHandler(private val preferencesHelper: PreferencesHelper) {
|
|||||||
lang.isoCode
|
lang.isoCode
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (lang.isoCode == "zh") {
|
||||||
|
addQueryParameter(
|
||||||
|
"originalLanguage[]",
|
||||||
|
"zh-hk"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is ContentRatingList -> {
|
is ContentRatingList -> {
|
||||||
|
@ -47,6 +47,10 @@ class FollowsHandler(
|
|||||||
suspend fun fetchFollows(page: Int): MetadataMangasPage {
|
suspend fun fetchFollows(page: Int): MetadataMangasPage {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val response = client.newCall(followsListRequest(MdUtil.mangaLimit * page - 1)).await()
|
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)
|
val mangaListResponse = response.parseAs<MangaListResponse>(MdUtil.jsonParser)
|
||||||
|
|
||||||
if (mangaListResponse.results.isEmpty()) {
|
if (mangaListResponse.results.isEmpty()) {
|
||||||
@ -195,6 +199,10 @@ class FollowsHandler(
|
|||||||
return withIOContext {
|
return withIOContext {
|
||||||
val response = client.newCall(followsListRequest(0)).await()
|
val response = client.newCall(followsListRequest(0)).await()
|
||||||
|
|
||||||
|
if (response.code == 204) {
|
||||||
|
return@withIOContext emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
val mangaListResponse = response.parseAs<MangaListResponse>(MdUtil.jsonParser)
|
val mangaListResponse = response.parseAs<MangaListResponse>(MdUtil.jsonParser)
|
||||||
val results = mangaListResponse.results.toMutableList()
|
val results = mangaListResponse.results.toMutableList()
|
||||||
|
|
||||||
@ -207,11 +215,15 @@ class FollowsHandler(
|
|||||||
|
|
||||||
while (hasMoreResults) {
|
while (hasMoreResults) {
|
||||||
val offset = lastOffset + mangaListResponse.limit
|
val offset = lastOffset + mangaListResponse.limit
|
||||||
val newMangaListResponse = client.newCall(followsListRequest(offset)).await()
|
val newResponse = client.newCall(followsListRequest(offset)).await()
|
||||||
.parseAs<MangaListResponse>(MdUtil.jsonParser)
|
if (newResponse.code != 204) {
|
||||||
results.addAll(newMangaListResponse.results)
|
val newMangaListResponse = newResponse.parseAs<MangaListResponse>(MdUtil.jsonParser)
|
||||||
hasMoreResults = newMangaListResponse.limit + newMangaListResponse.offset under newMangaListResponse.total
|
results.addAll(newMangaListResponse.results)
|
||||||
lastOffset = newMangaListResponse.offset
|
hasMoreResults = newMangaListResponse.limit + newMangaListResponse.offset under newMangaListResponse.total
|
||||||
|
lastOffset = newMangaListResponse.offset
|
||||||
|
} else {
|
||||||
|
hasMoreResults = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val statusListResponse = client.newCall(mangaStatusListRequest(results)).await().parseAs<MangaStatusListResponse>()
|
val statusListResponse = client.newCall(mangaStatusListRequest(results)).await().parseAs<MangaStatusListResponse>()
|
||||||
followsParseMangaPage(results, statusListResponse)
|
followsParseMangaPage(results, statusListResponse)
|
||||||
|
@ -81,6 +81,10 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, private val l
|
|||||||
return client.newCall(mangaFeedRequest(manga.toMangaInfo(), 0, lang))
|
return client.newCall(mangaFeedRequest(manga.toMangaInfo(), 0, lang))
|
||||||
.asObservableSuccess()
|
.asObservableSuccess()
|
||||||
.map { response ->
|
.map { response ->
|
||||||
|
if (response.code == 204) {
|
||||||
|
return@map emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
val chapterListResponse = response.parseAs<ChapterListResponse>(MdUtil.jsonParser)
|
val chapterListResponse = response.parseAs<ChapterListResponse>(MdUtil.jsonParser)
|
||||||
val results = chapterListResponse.results.toMutableList()
|
val results = chapterListResponse.results.toMutableList()
|
||||||
|
|
||||||
@ -89,11 +93,16 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, private val l
|
|||||||
|
|
||||||
while (hasMoreResults) {
|
while (hasMoreResults) {
|
||||||
val offset = lastOffset + chapterListResponse.limit
|
val offset = lastOffset + chapterListResponse.limit
|
||||||
val newChapterListResponse = client.newCall(mangaFeedRequest(manga.toMangaInfo(), offset, lang)).execute()
|
val newResponse = client.newCall(mangaFeedRequest(manga.toMangaInfo(), offset, lang)).execute()
|
||||||
.parseAs<ChapterListResponse>(MdUtil.jsonParser)
|
if (newResponse.code != 204) {
|
||||||
results.addAll(newChapterListResponse.results)
|
val newChapterListResponse = newResponse
|
||||||
hasMoreResults = newChapterListResponse.limit + newChapterListResponse.offset under newChapterListResponse.total
|
.parseAs<ChapterListResponse>(MdUtil.jsonParser)
|
||||||
lastOffset = newChapterListResponse.offset
|
results.addAll(newChapterListResponse.results)
|
||||||
|
hasMoreResults = newChapterListResponse.limit + newChapterListResponse.offset under newChapterListResponse.total
|
||||||
|
lastOffset = newChapterListResponse.offset
|
||||||
|
} else {
|
||||||
|
hasMoreResults = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val groupIds =
|
val groupIds =
|
||||||
results.asSequence()
|
results.asSequence()
|
||||||
@ -105,11 +114,17 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, private val l
|
|||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
val groupMap = runCatching {
|
val groupMap = runCatching {
|
||||||
groupIds.chunked(100).mapIndexed { index, ids ->
|
groupIds.chunked(100).flatMapIndexed { index, ids ->
|
||||||
val groupList = client.newCall(groupIdRequest(ids, 100 * index)).execute()
|
val groupResponse = client.newCall(groupIdRequest(ids, 100 * index)).execute()
|
||||||
.parseAs<GroupListResponse>(MdUtil.jsonParser)
|
if (groupResponse.code != 204) {
|
||||||
groupList.results.map { group -> Pair(group.data.id, group.data.attributes.name) }
|
groupResponse
|
||||||
}.flatten().toMap()
|
.parseAs<GroupListResponse>(MdUtil.jsonParser)
|
||||||
|
.results
|
||||||
|
.map { group -> Pair(group.data.id, group.data.attributes.name) }
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toMap()
|
||||||
}.getOrNull() ?: emptyMap()
|
}.getOrNull() ?: emptyMap()
|
||||||
|
|
||||||
ApiMangaParser(client, lang).chapterListParse(results, groupMap).map { it.toSChapter() }
|
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> {
|
suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
|
||||||
return withIOContext {
|
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
|
val results = chapterListResponse.results
|
||||||
|
|
||||||
var hasMoreResults = chapterListResponse.limit + chapterListResponse.offset under chapterListResponse.total
|
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) {
|
while (hasMoreResults) {
|
||||||
val offset = lastOffset + chapterListResponse.limit
|
val offset = lastOffset + chapterListResponse.limit
|
||||||
val newChapterListResponse = client.newCall(mangaFeedRequest(manga, offset, lang)).await()
|
val newResponse = client.newCall(mangaFeedRequest(manga, offset, lang)).await()
|
||||||
.parseAs<ChapterListResponse>(MdUtil.jsonParser)
|
if (newResponse.code != 204) {
|
||||||
hasMoreResults = newChapterListResponse.limit + newChapterListResponse.offset under newChapterListResponse.total
|
val newChapterListResponse = newResponse
|
||||||
lastOffset = newChapterListResponse.offset
|
.parseAs<ChapterListResponse>(MdUtil.jsonParser)
|
||||||
|
hasMoreResults = newChapterListResponse.limit + newChapterListResponse.offset under newChapterListResponse.total
|
||||||
|
lastOffset = newChapterListResponse.offset
|
||||||
|
} else {
|
||||||
|
hasMoreResults = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val groupMap = getGroupMap(results)
|
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> {
|
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 groupIds = results.asSequence()
|
||||||
val groupMap = runCatching {
|
.map { chapter -> chapter.relationships }
|
||||||
groupIds.chunked(100).mapIndexed { index, ids ->
|
.flatten()
|
||||||
client.newCall(groupIdRequest(ids, 100 * index)).await()
|
.filter { it.type == "scanlation_group" }
|
||||||
.parseAs<GroupListResponse>(MdUtil.jsonParser)
|
.map { it.id }
|
||||||
.results.map { group -> Pair(group.data.id, group.data.attributes.name) }
|
.distinct()
|
||||||
}.flatten().toMap()
|
.toList()
|
||||||
}.getOrNull() ?: emptyMap()
|
|
||||||
|
|
||||||
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 {
|
suspend fun fetchRandomMangaId(): String {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package exh.md.utils
|
package exh.md.utils
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
enum class MdLang(val lang: String, val prettyPrint: String, val extLang: String = lang) {
|
enum class MdLang(val lang: String, val prettyPrint: String, val extLang: String = lang) {
|
||||||
ENGLISH("en", "English"),
|
ENGLISH("en", "English"),
|
||||||
JAPANESE("jp", "Japanese", "ja"),
|
JAPANESE("ja", "Japanese"),
|
||||||
POLISH("pl", "Polish"),
|
POLISH("pl", "Polish"),
|
||||||
SERBO_CROATIAN("rs", "Serbo-Croatian", "sh"),
|
SERBO_CROATIAN("rs", "Serbo-Croatian", "sh"),
|
||||||
DUTCH("nl", "Dutch"),
|
DUTCH("nl", "Dutch"),
|
||||||
@ -12,35 +13,35 @@ enum class MdLang(val lang: String, val prettyPrint: String, val extLang: String
|
|||||||
HUNGARIAN("hu", "Hungarian"),
|
HUNGARIAN("hu", "Hungarian"),
|
||||||
FRENCH("fr", "French"),
|
FRENCH("fr", "French"),
|
||||||
FINNISH("fi", "Finnish"),
|
FINNISH("fi", "Finnish"),
|
||||||
VIETNAMESE("vn", "Vietnamese", "vi"),
|
VIETNAMESE("vi", "Vietnamese"),
|
||||||
GREEK("gr", "Greek", "el"),
|
GREEK("el", "Greek"),
|
||||||
BULGARIAN("bg", "BULGARIN"),
|
BULGARIAN("bg", "BULGARIN"),
|
||||||
SPANISH_ES("es", "Spanish (Es)"),
|
SPANISH_ES("es", "Spanish (Es)"),
|
||||||
PORTUGUESE_BR("br", "Portuguese (Br)", "pt-BR"),
|
PORTUGUESE_BR("pt-br", "Portuguese (Br)", "pt-BR"),
|
||||||
PORTUGUESE("pt", "Portuguese (Pt)"),
|
PORTUGUESE("pt", "Portuguese (Pt)"),
|
||||||
SWEDISH("se", "Swedish", "sv"),
|
SWEDISH("sv", "Swedish"),
|
||||||
ARABIC("sa", "Arabic", "ar"),
|
ARABIC("ar", "Arabic"),
|
||||||
DANISH("dk", "Danish", "da"),
|
DANISH("da", "Danish"),
|
||||||
CHINESE_SIMPLIFIED("cn", "Chinese (Simp)", "zh"),
|
CHINESE_SIMPLIFIED("zh", "Chinese (Simp)", "zh-Hans"),
|
||||||
BENGALI("bd", "Bengali", "bn"),
|
BENGALI("bn", "Bengali"),
|
||||||
ROMANIAN("ro", "Romanian"),
|
ROMANIAN("ro", "Romanian"),
|
||||||
CZECH("cz", "Czech", "cs"),
|
CZECH("cs", "Czech"),
|
||||||
MONGOLIAN("mn", "Mongolian"),
|
MONGOLIAN("mn", "Mongolian"),
|
||||||
TURKISH("tr", "Turkish"),
|
TURKISH("tr", "Turkish"),
|
||||||
INDONESIAN("id", "Indonesian"),
|
INDONESIAN("id", "Indonesian"),
|
||||||
KOREAN("kr", "Korean", "ko"),
|
KOREAN("kr", "Korean", "ko"),
|
||||||
SPANISH_LATAM("mx", "Spanish (LATAM)", "es-la"),
|
SPANISH_LATAM("es-la", "Spanish (LATAM)", "es-419"),
|
||||||
PERSIAN("ir", "Persian", "fa"),
|
PERSIAN("fa", "Persian"),
|
||||||
MALAY("my", "Malay", "ms"),
|
MALAY("ms", "Malay"),
|
||||||
THAI("th", "Thai"),
|
THAI("th", "Thai"),
|
||||||
CATALAN("ct", "Catalan", "ca"),
|
CATALAN("ca", "Catalan"),
|
||||||
FILIPINO("ph", "Filipino", "fi"),
|
FILIPINO("tl", "Filipino", "fil"),
|
||||||
CHINESE_TRAD("hk", "Chinese (Trad)", "zh-hk"),
|
CHINESE_TRAD("zh-hk", "Chinese (Trad)", "zh-Hant"),
|
||||||
UKRAINIAN("ua", "Ukrainian", "uk"),
|
UKRAINIAN("uk", "Ukrainian"),
|
||||||
BURMESE("mm", "Burmese", "my"),
|
BURMESE("my", "Burmese"),
|
||||||
LINTHUANIAN("lt", "Lithuanian"),
|
LINTHUANIAN("lt", "Lithuanian"),
|
||||||
HEBREW("il", "Hebrew", "he"),
|
HEBREW("he", "Hebrew"),
|
||||||
HINDI("in", "Hindi", "hi"),
|
HINDI("hi", "Hindi"),
|
||||||
NORWEGIAN("no", "Norwegian")
|
NORWEGIAN("no", "Norwegian")
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -61,6 +61,8 @@ class MdUtil {
|
|||||||
addQueryParameter("limit", "500")
|
addQueryParameter("limit", "500")
|
||||||
addQueryParameter("offset", offset.toString())
|
addQueryParameter("offset", offset.toString())
|
||||||
addQueryParameter("locales[]", language)
|
addQueryParameter("locales[]", language)
|
||||||
|
addQueryParameter("order[volume]", "desc")
|
||||||
|
addQueryParameter("order[chapter]", "desc")
|
||||||
}.build().toString()
|
}.build().toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user