fix manga group order and update time mismatch (#9213)

This commit is contained in:
sunbeams001 2021-09-24 22:10:04 +08:00 committed by GitHub
parent a03a505b78
commit e57d8438fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 20 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'CopyManga'
pkgNameSuffix = 'zh.copymanga'
extClass = '.CopyManga'
extVersionCode = 17
extVersionCode = 18
}
apply from: "$rootDir/common.gradle"

View File

@ -203,32 +203,24 @@ class CopyManga : ConfigurableSource, HttpSource() {
val retChapter = ArrayList<SChapter>()
// Get chapters according to groups
chapterGroups.keys().forEach { groupName ->
val keys = chapterGroups.keys().asSequence().toList()
keys.filter { it -> it == "default" }.forEach { groupName ->
run {
val chapterGroup = chapterGroups.getJSONObject(groupName)
fillChapters(chapterGroup, retChapter, comicPathWord)
}
}
// group's last update time
val groupLastUpdateTime =
chapterGroup.optJSONObject("last_chapter")?.optString("datetime_created")
// chapters in the group to
val chapterArray = chapterGroup.optJSONArray("chapters")
if (chapterArray != null) {
for (i in 0 until chapterArray.length()) {
val chapter = chapterArray.getJSONObject(i)
retChapter.add(
SChapter.create().apply {
name = chapter.getString("name")
date_upload = stringToUnixTimestamp(groupLastUpdateTime)
url = "/comic/$comicPathWord/chapter/${chapter.getString("id")}"
}
)
}
}
val otherChapters = ArrayList<SChapter>()
keys.filter { it -> it != "default" }.forEach { groupName ->
run {
val chapterGroup = chapterGroups.getJSONObject(groupName)
fillChapters(chapterGroup, otherChapters, comicPathWord)
}
}
// place others to top, as other group updates not so often
retChapter.addAll(0, otherChapters)
return retChapter.asReversed()
}
@ -422,6 +414,27 @@ class CopyManga : ConfigurableSource, HttpSource() {
return manga
}
private fun fillChapters(chapterGroup: JSONObject, retChapter: ArrayList<SChapter>, comicPathWord: String?) {
// group's last update time
val groupLastUpdateTime =
chapterGroup.optJSONObject("last_chapter")?.optString("datetime_created")
// chapters in the group to
val chapterArray = chapterGroup.optJSONArray("chapters")
if (chapterArray != null) {
for (i in 0 until chapterArray.length()) {
val chapter = chapterArray.getJSONObject(i)
retChapter.add(
SChapter.create().apply {
name = chapter.getString("name")
url = "/comic/$comicPathWord/chapter/${chapter.getString("id")}"
}
)
}
}
retChapter.lastOrNull()?.date_upload = stringToUnixTimestamp(groupLastUpdateTime)
}
private fun byteArrayToHexString(byteArray: ByteArray): String {
var sb = ""
for (b in byteArray) {