[Shinigami] Fixes

Koitharu 1 year ago
parent b24741678c
commit d2b2578a3a
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -6,14 +6,11 @@ import org.koitharu.kotatsu.parsers.MangaSourceParser
import org.koitharu.kotatsu.parsers.config.ConfigKey
import org.koitharu.kotatsu.parsers.core.LegacyPagedMangaParser
import org.koitharu.kotatsu.parsers.model.*
import org.koitharu.kotatsu.parsers.network.UserAgents
import org.koitharu.kotatsu.parsers.util.*
import org.koitharu.kotatsu.parsers.util.json.*
import java.text.SimpleDateFormat
import java.util.*
import org.koitharu.kotatsu.parsers.Broken
@Broken("TODO: Add author search")
@MangaSourceParser("SHINIGAMI", "Shinigami", "id")
internal class Shinigami(context: MangaLoaderContext) :
LegacyPagedMangaParser(context, MangaParserSource.SHINIGAMI, 24) {
@ -47,12 +44,12 @@ internal class Shinigami(context: MangaLoaderContext) :
availableStates = EnumSet.of(
MangaState.ONGOING,
MangaState.FINISHED,
MangaState.PAUSED
MangaState.PAUSED,
),
availableContentTypes = EnumSet.of(
ContentType.MANGA,
ContentType.MANHWA,
ContentType.MANHUA
ContentType.MANHUA,
),
)
}
@ -82,14 +79,14 @@ internal class Shinigami(context: MangaLoaderContext) :
SortOrder.NEWEST, SortOrder.NEWEST_ASC -> "latest"
SortOrder.RATING, SortOrder.RATING_ASC -> "rating"
else -> "latest"
}
},
)
append("&sort_order=")
append(
when (order) {
SortOrder.POPULARITY_ASC, SortOrder.NEWEST_ASC, SortOrder.RATING_ASC -> "asc"
else -> "desc"
}
},
)
filter.states.oneOrThrowIfMany()?.let {
@ -100,7 +97,7 @@ internal class Shinigami(context: MangaLoaderContext) :
MangaState.ONGOING -> "ongoing"
MangaState.PAUSED -> "hiatus"
else -> ""
}
},
)
}
@ -113,7 +110,7 @@ internal class Shinigami(context: MangaLoaderContext) :
ContentType.MANHUA -> "manhua"
ContentType.MANHWA -> "manhwa"
else -> ""
}
},
)
}
}
@ -130,6 +127,11 @@ internal class Shinigami(context: MangaLoaderContext) :
append("&genre_exclude_mode=and")
}
if (!filter.author.isNullOrEmpty()) {
append("&author=")
append(filter.author.lowercase().replace(' ', '-').urlEncoded())
}
if (!filter.query.isNullOrEmpty()) {
append("&q=")
val encodedQuery = filter.query.splitByWhitespace()
@ -150,10 +152,9 @@ internal class Shinigami(context: MangaLoaderContext) :
url = "/manga/detail/$id",
publicUrl = "https://$domain/series/$id",
title = jo.getString("title"),
altTitles = setOf(jo.optString("alternative_title") ?: ""),
coverUrl = jo.getString("cover_image_url"),
largeCoverUrl = jo.optString("cover_portrait_url")
.takeIf { it.isNotEmpty() },
altTitles = setOfNotNull(jo.getStringOrNull("alternative_title")),
coverUrl = jo.getStringOrNull("cover_image_url"),
largeCoverUrl = jo.getStringOrNull("cover_portrait_url"),
authors = jo.optJSONObject("taxonomy")
?.optJSONArray("Author")
?.mapJSONToSet { x ->
@ -164,26 +165,26 @@ internal class Shinigami(context: MangaLoaderContext) :
?.mapJSONToSet { x ->
MangaTag(
key = x.getString("slug"),
title = x.getString("name"),
source = source
title = x.getString("name").toTitleCase(sourceLocale),
source = source,
)
}.orEmpty(),
state = when (jo.getInt("status")) {
state = when (jo.getIntOrDefault("status", 0)) {
1 -> MangaState.ONGOING
2 -> MangaState.FINISHED
3 -> MangaState.PAUSED
else -> null
},
description = jo.optString("description"),
description = jo.getStringOrNull("description"),
contentRating = null,
source = source,
rating = RATING_UNKNOWN
rating = RATING_UNKNOWN,
)
}
}
override suspend fun getDetails(manga: Manga): Manga {
val json = webClient.httpGet("https://$apiSuffix" + manga.url).parseJson()
val json = webClient.httpGet("https://$apiSuffix${manga.url}").parseJson()
val jo = json.getJSONObject("data")
val id = jo.getString("manga_id")
@ -196,22 +197,21 @@ internal class Shinigami(context: MangaLoaderContext) :
title = x.getString("name"),
source = source,
)
}.orEmpty(),
} ?: manga.tags,
authors = jo.optJSONObject("taxonomy")
?.optJSONArray("Author")
?.mapJSONToSet { x ->
x.getString("name")
}.orEmpty(),
state = when (jo.getInt("status")) {
} ?: manga.authors,
state = when (jo.getIntOrDefault("status", 0)) {
1 -> MangaState.ONGOING
2 -> MangaState.FINISHED
3 -> MangaState.PAUSED
else -> null
},
description = jo.optString("description"),
largeCoverUrl = jo.optString("cover_portrait_url")
.takeIf { it.isNotEmpty() },
chapters = getChapters(id)
description = jo.getStringOrNull("description"),
largeCoverUrl = jo.getStringOrNull("cover_portrait_url"),
chapters = getChapters(id),
)
}
@ -222,21 +222,18 @@ internal class Shinigami(context: MangaLoaderContext) :
return data.mapJSON { jo ->
val chapterId = jo.getString("chapter_id")
val number = jo.getInt("chapter_number")
val title = jo.optString("chapter_title")
.takeIf { it.isNotEmpty() }
?: "Chapter $number"
val title = jo.getStringOrNull("chapter_title")
MangaChapter(
id = generateUid(chapterId),
title = title,
number = number.toFloat(),
number = jo.getFloatOrDefault("chapter_number", 0f),
url = "chapter/detail/$chapterId",
scanlator = null,
uploadDate = jo.getString("release_date").parseDate(),
branch = null,
source = source,
volume = 0
volume = 0,
)
}
}
@ -250,7 +247,7 @@ internal class Shinigami(context: MangaLoaderContext) :
return List(datas.length()) { i ->
val imgExt = datas.getString(i)
val imageUrl = "https://$cdnSuffix" + basePath + imgExt
val imageUrl = "https://$cdnSuffix$basePath$imgExt"
MangaPage(
id = generateUid(imageUrl),
@ -267,7 +264,7 @@ internal class Shinigami(context: MangaLoaderContext) :
return json.getJSONArray("data").mapJSONToSet { x ->
MangaTag(
key = x.getString("slug"),
title = x.getString("name"),
title = x.getString("name").toTitleCase(sourceLocale),
source = source,
)
}

Loading…
Cancel
Save