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