Bilibili: Show paid chapters in chapter list (#18437)

* Bilibili: Show paid chapters in chapter list

* lint
This commit is contained in:
AntsyLich 2023-10-09 03:47:26 +06:00 committed by GitHub
parent 7eb7c2567a
commit 8c8a015803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 33 deletions

View File

@ -123,12 +123,7 @@ abstract class BilibiliComics(lang: String) : Bilibili(
val userEpisodesResponse = client.newCall(userEpisodesRequest).execute()
val unlockedEpisodes = userEpisodesParse(userEpisodesResponse)
return comic.episodeList
.filter { episode ->
(episode.payMode == 0 && episode.payGold == 0) ||
episode.id in unlockedEpisodes
}
.map { ep -> chapterFromObject(ep, comic.id) }
return comic.episodeList.map { ep -> chapterFromObject(ep, comic.id, isUnlocked = ep.id in unlockedEpisodes) }
}
private fun userEpisodesRequest(comicId: Int): Request {

View File

@ -204,7 +204,7 @@ abstract class Bilibili(
title = comic.title
author = comic.authorName.joinToString()
genre = comic.genres(intl.pricePaid, EMOJI_LOCKED).joinToString()
genre = comic.styles.joinToString()
status = when {
comic.isFinish == 1 -> SManga.COMPLETED
comic.isOnHiatus -> SManga.ON_HIATUS
@ -215,11 +215,10 @@ abstract class Bilibili(
append("${intl.hasPaidChaptersWarning(comic.paidChaptersCount)}\n\n")
}
append("${comic.classicLines}\n\n")
append("${intl.informationTitle}:")
append("\n${intl.totalChapterCount}: ${intl.localize(comic.episodeList.size)}")
append(comic.classicLines)
if (comic.updateWeekdays.isNotEmpty() && status == SManga.ONGOING) {
append("\n\n${intl.informationTitle}:")
append("\n${intl.getUpdateDays(comic.updateWeekdays)}")
}
}
@ -237,13 +236,21 @@ abstract class Bilibili(
return emptyList()
}
return result.data!!.episodeList
.filter { episode -> episode.payMode == 0 && episode.payGold == 0 }
.map { ep -> chapterFromObject(ep, result.data.id) }
return result.data!!.episodeList.map { ep -> chapterFromObject(ep, result.data.id) }
}
protected open fun chapterFromObject(episode: BilibiliEpisodeDto, comicId: Int): SChapter = SChapter.create().apply {
name = episode.shortTitle.plus(if (episode.title.isNotBlank()) " - ${episode.title}" else "")
protected open fun chapterFromObject(episode: BilibiliEpisodeDto, comicId: Int, isUnlocked: Boolean = false): SChapter = SChapter.create().apply {
name = buildString {
if (episode.isPaid && !isUnlocked) {
append("$EMOJI_LOCKED ")
}
append(episode.shortTitle)
if (episode.title.isNotBlank()) {
append(" - ${episode.title}")
}
}
date_upload = episode.publicationTime.toDate()
url = "/mc$comicId/${episode.id}"
}

View File

@ -34,10 +34,7 @@ data class BilibiliComicDto(
get() = paidChaptersCount > 0
val paidChaptersCount: Int
get() = episodeList.filter { episode -> episode.payMode == 1 && episode.payGold > 0 }.size
fun genres(paidLabel: String, emoji: String): List<String> =
(if (hasPaidChapters) listOf("$emoji $paidLabel") else emptyList()) + styles
get() = episodeList.filter { it.isPaid }.size
}
@Serializable
@ -50,7 +47,9 @@ data class BilibiliEpisodeDto(
@SerialName("pub_time") val publicationTime: String,
@SerialName("short_title") val shortTitle: String,
val title: String,
)
) {
val isPaid = payMode == 1 && payGold > 0
}
@Serializable
data class BilibiliReader(

View File

@ -10,7 +10,7 @@ class BilibiliGenerator : ThemeSourceGenerator {
override val themeClass = "Bilibili"
override val baseVersionCode: Int = 8
override val baseVersionCode: Int = 9
override val sources = listOf(
MultiLang(

View File

@ -54,9 +54,8 @@ class BilibiliIntl(private val lang: String) {
"actualice la lista de capítulos para leerlos."
else ->
"${Bilibili.EMOJI_WARNING} WARNING: This series has ${chapterCount.localized} paid " +
"chapters that were filtered out from the chapter list. If you have already " +
"unlocked and have any in your account, sign in through WebView and refresh " +
"the chapter list to read them."
"chapters. If you have any unlocked in your account then sign in through WebView " +
"to be able to read them."
}
val imageQualityPrefTitle: String = when (lang) {
@ -85,6 +84,7 @@ class BilibiliIntl(private val lang: String) {
else -> "Interest"
}
@Suppress("UNUSED") // In BilibiliManga
val sortPopular: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "人气推荐"
INDONESIAN -> "Populer"
@ -101,11 +101,13 @@ class BilibiliIntl(private val lang: String) {
else -> "Updated"
}
@Suppress("UNUSED") // In BilibiliManga
val sortAdded: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "上架时间"
else -> "Added"
}
@Suppress("UNUSED") // In BilibiliManga
val sortFollowers: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "追漫人数"
else -> "Followers count"
@ -135,6 +137,7 @@ class BilibiliIntl(private val lang: String) {
else -> "Completed"
}
@Suppress("UNUSED") // In BilibiliManga
val priceAll: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "全部"
INDONESIAN -> "Semua"
@ -142,6 +145,7 @@ class BilibiliIntl(private val lang: String) {
else -> "All"
}
@Suppress("UNUSED") // In BilibiliManga
val priceFree: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "免费"
INDONESIAN -> "Bebas"
@ -149,6 +153,7 @@ class BilibiliIntl(private val lang: String) {
else -> "Free"
}
@Suppress("UNUSED") // In BilibiliManga
val pricePaid: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "付费"
INDONESIAN -> "Dibayar"
@ -156,17 +161,20 @@ class BilibiliIntl(private val lang: String) {
else -> "Paid"
}
@Suppress("UNUSED") // In BilibiliManga
val priceWaitForFree: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "等就免费"
else -> "Wait for free"
}
@Suppress("UNUSED") // In BilibiliComics
val failedToRefreshToken: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "无法刷新令牌。请打开 WebView 修正错误。"
SPANISH -> "Error al actualizar el token. Abra el WebView para solucionar este error."
else -> "Failed to refresh the token. Open the WebView to fix this error."
}
@Suppress("UNUSED") // In BilibiliComics
val failedToGetCredential: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "无法获取阅读章节所需的凭证。"
SPANISH -> "Erro al obtener la credencial para leer el capítulo."
@ -179,12 +187,6 @@ class BilibiliIntl(private val lang: String) {
else -> "Information"
}
val totalChapterCount: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "章节总数"
SPANISH -> "Número total de capítulos"
else -> "Total chapter count"
}
private val updatesDaily: String = when (lang) {
CHINESE, SIMPLIFIED_CHINESE -> "每日更新"
SPANISH -> "Actualizaciones diarias"
@ -208,17 +210,17 @@ class BilibiliIntl(private val lang: String) {
return updatesEvery(days)
}
fun localize(value: Int) = value.localized
private val Int.localized: String
get() = numberFormat.format(this)
companion object {
const val CHINESE = "zh"
const val ENGLISH = "en"
const val INDONESIAN = "id"
const val SIMPLIFIED_CHINESE = "zh-Hans"
const val SPANISH = "es"
const val FRENCH = "fr"
@Suppress("UNUSED") // In BilibiliComics
const val ENGLISH = "en"
}
}