batoto: exception on removed comics and optimize (#6584)

* batoto: exception on removed comics and optimize

* date parsing

* lint

* add headers
This commit is contained in:
AwkwardPeak7 2024-12-12 18:14:24 +05:00 committed by Draff
parent 21d51725e5
commit 44b820eca0
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 39 additions and 27 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Bato.to'
extClass = '.BatoToFactory'
extVersionCode = 42
extVersionCode = 43
isNsfw = true
}

View File

@ -38,6 +38,7 @@ import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
@ -116,7 +117,7 @@ open class BatoTo(
.build()
override fun latestUpdatesRequest(page: Int): Request {
return GET("$baseUrl/browse?langs=$siteLang&sort=update&page=$page")
return GET("$baseUrl/browse?langs=$siteLang&sort=update&page=$page", headers)
}
override fun latestUpdatesSelector(): String {
@ -140,7 +141,7 @@ open class BatoTo(
override fun latestUpdatesNextPageSelector() = "div#mainer nav.d-none .pagination .page-item:last-of-type:not(.disabled)"
override fun popularMangaRequest(page: Int): Request {
return GET("$baseUrl/browse?langs=$siteLang&sort=views_a&page=$page")
return GET("$baseUrl/browse?langs=$siteLang&sort=views_a&page=$page", headers)
}
override fun popularMangaSelector() = latestUpdatesSelector()
@ -362,44 +363,55 @@ open class BatoTo(
else -> SManga.UNKNOWN
}
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
val url = client.newCall(
GET(
when {
manga.url.startsWith("http") -> manga.url
else -> "$baseUrl${manga.url}"
},
),
).execute().asJsoup()
if (getAltChapterListPref() || checkChapterLists(url)) {
val id = manga.url.substringBeforeLast("/").substringAfterLast("/").trim()
return client.newCall(GET("$baseUrl/rss/series/$id.xml"))
.asObservableSuccess()
.map { altChapterParse(it, manga.title) }
}
return super.fetchChapterList(manga)
}
private fun altChapterParse(response: Response, title: String): List<SChapter> {
private fun altChapterParse(response: Response): List<SChapter> {
return Jsoup.parse(response.body.string(), response.request.url.toString(), Parser.xmlParser())
.select("channel > item").map { item ->
SChapter.create().apply {
url = item.selectFirst("guid")!!.text()
name = item.selectFirst("title")!!.text().substringAfter(title).trim()
date_upload = SimpleDateFormat("E, dd MMM yyyy H:m:s Z", Locale.US).parse(item.selectFirst("pubDate")!!.text())?.time ?: 0L
name = item.selectFirst("title")!!.text()
date_upload = parseAltChapterDate(item.selectFirst("pubDate")!!.text())
}
}
}
private val altDateFormat = SimpleDateFormat("E, dd MMM yyyy H:m:s Z", Locale.US)
private fun parseAltChapterDate(date: String): Long {
return try {
altDateFormat.parse(date)!!.time
} catch (_: ParseException) {
0L
}
}
private fun checkChapterLists(document: Document): Boolean {
return document.select(".episode-list > .alert-warning").text().contains("This comic has been marked as deleted and the chapter list is not available.")
}
override fun chapterListRequest(manga: SManga): Request {
if (manga.url.startsWith("http")) {
return GET(manga.url, headers)
return if (getAltChapterListPref()) {
val id = manga.url.substringBeforeLast("/").substringAfterLast("/").trim()
GET("$baseUrl/rss/series/$id.xml", headers)
} else if (manga.url.startsWith("http")) {
GET(manga.url, headers)
} else {
super.chapterListRequest(manga)
}
return super.chapterListRequest(manga)
}
override fun chapterListParse(response: Response): List<SChapter> {
if (getAltChapterListPref()) {
return altChapterParse(response)
}
val document = response.asJsoup()
if (checkChapterLists(document)) {
throw Exception("Deleted from site")
}
return document.select(chapterListSelector())
.map(::chapterFromElement)
}
override fun chapterListSelector() = "div.main div.p-2"