Skip to content

Commit

Permalink
[CuuTruyen] Fixes
Browse files Browse the repository at this point in the history
Fix timer + Add manga status for CuuTruyen
  • Loading branch information
dragonx943 authored Jan 3, 2025
2 parents 8ce6694 + f21aa28 commit a94adf4
Showing 1 changed file with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.koitharu.kotatsu.parsers.util.json.*
import java.net.HttpURLConnection
import java.text.SimpleDateFormat
import java.util.*
import java.util.TimeZone

@MangaSourceParser("CUUTRUYEN", "Cứu Truyện", "vi")
internal class CuuTruyenParser(context: MangaLoaderContext) :
Expand Down Expand Up @@ -55,6 +56,7 @@ internal class CuuTruyenParser(context: MangaLoaderContext) :
override suspend fun getFilterOptions(): MangaListFilterOptions {
return MangaListFilterOptions(
availableTags = availableTags(),
availableStates = EnumSet.of(MangaState.ONGOING, MangaState.FINISHED),
)
}

Expand Down Expand Up @@ -125,25 +127,39 @@ internal class CuuTruyenParser(context: MangaLoaderContext) :
}

override suspend fun getDetails(manga: Manga): Manga = coroutineScope {
val url = "https://" + domain + manga.url
val chapters = async {
webClient.httpGet("$url/chapters").parseJson().getJSONArray("data")
}
val json = webClient.httpGet(url).parseJson().getJSONObject("data")
val chapterDateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US)
val url = "https://" + domain + manga.url
val chapters = async {
webClient.httpGet("$url/chapters").parseJson().getJSONArray("data")
}
val json = webClient.httpGet(url).parseJson().getJSONObject("data")
val chapterDateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ROOT).apply {
timeZone = TimeZone.getTimeZone("GMT+7")
}
val tags = json.optJSONArray("tags")?.mapJSONToSet { jo ->
MangaTag(
title = jo.getString("name").toTitleCase(sourceLocale),
key = jo.getString("slug"),
source = source,
)
}.orEmpty()

// Testing: Add custom manga status using available tags
val state = when {
tags.any { it.key == "da-hoan-thanh" } -> MangaState.FINISHED
tags.any { it.key == "dang-tien-hanh" } -> MangaState.ONGOING
else -> null
}

manga.copy(
title = json.getStringOrNull("name") ?: manga.title,
isNsfw = json.getBooleanOrDefault("is_nsfw", manga.isNsfw),
// Remove old manga status from "tags"
val newTags = tags.filter { it.key != "da-hoan-thanh" && it.key != "dang-tien-hanh" }.toSet()

manga.copy(
title = json.getStringOrNull("name") ?: manga.title,
isNsfw = json.getBooleanOrDefault("is_nsfw", manga.isNsfw),
author = json.optJSONObject("author")?.getStringOrNull("name")?.substringBefore(','),
description = json.getString("full_description"),
tags = json.optJSONArray("tags")?.mapJSONToSet { jo ->
MangaTag(
title = jo.getString("name").toTitleCase(sourceLocale),
key = jo.getString("slug"),
source = source,
)
}.orEmpty(),
tags = newTags,
state = state,
chapters = chapters.await().mapJSON { jo ->
val chapterId = jo.getLong("id")
val number = jo.getFloatOrDefault("number", 0f)
Expand Down

0 comments on commit a94adf4

Please sign in to comment.