From 7d826f2c4637c7e8405ee7d73a57600cbb84bf24 Mon Sep 17 00:00:00 2001 From: Riztard Lanthorn Date: Fri, 4 Dec 2020 19:50:17 +0700 Subject: [PATCH] update Bacakomik (#5014) * update ext version * fix image issue * add chapter timestamp * fix manga details issue --- src/id/bacakomik/build.gradle | 2 +- .../extension/id/bacakomik/Bacakomik.kt | 78 +++++++++++++++---- 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/id/bacakomik/build.gradle b/src/id/bacakomik/build.gradle index 61bd272df..42c89f3ae 100644 --- a/src/id/bacakomik/build.gradle +++ b/src/id/bacakomik/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Bacakomik' pkgNameSuffix = 'id.bacakomik' extClass = '.Bacakomik' - extVersionCode = 1 + extVersionCode = 2 libVersion = '1.2' } diff --git a/src/id/bacakomik/src/eu/kanade/tachiyomi/extension/id/bacakomik/Bacakomik.kt b/src/id/bacakomik/src/eu/kanade/tachiyomi/extension/id/bacakomik/Bacakomik.kt index a915d9566..e84299841 100644 --- a/src/id/bacakomik/src/eu/kanade/tachiyomi/extension/id/bacakomik/Bacakomik.kt +++ b/src/id/bacakomik/src/eu/kanade/tachiyomi/extension/id/bacakomik/Bacakomik.kt @@ -13,6 +13,9 @@ import okhttp3.OkHttpClient import okhttp3.Request import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import java.text.SimpleDateFormat +import java.util.Calendar +import java.util.Locale class Bacakomik : ParsedHttpSource() { override val name = "Bacakomik" @@ -20,6 +23,7 @@ class Bacakomik : ParsedHttpSource() { override val lang = "id" override val supportsLatest = true override val client: OkHttpClient = network.cloudflareClient + private val dateFormat: SimpleDateFormat = SimpleDateFormat("MMM d, yyyy", Locale.US) override fun popularMangaRequest(page: Int): Request { return GET("$baseUrl/daftar-manga/page/$page/?order=popular", headers) @@ -91,8 +95,10 @@ class Bacakomik : ParsedHttpSource() { val descElement = document.select("div.desc > .entry-content.entry-content-single").first() val sepName = infoElement.select(".infox > .spe > span:nth-child(2)").last() val manga = SManga.create() - manga.author = sepName.ownText() - manga.artist = sepName.ownText() + //need authorCleaner to take "pengarang:" string to remove it from author + val authorCleaner = document.select(".infox .spe b:contains(Pengarang)").text() + manga.author = document.select(".infox .spe span:contains(Pengarang)").text().substringAfter(authorCleaner) + manga.artist = manga.author val genres = mutableListOf() infoElement.select(".infox > .genre-info > a").forEach { element -> val genre = element.text() @@ -106,22 +112,60 @@ class Bacakomik : ParsedHttpSource() { } private fun parseStatus(element: String): Int = when { - element.toLowerCase().contains("ongoing") -> SManga.ONGOING - element.toLowerCase().contains("completed") -> SManga.COMPLETED + element.toLowerCase().contains("berjalan") -> SManga.ONGOING + element.toLowerCase().contains("tamat") -> SManga.COMPLETED else -> SManga.UNKNOWN } - override fun chapterListSelector() = ".lchx" + override fun chapterListSelector() = "#chapter_list li" override fun chapterFromElement(element: Element): SChapter { - val urlElement = element.select("a").first() + val urlElement = element.select(".lchx a").first() val chapter = SChapter.create() chapter.setUrlWithoutDomain(urlElement.attr("href")) chapter.name = urlElement.text() - chapter.date_upload = 0 + chapter.date_upload = element.select(".dt a").first()?.text()?.let { parseChapterDate(it) } ?: 0 return chapter } + fun parseChapterDate(date: String): Long { + return if (date.contains("yang lalu")) { + val value = date.split(' ')[0].toInt() + when { + "detik" in date -> Calendar.getInstance().apply { + add(Calendar.SECOND, value * -1) + }.timeInMillis + "menit" in date -> Calendar.getInstance().apply { + add(Calendar.MINUTE, value * -1) + }.timeInMillis + "jam" in date -> Calendar.getInstance().apply { + add(Calendar.HOUR_OF_DAY, value * -1) + }.timeInMillis + "hari" in date -> Calendar.getInstance().apply { + add(Calendar.DATE, value * -1) + }.timeInMillis + "minggu" in date -> Calendar.getInstance().apply { + add(Calendar.DATE, value * 7 * -1) + }.timeInMillis + "bulan" in date -> Calendar.getInstance().apply { + add(Calendar.MONTH, value * -1) + }.timeInMillis + "tahun" in date -> Calendar.getInstance().apply { + add(Calendar.YEAR, value * -1) + }.timeInMillis + else -> { + 0L + } + } + } else { + try { + dateFormat.parse(date)?.time ?: 0 + } catch (_: Exception) { + 0L + } + } + } + override fun prepareNewChapter(chapter: SChapter, manga: SManga) { val basic = Regex("""Chapter\s([0-9]+)""") when { @@ -136,7 +180,7 @@ class Bacakomik : ParsedHttpSource() { override fun pageListParse(document: Document): List { val pages = mutableListOf() var i = 0 - document.select("div#chimg img").forEach { element -> + document.select("div#chimg noscript img").forEach { element -> val url = element.attr("src") i++ if (url.isNotEmpty()) { @@ -149,11 +193,19 @@ class Bacakomik : ParsedHttpSource() { override fun imageUrlParse(document: Document) = "" override fun imageRequest(page: Page): Request { - val imgHeader = Headers.Builder().apply { - add("User-Agent", "Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Build/KLP) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30") - add("Referer", baseUrl) - }.build() - return GET(page.imageUrl!!, imgHeader) + if (page.imageUrl!!.contains("i2.wp.com")) { + val headers = Headers.Builder() + headers.apply { + add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3") + } + return GET(page.imageUrl!!, headers.build()) + } else { + val imgHeader = Headers.Builder().apply { + add("User-Agent", "Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Build/KLP) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30") + add("Referer", baseUrl) + }.build() + return GET(page.imageUrl!!, imgHeader) + } } private class AuthorFilter : Filter.Text("Author")