Toonily: Fix chapter date parsing (#1533)

Toonily: Update chapter date parsing
This commit is contained in:
Rama Bondan Prakoso 2019-09-19 21:47:57 +07:00 committed by arkon
parent ccb12ca509
commit 2b8629b21a
2 changed files with 33 additions and 9 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: Toonily' appName = 'Tachiyomi: Toonily'
pkgNameSuffix = 'en.toonily' pkgNameSuffix = 'en.toonily'
extClass = '.Toonily' extClass = '.Toonily'
extVersionCode = 2 extVersionCode = 3
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -144,17 +144,41 @@ class Toonily: ParsedHttpSource() {
val chapter = SChapter.create() val chapter = SChapter.create()
chapter.setUrlWithoutDomain(urlElement.attr("href")) chapter.setUrlWithoutDomain(urlElement.attr("href"))
chapter.name = urlElement.text() chapter.name = urlElement.text()
chapter.date_upload = element.select("span.chapter-release-date i").last()?.text()?.let { val new = element.select(".c-new-tag img").attr("alt")
try { if (new.isNotEmpty())
SimpleDateFormat("MMMM dd, yyyy", Locale.US).parse(it).time chapter.date_upload = parseChapterDate(new)
} catch (e: ParseException) { else {
SimpleDateFormat("MMM dd, yyyy", Locale.US).parse(it).time chapter.date_upload = element.select("span.chapter-release-date i").last()?.text()?.let {
} try {
SimpleDateFormat("MMMM dd, yyyy", Locale.US).parse(it).time
} ?: 0 } catch (e: ParseException) {
SimpleDateFormat("MMM dd, yyyy", Locale.US).parse(it).time
}
} ?: 0
}
return chapter return chapter
} }
private fun parseChapterDate(date: String): Long {
val value = date.split(' ')[0].toInt()
return when {
"mins" in date -> Calendar.getInstance().apply {
add(Calendar.MINUTE, value * -1)
}.timeInMillis
"hours" in date -> Calendar.getInstance().apply {
add(Calendar.HOUR_OF_DAY, value * -1)
}.timeInMillis
"days" in date -> Calendar.getInstance().apply {
add(Calendar.DATE, value * -1)
}.timeInMillis
else -> {
return 0
}
}
}
override fun prepareNewChapter(chapter: SChapter, manga: SManga) { override fun prepareNewChapter(chapter: SChapter, manga: SManga) {
val basic = Regex("""Chapter\s([0-9]+)""") val basic = Regex("""Chapter\s([0-9]+)""")
when { when {