WP Comics - add NhatTruyen (#2829)

WP Comics - add NhatTruyen
This commit is contained in:
Mike 2020-04-25 18:24:30 -04:00 committed by GitHub
parent 9d7f8c9357
commit 844b32f560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 15 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: WP-Comics' appName = 'Tachiyomi: WP-Comics'
pkgNameSuffix = 'all.wpcomics' pkgNameSuffix = 'all.wpcomics'
extClass = '.WPComicsFactory' extClass = '.WPComicsFactory'
extVersionCode = 5 extVersionCode = 6
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -26,6 +26,8 @@ abstract class WPComics(
override val client: OkHttpClient = network.cloudflareClient override val client: OkHttpClient = network.cloudflareClient
private fun List<String>.doesInclude(thisWord: String): Boolean = this.any { it.contains(thisWord, ignoreCase = true) }
// Popular // Popular
open val popularPath = "hot" open val popularPath = "hot"
@ -92,11 +94,15 @@ abstract class WPComics(
} }
} }
private fun String?.toStatus() = when { private fun String?.toStatus(): Int {
this == null -> SManga.UNKNOWN val ongoingWords = listOf("Ongoing", "Updating", "Đang tiến hành")
this.contains("Updating", ignoreCase = true) -> SManga.ONGOING val completedWords = listOf("Complete", "Hoàn thành")
this.contains("Complete", ignoreCase = true) -> SManga.COMPLETED return when {
else -> SManga.UNKNOWN this == null -> SManga.UNKNOWN
ongoingWords.doesInclude(this) -> SManga.ONGOING
completedWords.doesInclude(this) -> SManga.COMPLETED
else -> SManga.UNKNOWN
}
} }
// Chapters // Chapters
@ -116,21 +122,29 @@ abstract class WPComics(
private val currentYear by lazy { Calendar.getInstance(Locale.US)[1].toString().takeLast(2) } private val currentYear by lazy { Calendar.getInstance(Locale.US)[1].toString().takeLast(2) }
private fun String?.toDate(): Long { 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 { 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 trimmedDate = this.substringBefore(" ago").removeSuffix("s").split(" ")
val calendar = Calendar.getInstance() val calendar = Calendar.getInstance()
when (trimmedDate[1]) { when {
"day" -> calendar.apply { add(Calendar.DAY_OF_MONTH, -trimmedDate[0].toInt()) } dayWords.doesInclude(trimmedDate[1]) -> calendar.apply { add(Calendar.DAY_OF_MONTH, -trimmedDate[0].toInt()) }
"hour" -> calendar.apply { add(Calendar.HOUR_OF_DAY, -trimmedDate[0].toInt()) } hourWords.doesInclude(trimmedDate[1]) -> calendar.apply { add(Calendar.HOUR_OF_DAY, -trimmedDate[0].toInt()) }
"minute" -> calendar.apply { add(Calendar.MINUTE, -trimmedDate[0].toInt()) } minuteWords.doesInclude(trimmedDate[1]) -> calendar.apply { add(Calendar.MINUTE, -trimmedDate[0].toInt()) }
"second" -> calendar.apply { add(Calendar.SECOND, -trimmedDate[0].toInt()) } secondWords.doesInclude(trimmedDate[1]) -> calendar.apply { add(Calendar.SECOND, -trimmedDate[0].toInt()) }
} }
calendar.timeInMillis calendar.timeInMillis
} else { } else {
(if (gmtOffset == null) this?.substringAfterLast(" ") else "$this $gmtOffset")?.let { (if (gmtOffset == null) this.substringAfterLast(" ") else "$this $gmtOffset").let {
// timestamp has year // timestamp has year
if (Regex("""\d+/\d+/\d\d""").find(it)?.value != null) { if (Regex("""\d+/\d+/\d\d""").find(it)?.value != null) {
dateFormat.parse(it).time dateFormat.parse(it).time
@ -138,7 +152,7 @@ abstract class WPComics(
// MangaSum - timestamp sometimes doesn't have year (current year implied) // MangaSum - timestamp sometimes doesn't have year (current year implied)
dateFormat.parse("$it/$currentYear").time dateFormat.parse("$it/$currentYear").time
} }
} ?: 0L }
} }
} catch (_: Exception) { } catch (_: Exception) {
0L 0L

View File

@ -4,6 +4,7 @@ import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceFactory import eu.kanade.tachiyomi.source.SourceFactory
import eu.kanade.tachiyomi.source.model.FilterList 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.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@ -16,7 +17,8 @@ class WPComicsFactory : SourceFactory {
ManhuaPlus(), ManhuaPlus(),
ManhuaES(), ManhuaES(),
MangaSum(), 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") 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())
}