diff --git a/src/all/batoto/build.gradle b/src/all/batoto/build.gradle index 5fd9f18c6..bca6d13fe 100644 --- a/src/all/batoto/build.gradle +++ b/src/all/batoto/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Bato.to' extClass = '.BatoToFactory' - extVersionCode = 42 + extVersionCode = 43 isNsfw = true } diff --git a/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt b/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt index 464ac55d2..3921190ee 100644 --- a/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt +++ b/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt @@ -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> { - 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 { + private fun altChapterParse(response: Response): List { 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 { + 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"