Comick: filter out delayed chapters (#3161)

filter out delayed chapters
This commit is contained in:
AwkwardPeak7 2024-05-22 10:33:37 +05:00 committed by GitHub
parent 07c9a5cbec
commit c2a3a40b05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 3 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Comick'
extClass = '.ComickFactory'
extVersionCode = 44
extVersionCode = 45
isNsfw = true
}

View File

@ -27,6 +27,10 @@ import okhttp3.Response
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.TimeZone
import java.util.concurrent.TimeUnit
import kotlin.math.min
@ -422,13 +426,31 @@ abstract class Comick(
.substringBefore("/chapters")
.substringAfter(apiUrl)
val currentTimestamp = System.currentTimeMillis()
return chapterListResponse.chapters
.filter {
it.groups.map { g -> g.lowercase() }.intersect(preferences.ignoredGroups).isEmpty()
val publishTime = try {
publishedDateFormat.parse(it.publishedAt)!!.time
} catch (_: ParseException) {
0L
}
val publishedChapter = publishTime <= currentTimestamp
val noGroupBlock = it.groups.map { g -> g.lowercase() }
.intersect(preferences.ignoredGroups)
.isEmpty()
publishedChapter && noGroupBlock
}
.map { it.toSChapter(mangaUrl) }
}
private val publishedDateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH).apply {
timeZone = TimeZone.getTimeZone("UTC")
}
override fun getChapterUrl(chapter: SChapter): String {
return "$baseUrl${chapter.url}"
}

View File

@ -170,7 +170,8 @@ class Chapter(
private val hid: String,
private val lang: String = "",
private val title: String = "",
@SerialName("created_at") val createdAt: String = "",
@SerialName("created_at") private val createdAt: String = "",
@SerialName("publish_at") val publishedAt: String = "",
private val chap: String = "",
private val vol: String = "",
@SerialName("group_name") val groups: List<String> = emptyList(),