Updated code to work with the new site design (#687)

[japscan] Updated code to work with the new site design
This commit is contained in:
Peuuuur-Noel 2018-12-29 14:23:18 +01:00 committed by Carlos
parent 2450e6e69d
commit 0bfd8dbeb1
2 changed files with 87 additions and 36 deletions

View File

@ -5,8 +5,13 @@ ext {
appName = 'Tachiyomi: Japscan' appName = 'Tachiyomi: Japscan'
pkgNameSuffix = 'fr.japscan' pkgNameSuffix = 'fr.japscan'
extClass = '.Japscan' extClass = '.Japscan'
extVersionCode = 4 extVersionCode = 5
libVersion = '1.2' libVersion = '1.2'
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"
dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.apache.commons:commons-lang3:3.8.1'
}

View File

@ -5,17 +5,23 @@ package eu.kanade.tachiyomi.extension.fr.japscan
* @brief Defines class Japscan for french source Japscan * @brief Defines class Japscan for french source Japscan
* @date 2018-09-02 * @date 2018-09-02
* @version 1.0 * @version 1.0
*
* There is no research page on this source, so searching just returns all mangas from the source
* There are also no thumbnails for mangas
*/ */
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.model.*
import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import okhttp3.FormBody
import okhttp3.Request import okhttp3.Request
import okhttp3.Response
import okhttp3.OkHttpClient
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import java.text.ParseException
import java.text.SimpleDateFormat
import org.apache.commons.lang3.StringUtils
class Japscan : ParsedHttpSource() { class Japscan : ParsedHttpSource() {
@ -29,13 +35,21 @@ class Japscan : ParsedHttpSource() {
override val supportsLatest = true override val supportsLatest = true
override fun popularMangaSelector() = "ul.increment-list > li" override val client: OkHttpClient = network.cloudflareClient
companion object {
val dateFormat by lazy {
SimpleDateFormat("dd MMM yyyy")
}
}
override fun popularMangaSelector() = "#top_mangas_week li > span"
override fun popularMangaRequest(page: Int): Request { override fun popularMangaRequest(page: Int): Request {
return GET("$baseUrl", headers) return GET("$baseUrl", headers)
} }
override fun latestUpdatesSelector() = "#dernieres_sorties > div.manga" override fun latestUpdatesSelector() = "#chapters > div:eq(0) > h3.text-truncate"
override fun latestUpdatesRequest(page: Int): Request { override fun latestUpdatesRequest(page: Int): Request {
return GET("$baseUrl", headers) return GET("$baseUrl", headers)
@ -46,46 +60,71 @@ class Japscan : ParsedHttpSource() {
element.select("a").first().let { element.select("a").first().let {
manga.setUrlWithoutDomain(it.attr("href")) manga.setUrlWithoutDomain(it.attr("href"))
manga.title = it.text() manga.title = it.text()
val s = StringUtils.stripAccents(it.text())
.replace("[\\W]".toRegex(), "-")
.replace("[-]{2,}".toRegex(), "-")
.replace("^-|-$".toRegex(), "")
manga.thumbnail_url = "$baseUrl/imgs/mangas/$s.jpg"
} }
return manga return manga
} }
override fun latestUpdatesFromElement(element: Element): SManga { override fun latestUpdatesFromElement(element: Element): SManga = popularMangaFromElement(element)
return popularMangaFromElement(element)
}
override fun popularMangaNextPageSelector() = "#theresnone" override fun popularMangaNextPageSelector() = "#theresnone"
override fun latestUpdatesNextPageSelector() = "#theresnone" override fun latestUpdatesNextPageSelector() = "#theresnone"
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
return GET("$baseUrl/mangas/", headers) val form = FormBody.Builder().apply {
} add("search", StringUtils.stripAccents(query))
override fun searchMangaSelector() = "div#liste_mangas > div.row"
override fun searchMangaFromElement(element: Element): SManga {
val manga = SManga.create()
element.select("a").first().let {
manga.setUrlWithoutDomain(it.attr("href"))
manga.title = it.text()
} }
return manga return POST("$baseUrl/search/", headers, form.build())
} }
override fun searchMangaParse(response: Response): MangasPage {
val result = JsonParser().parse(response.body()!!.string()).asJsonArray
if (!result!!.isJsonArray)
return MangasPage(emptyList(), false)
val searchMangas = result.map {
searchMangaItemParse(it.asJsonObject)
}
return MangasPage(searchMangas, false)
}
private fun searchMangaItemParse(obj: JsonObject) = SManga.create().apply {
title = obj["name"]!!.asString
thumbnail_url = "$baseUrl/${obj["image"]!!.asString}"
url = obj["url"]!!.asString
}
override fun searchMangaSelector() = "#theresnone"
override fun searchMangaFromElement(element: Element) = popularMangaFromElement(element)
override fun searchMangaNextPageSelector() = "#theresnone" override fun searchMangaNextPageSelector() = "#theresnone"
override fun mangaDetailsParse(document: Document): SManga { override fun mangaDetailsParse(document: Document): SManga {
val infoElement = document.select("div.content").first() val infoElement = document.select("div#main > .card > .card-body").first()
val rowElement = infoElement.select("div.table > div.row").first()
val manga = SManga.create() val manga = SManga.create()
manga.author = rowElement.select("div:eq(0)").first()?.text() manga.thumbnail_url = "$baseUrl/${infoElement.select(".d-flex > div.m-2:eq(0) > img").attr("src")}"
manga.artist = rowElement.select("div:eq(0)").first()?.text()
manga.genre = rowElement.select("div:eq(2)").first()?.text()
manga.description = infoElement.select("div#synopsis").text()
manga.status = rowElement.select("div:eq(4)").first()?.text().orEmpty().let { parseStatus(it) } infoElement.select(".d-flex > div.m-2:eq(1) > p.mb-2").forEachIndexed { _, el ->
when (el.select("span").text().trim()) {
"Auteur(s):" -> manga.author = el.text().replace("Auteur(s):", "").trim()
"Artiste(s):" -> manga.artist = el.text().replace("Artiste(s):", "").trim()
"Genre(s):" -> manga.genre = el.text().replace("Genre(s):", "").trim()
"Statut:" -> manga.status = el.text().replace("Statut:", "").trim().let {
parseStatus(it)
}
}
}
manga.description = infoElement.select("> p").text().orEmpty()
return manga return manga
} }
@ -96,29 +135,36 @@ class Japscan : ParsedHttpSource() {
else -> SManga.UNKNOWN else -> SManga.UNKNOWN
} }
override fun chapterListSelector() = "div#liste_chapitres > ul > li" override fun chapterListSelector() = "div#chapters_list > div.collapse > div.chapters_list"
override fun chapterFromElement(element: Element): SChapter { override fun chapterFromElement(element: Element): SChapter {
val urlElement = element.select("a").first() val urlElement = element.select("a").first()
val chapter = SChapter.create() val chapter = SChapter.create()
chapter.setUrlWithoutDomain(urlElement.attr("href")) chapter.setUrlWithoutDomain(urlElement.attr("href"))
chapter.name = urlElement.text() chapter.name = urlElement.text().replace(" VUS", "")
chapter.date_upload = 0 chapter.date_upload = element.select("> span").text().trim().let { parseChapterDate(it) }
return chapter return chapter
} }
private fun parseChapterDate(date: String): Long {
return try {
dateFormat.parse(date).time
} catch (e: ParseException) {
0L
}
}
override fun pageListParse(document: Document): List<Page> { override fun pageListParse(document: Document): List<Page> {
val pages = mutableListOf<Page>() val pages = mutableListOf<Page>()
val imagePath = "(.*\\/).*".toRegex().find(document.select("#image").attr("data-src"))
document.select("select#pages").first()?.select("option")?.forEach { document.select("select#pages").first()?.select("option")?.forEach {
pages.add(Page(pages.size, "$baseUrl${it.attr("value")}")) pages.add(Page(pages.size, "", "${imagePath?.groupValues?.get(1)}${it.attr("data-img")}"))
} }
return pages return pages
} }
override fun imageUrlParse(document: Document): String { override fun imageUrlParse(document: Document): String = ""
val url = document.getElementById("image").attr("src")
return url
}
} }