Fix time for Rawlh source

This commit is contained in:
pavka 2018-04-19 19:37:55 +03:00
parent d9f31622f2
commit 923490d0ad
1 changed files with 32 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import okhttp3.HttpUrl
import okhttp3.Request
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import java.util.Calendar
class Rawlh : ParsedHttpSource() {
@ -106,14 +107,44 @@ class Rawlh : ParsedHttpSource() {
override fun chapterFromElement(element: Element): SChapter {
val urlElement = element.select("td a").first()
val timeElement = element.select("td time").first()
val chapter = SChapter.create()
chapter.setUrlWithoutDomain("/" + urlElement.attr("href"))
chapter.name = urlElement.text()
chapter.date_upload = 0
chapter.date_upload = parseChapterDate(timeElement.text())
return chapter
}
private fun parseChapterDate(date: String): Long {
val value = date.split(' ')[0].toInt()
return when {
"hour(s) ago" in date -> Calendar.getInstance().apply {
add(Calendar.HOUR_OF_DAY, value * -1)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}.timeInMillis
"day(s) ago" in date -> Calendar.getInstance().apply {
add(Calendar.DATE, value * -1)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}.timeInMillis
"week(s) ago" in date -> Calendar.getInstance().apply {
add(Calendar.DATE, value * 7 * -1)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}.timeInMillis
"month(s) ago" in date -> Calendar.getInstance().apply {
add(Calendar.MONTH, value * -1)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}.timeInMillis
else -> {
return 0
}
}
}
override fun pageListParse(document: Document): List<Page> {
val pages = mutableListOf<Page>()