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:
parent
21d51725e5
commit
44b820eca0
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'Bato.to'
|
extName = 'Bato.to'
|
||||||
extClass = '.BatoToFactory'
|
extClass = '.BatoToFactory'
|
||||||
extVersionCode = 42
|
extVersionCode = 43
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ import rx.Observable
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
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.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
@ -116,7 +117,7 @@ open class BatoTo(
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
override fun latestUpdatesRequest(page: Int): Request {
|
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 {
|
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 latestUpdatesNextPageSelector() = "div#mainer nav.d-none .pagination .page-item:last-of-type:not(.disabled)"
|
||||||
|
|
||||||
override fun popularMangaRequest(page: Int): Request {
|
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()
|
override fun popularMangaSelector() = latestUpdatesSelector()
|
||||||
|
@ -362,44 +363,55 @@ open class BatoTo(
|
||||||
else -> SManga.UNKNOWN
|
else -> SManga.UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
|
private fun altChapterParse(response: Response): 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> {
|
|
||||||
return Jsoup.parse(response.body.string(), response.request.url.toString(), Parser.xmlParser())
|
return Jsoup.parse(response.body.string(), response.request.url.toString(), Parser.xmlParser())
|
||||||
.select("channel > item").map { item ->
|
.select("channel > item").map { item ->
|
||||||
SChapter.create().apply {
|
SChapter.create().apply {
|
||||||
url = item.selectFirst("guid")!!.text()
|
url = item.selectFirst("guid")!!.text()
|
||||||
name = item.selectFirst("title")!!.text().substringAfter(title).trim()
|
name = item.selectFirst("title")!!.text()
|
||||||
date_upload = SimpleDateFormat("E, dd MMM yyyy H:m:s Z", Locale.US).parse(item.selectFirst("pubDate")!!.text())?.time ?: 0L
|
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 {
|
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.")
|
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 {
|
override fun chapterListRequest(manga: SManga): Request {
|
||||||
if (manga.url.startsWith("http")) {
|
return if (getAltChapterListPref()) {
|
||||||
return GET(manga.url, headers)
|
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"
|
override fun chapterListSelector() = "div.main div.p-2"
|
||||||
|
|
Loading…
Reference in New Issue