Mangatown update (#1873)

Mangatown update
This commit is contained in:
Mike 2019-12-13 07:22:46 -05:00 committed by arkon
parent 482e03f449
commit 43b66fa0fe
2 changed files with 48 additions and 56 deletions

View File

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

View File

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.extension.en.mangatown
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.source.model.*
import eu.kanade.tachiyomi.source.model.SManga.Companion.LICENSED
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import okhttp3.OkHttpClient
import okhttp3.Request
@ -12,14 +11,15 @@ import org.jsoup.nodes.Element
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Response
import java.text.SimpleDateFormat
import java.util.*
import java.util.Calendar
import java.util.Locale
class Mangatown : ParsedHttpSource() {
override val name = "Mangatown"
override val baseUrl = "http://mangatown.com"
override val baseUrl = "http://www.mangatown.com"
override val lang = "en"
@ -28,25 +28,25 @@ class Mangatown : ParsedHttpSource() {
override val client: OkHttpClient = network.cloudflareClient
override fun popularMangaSelector() = "li:has(a.manga_cover)"
override fun popularMangaRequest(page: Int): Request {
return GET("$baseUrl/directory/0-0-0-0-0-0/$page.htm")
return GET("$baseUrl/directory/0-0-0-0-0-0/$page.htm")
}
override fun latestUpdatesSelector() = popularMangaSelector()
override fun latestUpdatesRequest(page: Int): Request {
return GET("$baseUrl/latest/$page.htm")
}
override fun popularMangaFromElement(element: Element): SManga {
val manga = SManga.create()
element.select("p.title a").first().let {
manga.setUrlWithoutDomain(it.attr("href"))
manga.title = it.text()
return SManga.create().apply {
element.select("p.title a").first().let {
setUrlWithoutDomain(it.attr("href"))
title = it.text()
}
thumbnail_url = element.select("img").attr("abs:src")
}
manga.thumbnail_url = element.select("img").attr("src")
return manga
}
override fun latestUpdatesFromElement(element: Element) = popularMangaFromElement(element)
@ -56,8 +56,7 @@ class Mangatown : ParsedHttpSource() {
override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector()
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
val url = "$baseUrl/search.php?name=$query"
return POST(url, headers)
return POST("$baseUrl/search?page=$page&name=$query", headers)
}
override fun searchMangaSelector() = popularMangaSelector()
@ -69,76 +68,69 @@ class Mangatown : ParsedHttpSource() {
override fun mangaDetailsParse(document: Document): SManga {
val infoElement = document.select("div.article_content")
val manga = SManga.create()
manga.title = infoElement.select("h1").text()
manga.author = infoElement.select("b:containsOwn(author) + a").text()
manga.artist = infoElement.select("b:containsOwn(artist) + a").text()
val status = infoElement.select("li:contains(status)").first().text().substringAfter(":").split(" ").first()
if(infoElement.select("div.chapter_content:contains(has been licensed)").isNotEmpty()) {
manga.status = LICENSED
} else {
manga.status = parseStatus(status)
return SManga.create().apply {
title = infoElement.select("h1").text()
author = infoElement.select("b:containsOwn(author) + a").text()
artist = infoElement.select("b:containsOwn(artist) + a").text()
status = if (infoElement.select("div.chapter_content:contains(has been licensed)").isNotEmpty()) {
SManga.LICENSED
} else {
parseStatus(infoElement.select("li:has(b:containsOwn(status))").text())
}
genre = infoElement.select("li:has(b:containsOwn(genre)) a").joinToString { it.text() }
description = document.select("span#show").text().removeSuffix("HIDE")
thumbnail_url = document.select("div.detail_info img").attr("abs:src")
}
manga.genre = infoElement.select("li:contains(genre)").first().text().substringAfter(":")
manga.description = document.select("span#show").text()
manga.thumbnail_url = document.select("div.detail_info img").attr("src")
return manga
}
private fun parseStatus(status: String?) = when {
status == null -> SManga.UNKNOWN
status.contains("Ongoing") -> SManga.ONGOING
status.contains("Completed") -> SManga.COMPLETED
status.contains("Ongoing", ignoreCase = true) -> SManga.ONGOING
status.contains("Completed", ignoreCase = true) -> SManga.COMPLETED
else -> SManga.UNKNOWN
}
override fun chapterListSelector() = "ul.chapter_list li"
override fun chapterFromElement(element: Element): SChapter {
val urlElement = element.select("a").first()
val chapter = SChapter.create()
chapter.setUrlWithoutDomain(urlElement.attr("href"))
val nameWithDate = element.text()
val cDate = element.select("li span.time").text()
chapter.name = nameWithDate.substringBefore(cDate)
if (element.select("li span.new").toString().isNotEmpty()) { chapter.name = chapter.name.substringBefore("new") }
chapter.date_upload = parseDate(cDate)
return chapter
return SChapter.create().apply {
element.select("a").let { urlElement ->
setUrlWithoutDomain(urlElement.attr("href"))
name = "${urlElement.text()} ${element.select("span:not(span.time,span.new)").joinToString(" ") { it.text() }}"
}
date_upload = parseDate(element.select("span.time").text())
}
}
private fun parseDate(date: String): Long {
when (date) {
"Today" -> return Calendar.getInstance().apply{}.timeInMillis
"Yesterday" -> return Calendar.getInstance().apply{add(Calendar.DAY_OF_MONTH, -1)}.timeInMillis
return when {
date.contains("Today") -> Calendar.getInstance().apply{}.timeInMillis
date.contains("Yesterday") -> Calendar.getInstance().apply{add(Calendar.DAY_OF_MONTH, -1)}.timeInMillis
else -> {
return SimpleDateFormat("MMM d, yyyy", Locale.US).parse(date).time
try {
SimpleDateFormat("MMM dd,yyyy", Locale.US).parse(date).time
} catch (e: Exception) {
0L
}
}
}
}
override fun pageListParse(document: Document): List<Page> {
val pages = mutableListOf<Page>()
document.select("select#top_chapter_list ~ div.page_select option:not(:contains(featured))").forEach {
pages.add(Page(pages.size, it.attr("value").substringAfter("com")))
return document.select("select#top_chapter_list ~ div.page_select option:not(:contains(featured))").mapIndexed { i, element ->
Page(i, element.attr("value").substringAfter("com"))
}
return pages
}
// Get the page
override fun imageUrlRequest(page: Page) = GET("$baseUrl" + page.url)
override fun imageUrlRequest(page: Page) = GET(baseUrl + page.url)
// Get the image from the requested page
// Get the image from the requested page
override fun imageUrlParse (response: Response): String {
val document = response.asJsoup()
return document.select("div#viewer img").attr("src")
return response.asJsoup().select("div#viewer img").attr("abs:src")
}
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("No used")
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used")
override fun getFilterList() = FilterList()