[Mangahub.io] Fix some parsing bugs (#1682)
[Mangahub.io] Fix some parsing bugs
This commit is contained in:
parent
8ee25c471b
commit
78f274e27d
|
@ -5,7 +5,7 @@ ext {
|
||||||
appName = 'Tachiyomi: Mangahub'
|
appName = 'Tachiyomi: Mangahub'
|
||||||
pkgNameSuffix = 'en.mangahub'
|
pkgNameSuffix = 'en.mangahub'
|
||||||
extClass = '.Mangahub'
|
extClass = '.Mangahub'
|
||||||
extVersionCode = 2
|
extVersionCode = 3
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,56 +92,54 @@ class Mangahub : ParsedHttpSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseChapterDate(date: String): Long {
|
private fun parseChapterDate(date: String): Long {
|
||||||
return when {
|
val now = Calendar.getInstance().apply {
|
||||||
"hours" in date || "just now" in date -> {
|
set(Calendar.HOUR_OF_DAY, 0)
|
||||||
Calendar.getInstance().apply {
|
set(Calendar.MINUTE, 0)
|
||||||
set(Calendar.HOUR_OF_DAY, 0)
|
set(Calendar.SECOND, 0)
|
||||||
set(Calendar.MINUTE, 0)
|
set(Calendar.MILLISECOND, 0)
|
||||||
set(Calendar.SECOND, 0)
|
}
|
||||||
set(Calendar.MILLISECOND, 0)
|
var parsedDate = 0L
|
||||||
}.timeInMillis
|
when {
|
||||||
|
"just now" in date || "less than an hour" in date -> {
|
||||||
|
parsedDate = now.timeInMillis
|
||||||
}
|
}
|
||||||
"days" in date -> {
|
// parses: "1 hour ago" and "2 hours ago"
|
||||||
val days = date.replace("days ago", "").trim().toInt()
|
"hour" in date -> {
|
||||||
Calendar.getInstance().apply {
|
val hours = date.replaceAfter(" ", "").trim().toInt()
|
||||||
add(Calendar.DAY_OF_YEAR, -days)
|
parsedDate = now.apply { add(Calendar.HOUR, -hours) }.timeInMillis
|
||||||
set(Calendar.HOUR_OF_DAY, 0)
|
|
||||||
set(Calendar.MINUTE, 0)
|
|
||||||
set(Calendar.SECOND, 0)
|
|
||||||
set(Calendar.MILLISECOND, 0)
|
|
||||||
}.timeInMillis
|
|
||||||
}
|
}
|
||||||
|
// parses: "Yesterday" and "2 days ago"
|
||||||
|
"day" in date -> {
|
||||||
|
val days = date.replace("days ago", "").trim().toIntOrNull() ?: 1
|
||||||
|
parsedDate = now.apply { add(Calendar.DAY_OF_YEAR, -days) }.timeInMillis
|
||||||
|
}
|
||||||
|
// parses: "2 weeks ago"
|
||||||
"weeks" in date -> {
|
"weeks" in date -> {
|
||||||
val weeks = date.replace("weeks ago", "").trim().toInt()
|
val weeks = date.replace("weeks ago", "").trim().toInt()
|
||||||
Calendar.getInstance().apply {
|
parsedDate = now.apply { add(Calendar.WEEK_OF_YEAR, -weeks) }.timeInMillis
|
||||||
add(Calendar.WEEK_OF_YEAR, -weeks)
|
|
||||||
set(Calendar.HOUR_OF_DAY, 0)
|
|
||||||
set(Calendar.MINUTE, 0)
|
|
||||||
set(Calendar.SECOND, 0)
|
|
||||||
set(Calendar.MILLISECOND, 0)
|
|
||||||
}.timeInMillis
|
|
||||||
}
|
}
|
||||||
|
// parses: "12-20-2019" and defaults everything that wasn't taken into account to 0
|
||||||
else -> {
|
else -> {
|
||||||
try {
|
try {
|
||||||
SimpleDateFormat("MM-dd-yyyy", Locale.US).parse(date).time
|
parsedDate = SimpleDateFormat("MM-dd-yyyy", Locale.US).parse(date).time
|
||||||
} catch (e: ParseException) {
|
} catch (e: ParseException) { /*nothing to do, parsedDate is initialized with 0L*/ }
|
||||||
0L
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return parsedDate
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageListParse(document: Document): List<Page> {
|
override fun pageListParse(document: Document): List<Page> {
|
||||||
val pageList = mutableListOf<Page>()
|
val pageList = mutableListOf<Page>()
|
||||||
|
|
||||||
val page = document.select("div#mangareader img.PB0mN").first()
|
val pages = document.select("div#mangareader img.PB0mN")
|
||||||
val pageUrl = page.attr("src")
|
val pageUrl = pages.first().attr("src")
|
||||||
val extension = pageUrl.split(".").last()
|
|
||||||
val pageRoot = pageUrl.replaceAfterLast("/", "")
|
val pageRoot = pageUrl.replaceAfterLast("/", "")
|
||||||
val numPages = page.nextElementSibling().text().split("/").last().toInt()
|
val numPages = pages.first().nextElementSibling().text().split("/").last().toInt()
|
||||||
|
|
||||||
for (i in 1..numPages) {
|
pageList.add(Page(0, "", pages.first().attr("src")))
|
||||||
pageList.add(Page(i, "", "$pageRoot$i.$extension"))
|
val extension = pages.last().attr("src").split(".").last()
|
||||||
|
for (i in 2..numPages) {
|
||||||
|
pageList.add(Page(i-1, "", "$pageRoot$i.$extension"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return pageList
|
return pageList
|
||||||
|
|
Loading…
Reference in New Issue