Skip to content

Commit

Permalink
fix: fix the fix for MangaUpdates (#327)
Browse files Browse the repository at this point in the history
Further filtering prevents the bad records from cancelling the whole operation
  • Loading branch information
TwistedUmbrellaX authored Apr 6, 2024
1 parent dd994dc commit 04538c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 1 addition & 6 deletions app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,7 @@ fun countDown(media: Media, view: ViewGroup) {
fun sinceWhen(media: Media, view: ViewGroup) {
CoroutineScope(Dispatchers.IO).launch {
MangaUpdates().search(media.name ?: media.nameRomaji, media.startDate)?.let {
val latestChapter = it.metadata.series.latestChapter ?: it.record.chapter?.let { chapter ->
if (chapter.contains("-"))
chapter.split("-")[1].trim()
else
chapter
}?.toIntOrNull() ?: return@launch
val latestChapter = MangaUpdates.getLatestChapter(it)
val timeSince = (System.currentTimeMillis() -
(it.metadata.series.lastUpdated!!.timestamp * 1000)) / 1000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ class MangaUpdates {
}
}
val res = client.post(apiUrl, json = query).parsed<MangaUpdatesResponse>()
res.results?.forEach{ println("MangaUpdates: $it") }
res.results?.first { it.metadata.series.lastUpdated?.timestamp != null }
res.results?.first {
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()
}
}

Expand Down

0 comments on commit 04538c5

Please sign in to comment.