Hentai2Read fix date parsing (#9389)
* Fixed Date Parsing * Update build.gradle
This commit is contained in:
parent
9d79f5f8dc
commit
516be4d204
@ -5,7 +5,7 @@ ext {
|
|||||||
extName = 'Hentai2Read'
|
extName = 'Hentai2Read'
|
||||||
pkgNameSuffix = 'en.hentai2read'
|
pkgNameSuffix = 'en.hentai2read'
|
||||||
extClass = '.Hentai2Read'
|
extClass = '.Hentai2Read'
|
||||||
extVersionCode = 12
|
extVersionCode = 13
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +42,6 @@ class Hentai2Read : ParsedHttpSource() {
|
|||||||
Pattern.compile("""'images' : \[\"(.*?)[,]?\"\]""")
|
Pattern.compile("""'images' : \[\"(.*?)[,]?\"\]""")
|
||||||
}
|
}
|
||||||
|
|
||||||
val chapterDatePattern by lazy {
|
|
||||||
Pattern.compile("""about (\d+\s+\w+\s+ago)""")
|
|
||||||
}
|
|
||||||
|
|
||||||
lateinit var nextSearchPage: String
|
lateinit var nextSearchPage: String
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,37 +206,43 @@ class Hentai2Read : ParsedHttpSource() {
|
|||||||
override fun chapterFromElement(element: Element): SChapter {
|
override fun chapterFromElement(element: Element): SChapter {
|
||||||
return SChapter.create().apply {
|
return SChapter.create().apply {
|
||||||
setUrlWithoutDomain(element.attr("href"))
|
setUrlWithoutDomain(element.attr("href"))
|
||||||
|
var time = element.select("div > small").text().substringAfter("about").substringBefore("ago")
|
||||||
name = element.ownText().trim()
|
name = element.ownText().trim()
|
||||||
date_upload = element.select("div > small").text()?.let {
|
if (time != "") {
|
||||||
val matcher = chapterDatePattern.matcher(it)
|
date_upload = parseChapterDate(time)
|
||||||
if (matcher.find()) {
|
}
|
||||||
parseChapterDate(matcher.group(1)!!)
|
|
||||||
} else {
|
|
||||||
0L
|
|
||||||
}
|
|
||||||
} ?: 0L
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseChapterDate(date: String): Long {
|
private fun parseChapterDate(date: String): Long {
|
||||||
val dateWords = date.split(" ")
|
val value = date.replace(Regex("[^\\d]"), "").toInt()
|
||||||
if (dateWords.size == 3) {
|
|
||||||
val timeAgo = Integer.parseInt(dateWords[0])
|
return when {
|
||||||
return Calendar.getInstance().apply {
|
"second" in date -> Calendar.getInstance().apply {
|
||||||
when (dateWords[1]) {
|
add(Calendar.SECOND, value * -1)
|
||||||
"minute", "minutes" -> Calendar.MINUTE
|
|
||||||
"hour", "hours" -> Calendar.HOUR
|
|
||||||
"day", "days" -> Calendar.DAY_OF_YEAR
|
|
||||||
"week", "weeks" -> Calendar.WEEK_OF_YEAR
|
|
||||||
"month", "months" -> Calendar.MONTH
|
|
||||||
"year", "years" -> Calendar.YEAR
|
|
||||||
else -> null
|
|
||||||
}?.let {
|
|
||||||
add(it, -timeAgo)
|
|
||||||
}
|
|
||||||
}.timeInMillis
|
}.timeInMillis
|
||||||
|
"minute" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.MINUTE, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"hour" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.HOUR_OF_DAY, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"day" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.DATE, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"week" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.DATE, value * 7 * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"month" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.MONTH, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"year" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.YEAR, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
else -> {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0L
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageListParse(response: Response): List<Page> {
|
override fun pageListParse(response: Response): List<Page> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user