MangaFire: parse chapter dates (#16395)
* MangaFire: parse chapter dates * ignore relative dates
This commit is contained in:
parent
ba11a1c543
commit
628a076e32
|
@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.source.model.FilterList
|
|||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
@ -20,6 +21,8 @@ import org.jsoup.nodes.Document
|
|||
import org.jsoup.nodes.Element
|
||||
import org.jsoup.select.Evaluator
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
open class MangaFire(
|
||||
override val lang: String,
|
||||
|
@ -31,7 +34,7 @@ open class MangaFire(
|
|||
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
override val client = network.client.newBuilder()
|
||||
override val client = network.cloudflareClient.newBuilder()
|
||||
.addInterceptor(ImageInterceptor)
|
||||
.build()
|
||||
|
||||
|
@ -140,6 +143,26 @@ open class MangaFire(
|
|||
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 {
|
||||
val typeAndId = chapter.url.substringAfterLast('#')
|
||||
return GET("$baseUrl/ajax/read/$typeAndId", headers)
|
||||
|
|
|
@ -71,6 +71,8 @@ abstract class MangaReader : HttpSource(), ConfigurableSource {
|
|||
|
||||
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 {
|
||||
val path = manga.url
|
||||
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"))
|
||||
}
|
||||
}
|
||||
}.also { if (!isVolume && it.isNotEmpty()) updateChapterList(manga, it) }
|
||||
}
|
||||
|
||||
final override fun getChapterUrl(chapter: SChapter) = baseUrl + chapter.url.substringBeforeLast('#')
|
||||
|
|
|
@ -21,6 +21,7 @@ class MangaReaderGenerator : ThemeSourceGenerator {
|
|||
baseUrl = "https://mangafire.to",
|
||||
langs = listOf("en", "es", "es-419", "fr", "ja", "pt", "pt-BR"),
|
||||
isNsfw = true,
|
||||
overrideVersionCode = 1,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue