MangaFire: parse chapter dates (#16395)

* MangaFire: parse chapter dates

* ignore relative dates
This commit is contained in:
stevenyomi 2023-05-10 21:40:15 +08:00 committed by GitHub
parent ba11a1c543
commit 628a076e32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
@ -20,6 +21,8 @@ import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import org.jsoup.select.Evaluator import org.jsoup.select.Evaluator
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.text.SimpleDateFormat
import java.util.Locale
open class MangaFire( open class MangaFire(
override val lang: String, override val lang: String,
@ -31,7 +34,7 @@ open class MangaFire(
private val json: Json by injectLazy() private val json: Json by injectLazy()
override val client = network.client.newBuilder() override val client = network.cloudflareClient.newBuilder()
.addInterceptor(ImageInterceptor) .addInterceptor(ImageInterceptor)
.build() .build()
@ -140,6 +143,26 @@ open class MangaFire(
return container.children().map { it.child(0) } return container.children().map { it.child(0) }
} }
override fun updateChapterList(manga: SManga, chapters: List<SChapter>) {
val document = client.newCall(mangaDetailsRequest(manga)).execute().asJsoup()
val elements = document.selectFirst(".chapter-list[data-name=$langCode]")!!.children()
val chapterCount = chapters.size
if (elements.size != chapterCount) throw Exception("Chapter count doesn't match. Try updating again.")
val dateFormat = SimpleDateFormat("MMM dd, yyyy", Locale.US)
for (i in 0 until chapterCount) {
val chapter = chapters[i]
val element = elements[i]
val number = element.attr("data-number").toFloatOrNull() ?: -1f
if (chapter.chapter_number != number) throw Exception("Chapter number doesn't match. Try updating again.")
val date = element.select(Evaluator.Tag("span"))[1].ownText()
chapter.date_upload = try {
dateFormat.parse(date)!!.time
} catch (_: Throwable) {
0
}
}
}
override fun pageListRequest(chapter: SChapter): Request { override fun pageListRequest(chapter: SChapter): Request {
val typeAndId = chapter.url.substringAfterLast('#') val typeAndId = chapter.url.substringAfterLast('#')
return GET("$baseUrl/ajax/read/$typeAndId", headers) return GET("$baseUrl/ajax/read/$typeAndId", headers)

View File

@ -71,6 +71,8 @@ abstract class MangaReader : HttpSource(), ConfigurableSource {
override fun chapterListParse(response: Response) = throw UnsupportedOperationException() override fun chapterListParse(response: Response) = throw UnsupportedOperationException()
open fun updateChapterList(manga: SManga, chapters: List<SChapter>) = Unit
final override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> = Observable.fromCallable { final override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> = Observable.fromCallable {
val path = manga.url val path = manga.url
val isVolume = path.endsWith(VOLUME_URL_SUFFIX) val isVolume = path.endsWith(VOLUME_URL_SUFFIX)
@ -96,7 +98,7 @@ abstract class MangaReader : HttpSource(), ConfigurableSource {
} }
setUrlWithoutDomain(link.attr("href") + '#' + type + '/' + element.attr("data-id")) setUrlWithoutDomain(link.attr("href") + '#' + type + '/' + element.attr("data-id"))
} }
} }.also { if (!isVolume && it.isNotEmpty()) updateChapterList(manga, it) }
} }
final override fun getChapterUrl(chapter: SChapter) = baseUrl + chapter.url.substringBeforeLast('#') final override fun getChapterUrl(chapter: SChapter) = baseUrl + chapter.url.substringBeforeLast('#')

View File

@ -21,6 +21,7 @@ class MangaReaderGenerator : ThemeSourceGenerator {
baseUrl = "https://mangafire.to", baseUrl = "https://mangafire.to",
langs = listOf("en", "es", "es-419", "fr", "ja", "pt", "pt-BR"), langs = listOf("en", "es", "es-419", "fr", "ja", "pt", "pt-BR"),
isNsfw = true, isNsfw = true,
overrideVersionCode = 1,
), ),
) )