From 844b32f560301a11c8f317555c603e1407f9c0a6 Mon Sep 17 00:00:00 2001 From: Mike <51273546+SnakeDoc83@users.noreply.github.com> Date: Sat, 25 Apr 2020 18:24:30 -0400 Subject: [PATCH] WP Comics - add NhatTruyen (#2829) WP Comics - add NhatTruyen --- src/all/wpcomics/build.gradle | 2 +- .../extension/all/wpcomics/WPComics.kt | 40 +++++++++++++------ .../extension/all/wpcomics/WPComicsFactory.kt | 9 ++++- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/all/wpcomics/build.gradle b/src/all/wpcomics/build.gradle index ccaa1927c..dfda619ad 100644 --- a/src/all/wpcomics/build.gradle +++ b/src/all/wpcomics/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: WP-Comics' pkgNameSuffix = 'all.wpcomics' extClass = '.WPComicsFactory' - extVersionCode = 5 + extVersionCode = 6 libVersion = '1.2' } diff --git a/src/all/wpcomics/src/eu/kanade/tachiyomi/extension/all/wpcomics/WPComics.kt b/src/all/wpcomics/src/eu/kanade/tachiyomi/extension/all/wpcomics/WPComics.kt index d655f12ad..73a460c44 100644 --- a/src/all/wpcomics/src/eu/kanade/tachiyomi/extension/all/wpcomics/WPComics.kt +++ b/src/all/wpcomics/src/eu/kanade/tachiyomi/extension/all/wpcomics/WPComics.kt @@ -26,6 +26,8 @@ abstract class WPComics( override val client: OkHttpClient = network.cloudflareClient + private fun List.doesInclude(thisWord: String): Boolean = this.any { it.contains(thisWord, ignoreCase = true) } + // Popular open val popularPath = "hot" @@ -92,11 +94,15 @@ abstract class WPComics( } } - private fun String?.toStatus() = when { - this == null -> SManga.UNKNOWN - this.contains("Updating", ignoreCase = true) -> SManga.ONGOING - this.contains("Complete", ignoreCase = true) -> SManga.COMPLETED - else -> SManga.UNKNOWN + private fun String?.toStatus(): Int { + val ongoingWords = listOf("Ongoing", "Updating", "Đang tiến hành") + val completedWords = listOf("Complete", "Hoàn thành") + return when { + this == null -> SManga.UNKNOWN + ongoingWords.doesInclude(this) -> SManga.ONGOING + completedWords.doesInclude(this) -> SManga.COMPLETED + else -> SManga.UNKNOWN + } } // Chapters @@ -116,21 +122,29 @@ abstract class WPComics( private val currentYear by lazy { Calendar.getInstance(Locale.US)[1].toString().takeLast(2) } private fun String?.toDate(): Long { + this ?: return 0 + + val secondWords = listOf("second", "giây") + val minuteWords = listOf("minute", "phút") + val hourWords = listOf("hour", "giờ") + val dayWords = listOf("day", "ngày") + val agoWords = listOf("ago", "trước") + return try { - if (this?.contains("ago", ignoreCase = true) == true) { + if (agoWords.any { this.contains(it, ignoreCase = true) }) { val trimmedDate = this.substringBefore(" ago").removeSuffix("s").split(" ") val calendar = Calendar.getInstance() - when (trimmedDate[1]) { - "day" -> calendar.apply { add(Calendar.DAY_OF_MONTH, -trimmedDate[0].toInt()) } - "hour" -> calendar.apply { add(Calendar.HOUR_OF_DAY, -trimmedDate[0].toInt()) } - "minute" -> calendar.apply { add(Calendar.MINUTE, -trimmedDate[0].toInt()) } - "second" -> calendar.apply { add(Calendar.SECOND, -trimmedDate[0].toInt()) } + when { + dayWords.doesInclude(trimmedDate[1]) -> calendar.apply { add(Calendar.DAY_OF_MONTH, -trimmedDate[0].toInt()) } + hourWords.doesInclude(trimmedDate[1]) -> calendar.apply { add(Calendar.HOUR_OF_DAY, -trimmedDate[0].toInt()) } + minuteWords.doesInclude(trimmedDate[1]) -> calendar.apply { add(Calendar.MINUTE, -trimmedDate[0].toInt()) } + secondWords.doesInclude(trimmedDate[1]) -> calendar.apply { add(Calendar.SECOND, -trimmedDate[0].toInt()) } } calendar.timeInMillis } else { - (if (gmtOffset == null) this?.substringAfterLast(" ") else "$this $gmtOffset")?.let { + (if (gmtOffset == null) this.substringAfterLast(" ") else "$this $gmtOffset").let { // timestamp has year if (Regex("""\d+/\d+/\d\d""").find(it)?.value != null) { dateFormat.parse(it).time @@ -138,7 +152,7 @@ abstract class WPComics( // MangaSum - timestamp sometimes doesn't have year (current year implied) dateFormat.parse("$it/$currentYear").time } - } ?: 0L + } } } catch (_: Exception) { 0L diff --git a/src/all/wpcomics/src/eu/kanade/tachiyomi/extension/all/wpcomics/WPComicsFactory.kt b/src/all/wpcomics/src/eu/kanade/tachiyomi/extension/all/wpcomics/WPComicsFactory.kt index 30a75092f..81d6bfb1f 100644 --- a/src/all/wpcomics/src/eu/kanade/tachiyomi/extension/all/wpcomics/WPComicsFactory.kt +++ b/src/all/wpcomics/src/eu/kanade/tachiyomi/extension/all/wpcomics/WPComicsFactory.kt @@ -4,6 +4,7 @@ import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceFactory 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 java.text.SimpleDateFormat @@ -16,7 +17,8 @@ class WPComicsFactory : SourceFactory { ManhuaPlus(), ManhuaES(), MangaSum(), - XoxoComics() + XoxoComics(), + NhatTruyen() ) } @@ -61,3 +63,8 @@ private class XoxoComics : WPComics("XOXO Comics", "https://xoxocomics.com", "en } override fun pageListRequest(chapter: SChapter): Request = GET(baseUrl + "${chapter.url}/all") } + +private class NhatTruyen : WPComics("NhatTruyen", "http://nhattruyen.com", "vi", SimpleDateFormat("dd/MM/yy", Locale.getDefault()), null) { + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = GET("$baseUrl/the-loai?keyword=$query&page=$page", headers) + override fun imageRequest(page: Page): Request = GET(page.imageUrl!!, headersBuilder().add("Referer", baseUrl).build()) +}