[MangaDex] Chapters fixes
This commit is contained in:
@@ -290,28 +290,31 @@ internal class MangaDexParser(context: MangaLoaderContext) : MangaParser(context
|
|||||||
Locale.ROOT,
|
Locale.ROOT,
|
||||||
)
|
)
|
||||||
val chaptersBuilder = ChaptersListBuilder(list.size)
|
val chaptersBuilder = ChaptersListBuilder(list.size)
|
||||||
val branchedChapters = HashMap<String?, HashMap<Float, MangaChapter>>()
|
val branchedChapters = HashMap<String?, HashMap<Pair<Int, Float>, MangaChapter>>()
|
||||||
for (jo in list) {
|
for (jo in list) {
|
||||||
val id = jo.getString("id")
|
val id = jo.getString("id")
|
||||||
val attrs = jo.getJSONObject("attributes")
|
val attrs = jo.getJSONObject("attributes")
|
||||||
if (!attrs.isNull("externalUrl")) {
|
if (!attrs.isNull("externalUrl")) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val number = jo.getJSONObject("attributes").getFloatOrDefault("chapter", 0f)
|
val number = attrs.getFloatOrDefault("chapter", 0f)
|
||||||
|
val volume = attrs.getIntOrDefault("volume", 0)
|
||||||
val locale = attrs.getStringOrNull("translatedLanguage")?.let { Locale.forLanguageTag(it) }
|
val locale = attrs.getStringOrNull("translatedLanguage")?.let { Locale.forLanguageTag(it) }
|
||||||
val lc = locale?.getDisplayName(locale)?.toTitleCase(locale)
|
val lc = locale?.getDisplayName(locale)?.toTitleCase(locale)
|
||||||
val relations = jo.getJSONArray("relationships").associateByKey("type")
|
val relations = jo.getJSONArray("relationships").associateByKey("type")
|
||||||
val team = relations["scanlation_group"]?.getJSONObject("attributes")?.getStringOrNull("name")
|
val team = relations["scanlation_group"]?.optJSONObject("attributes")?.getStringOrNull("name")
|
||||||
?.takeUnless { it.isBlank() }
|
|
||||||
val branch = (list.indices).firstNotNullOf { i ->
|
val branch = (list.indices).firstNotNullOf { i ->
|
||||||
val b = if (i == 0) lc else "$lc ($i)"
|
val b = if (i == 0) lc else "$lc ($i)"
|
||||||
if (branchedChapters[b]?.get(number) == null) b else null
|
if (branchedChapters[b]?.get(volume to number) == null) b else null
|
||||||
}
|
}
|
||||||
val chapter = MangaChapter(
|
val chapter = MangaChapter(
|
||||||
id = generateUid(id),
|
id = generateUid(id),
|
||||||
name = attrs.getStringOrNull("title")?.takeUnless(String::isEmpty)
|
name = attrs.getStringOrNull("title") ?: buildString {
|
||||||
?: "Chapter #${number.formatSimple()}",
|
if (volume > 0) append("Vol. ").append(volume).append(' ')
|
||||||
number = if (number <= 0f) (branchedChapters[branch]?.size?.plus(1) ?: 0) else number.toInt(),
|
append("Chapter ").append(number.formatSimple())
|
||||||
|
},
|
||||||
|
number = number,
|
||||||
|
volume = volume,
|
||||||
url = id,
|
url = id,
|
||||||
scanlator = team,
|
scanlator = team,
|
||||||
uploadDate = dateFormat.tryParse(attrs.getString("publishAt")),
|
uploadDate = dateFormat.tryParse(attrs.getString("publishAt")),
|
||||||
@@ -319,7 +322,7 @@ internal class MangaDexParser(context: MangaLoaderContext) : MangaParser(context
|
|||||||
source = source,
|
source = source,
|
||||||
)
|
)
|
||||||
if (chaptersBuilder.add(chapter)) {
|
if (chaptersBuilder.add(chapter)) {
|
||||||
branchedChapters.getOrPut(branch, ::HashMap)[number] = chapter
|
branchedChapters.getOrPut(branch, ::HashMap)[volume to number] = chapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return chaptersBuilder.toList()
|
return chaptersBuilder.toList()
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ package org.koitharu.kotatsu.parsers
|
|||||||
import org.junit.jupiter.params.provider.EnumSource
|
import org.junit.jupiter.params.provider.EnumSource
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
|
||||||
@EnumSource(MangaSource::class, names = ["LOCAL", "DUMMY"], mode = EnumSource.Mode.EXCLUDE)
|
@EnumSource(MangaSource::class, names = ["MANGADEX"], mode = EnumSource.Mode.INCLUDE)
|
||||||
internal annotation class MangaSources
|
internal annotation class MangaSources
|
||||||
|
|||||||
Reference in New Issue
Block a user