Fix wrong chapter numbers in Bilibili (#9885)

* Fix wrong chapter numbers in Bilibili.

* Use short_title in chapter_number too.

* Change extension name and remove explicit chapter_number.
This commit is contained in:
Alessandro Jean 2021-11-21 20:40:50 -03:00 committed by GitHub
parent d186bacf98
commit f3b1dcb056
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 22 deletions

View File

@ -3,10 +3,10 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization' apply plugin: 'kotlinx-serialization'
ext { ext {
extName = 'Bilibili Comics' extName = 'BILIBILI COMICS'
pkgNameSuffix = 'en.bilibilicomics' pkgNameSuffix = 'en.bilibilicomics'
extClass = '.BilibiliComics' extClass = '.BilibiliComics'
extVersionCode = 7 extVersionCode = 8
isNsfw = true isNsfw = true
} }

View File

@ -26,7 +26,6 @@ import okhttp3.Response
import org.jsoup.Jsoup import org.jsoup.Jsoup
import rx.Observable import rx.Observable
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.text.ParseException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -78,7 +77,7 @@ class BilibiliComics : HttpSource() {
} }
override fun popularMangaParse(response: Response): MangasPage { override fun popularMangaParse(response: Response): MangasPage {
val result = json.decodeFromString<BilibiliResultDto<List<BilibiliComicDto>>>(response.body!!.string()) val result = response.parseAs<List<BilibiliComicDto>>()
if (result.code != 0) { if (result.code != 0) {
return MangasPage(emptyList(), hasNextPage = false) return MangasPage(emptyList(), hasNextPage = false)
@ -122,7 +121,7 @@ class BilibiliComics : HttpSource() {
} }
override fun latestUpdatesParse(response: Response): MangasPage { override fun latestUpdatesParse(response: Response): MangasPage {
val result = json.decodeFromString<BilibiliResultDto<List<BilibiliComicDto>>>(response.body!!.string()) val result = response.parseAs<List<BilibiliComicDto>>()
if (result.code != 0) { if (result.code != 0) {
return MangasPage(emptyList(), hasNextPage = false) return MangasPage(emptyList(), hasNextPage = false)
@ -202,7 +201,7 @@ class BilibiliComics : HttpSource() {
} }
if (response.request.url.toString().contains("ClassPage")) { if (response.request.url.toString().contains("ClassPage")) {
val result = json.decodeFromString<BilibiliResultDto<List<BilibiliComicDto>>>(response.body!!.string()) val result = response.parseAs<List<BilibiliComicDto>>()
if (result.code != 0) { if (result.code != 0) {
return MangasPage(emptyList(), hasNextPage = false) return MangasPage(emptyList(), hasNextPage = false)
@ -214,7 +213,7 @@ class BilibiliComics : HttpSource() {
return MangasPage(comicList, hasNextPage) return MangasPage(comicList, hasNextPage)
} }
val result = json.decodeFromString<BilibiliResultDto<BilibiliSearchDto>>(response.body!!.string()) val result = response.parseAs<BilibiliSearchDto>()
if (result.code != 0) { if (result.code != 0) {
return MangasPage(emptyList(), hasNextPage = false) return MangasPage(emptyList(), hasNextPage = false)
@ -263,7 +262,7 @@ class BilibiliComics : HttpSource() {
} }
override fun mangaDetailsParse(response: Response): SManga = SManga.create().apply { override fun mangaDetailsParse(response: Response): SManga = SManga.create().apply {
val result = json.decodeFromString<BilibiliResultDto<BilibiliComicDto>>(response.body!!.string()) val result = response.parseAs<BilibiliComicDto>()
val comic = result.data!! val comic = result.data!!
title = comic.title title = comic.title
@ -279,21 +278,18 @@ class BilibiliComics : HttpSource() {
override fun chapterListRequest(manga: SManga): Request = mangaDetailsApiRequest(manga.url) override fun chapterListRequest(manga: SManga): Request = mangaDetailsApiRequest(manga.url)
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val result = json.decodeFromString<BilibiliResultDto<BilibiliComicDto>>(response.body!!.string()) val result = response.parseAs<BilibiliComicDto>()
if (result.code != 0) if (result.code != 0)
return emptyList() return emptyList()
return result.data!!.episodeList return result.data!!.episodeList
.filter { episode -> episode.isLocked.not() } .filterNot { episode -> episode.isLocked }
.map { ep -> chapterFromObject(ep, result.data.id) } .map { ep -> chapterFromObject(ep, result.data.id) }
} }
private fun chapterFromObject(episode: BilibiliEpisodeDto, comicId: Int): SChapter = SChapter.create().apply { private fun chapterFromObject(episode: BilibiliEpisodeDto, comicId: Int): SChapter = SChapter.create().apply {
name = "Ep. " + episode.order.toString().removeSuffix(".0") + name = "Ep. " + episode.shortTitle + " - " + episode.title
" - " + episode.title
chapter_number = episode.order
scanlator = this@BilibiliComics.name
date_upload = episode.publicationTime.substringBefore("T").toDate() date_upload = episode.publicationTime.substringBefore("T").toDate()
url = "/mc$comicId/${episode.id}" url = "/mc$comicId/${episode.id}"
} }
@ -318,7 +314,7 @@ class BilibiliComics : HttpSource() {
} }
override fun pageListParse(response: Response): List<Page> { override fun pageListParse(response: Response): List<Page> {
val result = json.decodeFromString<BilibiliResultDto<BilibiliReader>>(response.body!!.string()) val result = response.parseAs<BilibiliReader>()
if (result.code != 0) { if (result.code != 0) {
return emptyList() return emptyList()
@ -347,7 +343,7 @@ class BilibiliComics : HttpSource() {
} }
override fun imageUrlParse(response: Response): String { override fun imageUrlParse(response: Response): String {
val result = json.decodeFromString<BilibiliResultDto<List<BilibiliPageDto>>>(response.body!!.string()) val result = response.parseAs<List<BilibiliPageDto>>()
val page = result.data!![0] val page = result.data!![0]
return "${page.url}?token=${page.token}" return "${page.url}?token=${page.token}"
@ -394,12 +390,13 @@ class BilibiliComics : HttpSource() {
GenreFilter(getAllGenres()) GenreFilter(getAllGenres())
) )
private fun String.toDate(): Long { private inline fun <reified T> Response.parseAs(): BilibiliResultDto<T> = use {
return try { json.decodeFromString(it.body?.string().orEmpty())
DATE_FORMATTER.parse(this)?.time ?: 0L
} catch (e: ParseException) {
0L
} }
private fun String.toDate(): Long {
return runCatching { DATE_FORMATTER.parse(this)?.time }
.getOrNull() ?: 0L
} }
companion object { companion object {

View File

@ -33,8 +33,8 @@ data class BilibiliComicDto(
data class BilibiliEpisodeDto( data class BilibiliEpisodeDto(
val id: Int, val id: Int,
@SerialName("is_locked") val isLocked: Boolean, @SerialName("is_locked") val isLocked: Boolean,
@SerialName("ord") val order: Float,
@SerialName("pub_time") val publicationTime: String, @SerialName("pub_time") val publicationTime: String,
@SerialName("short_title") val shortTitle: String,
val title: String val title: String
) )