fix: fix the fix for MangaUpdates (#327)

Further filtering prevents the bad records from cancelling the whole operation
This commit is contained in:
TwistedUmbrellaX 2024-04-05 21:04:03 -04:00 committed by GitHub
parent dd994dcfab
commit 04538c52f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 8 deletions

View file

@ -993,12 +993,7 @@ fun countDown(media: Media, view: ViewGroup) {
fun sinceWhen(media: Media, view: ViewGroup) { fun sinceWhen(media: Media, view: ViewGroup) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
MangaUpdates().search(media.name ?: media.nameRomaji, media.startDate)?.let { MangaUpdates().search(media.name ?: media.nameRomaji, media.startDate)?.let {
val latestChapter = it.metadata.series.latestChapter ?: it.record.chapter?.let { chapter -> val latestChapter = MangaUpdates.getLatestChapter(it)
if (chapter.contains("-"))
chapter.split("-")[1].trim()
else
chapter
}?.toIntOrNull() ?: return@launch
val timeSince = (System.currentTimeMillis() - val timeSince = (System.currentTimeMillis() -
(it.metadata.series.lastUpdated!!.timestamp * 1000)) / 1000 (it.metadata.series.lastUpdated!!.timestamp * 1000)) / 1000

View file

@ -34,8 +34,18 @@ class MangaUpdates {
} }
} }
val res = client.post(apiUrl, json = query).parsed<MangaUpdatesResponse>() val res = client.post(apiUrl, json = query).parsed<MangaUpdatesResponse>()
res.results?.forEach{ println("MangaUpdates: $it") } res.results?.first {
res.results?.first { it.metadata.series.lastUpdated?.timestamp != null } it.metadata.series.lastUpdated?.timestamp != null
&& (it.metadata.series.latestChapter != null
|| (it.record.volume.isNullOrBlank() && it.record.chapter != null))
}
}
}
companion object {
fun getLatestChapter(results: MangaUpdatesResponse.Results): Int {
return results.metadata.series.latestChapter
?: results.record.chapter!!.substringAfterLast("-").trim().toInt()
} }
} }