MMRCMS - parse grid layout for latest (#4078)

* MMRCMS - parse grid layout for latest

* fix Mangas.pw search
This commit is contained in:
Mike 2020-08-10 20:35:34 -04:00 committed by GitHub
parent bf5e301f63
commit 7865e6a42e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 71 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'My Manga Reader CMS (Many sources)' extName = 'My Manga Reader CMS (Many sources)'
pkgNameSuffix = 'all.mmrcms' pkgNameSuffix = 'all.mmrcms'
extClass = '.MyMangaReaderCMSSources' extClass = '.MyMangaReaderCMSSources'
extVersionCode = 46 extVersionCode = 47
libVersion = '1.2' libVersion = '1.2'
} }

File diff suppressed because one or more lines are too long

View File

@ -170,7 +170,7 @@ class Generator {
private fun supportsLatest(third: String): Boolean { private fun supportsLatest(third: String): Boolean {
val document = getDocument("$third/latest-release?page=1", false) ?: return false val document = getDocument("$third/latest-release?page=1", false) ?: return false
return document.select("div.mangalist div.manga-item a").isNotEmpty() return document.select("div.mangalist div.manga-item a, div.grid-manga tr").isNotEmpty()
} }
private fun parseCategories(document: Document): MutableList<Map<String, String>> { private fun parseCategories(document: Document): MutableList<Map<String, String>> {

View File

@ -64,27 +64,22 @@ class MyMangaReaderCMSSource(
} }
} }
/**
* Search through a list of titles client-side or let the server do it
*/
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
return if (name == "Mangas.pw") {
selfSearch(query)
} else {
super.fetchSearchManga(page, query, filters)
}
}
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
// Query overrides everything
val url: Uri.Builder val url: Uri.Builder
if (query.isNotBlank()) { when {
url = Uri.parse("$baseUrl/search")!!.buildUpon() name == "Mangas.pw" -> {
url.appendQueryParameter("query", query) url = Uri.parse("$baseUrl/search")!!.buildUpon()
} else { url.appendQueryParameter("q", query)
url = Uri.parse("$baseUrl/filterList?page=$page")!!.buildUpon() }
filters.filterIsInstance<UriFilter>() query.isNotBlank() -> {
url = Uri.parse("$baseUrl/search")!!.buildUpon()
url.appendQueryParameter("query", query)
}
else -> {
url = Uri.parse("$baseUrl/filterList?page=$page")!!.buildUpon()
filters.filterIsInstance<UriFilter>()
.forEach { it.addToUri(url) } .forEach { it.addToUri(url) }
}
} }
return GET(url.toString(), headers) return GET(url.toString(), headers)
} }
@ -113,20 +108,22 @@ class MyMangaReaderCMSSource(
override fun popularMangaParse(response: Response) = internalMangaParse(response) override fun popularMangaParse(response: Response) = internalMangaParse(response)
override fun searchMangaParse(response: Response): MangasPage { override fun searchMangaParse(response: Response): MangasPage {
return if (response.request().url().queryParameter("query")?.isNotBlank() == true) { return if (listOf("query", "q").any { it in response.request().url().queryParameterNames() }) {
// If a search query was specified, use search instead! // If a search query was specified, use search instead!
MangasPage(jsonParser val jsonArray = jsonParser.parse(response.body()!!.string()).let {
.parse(response.body()!!.string())["suggestions"].array if (name == "Mangas.pw") it.array else it["suggestions"].array
.map { }
SManga.create().apply { MangasPage(jsonArray
val segment = it["data"].string .map {
url = getUrlWithoutBaseUrl(itemUrl + segment) SManga.create().apply {
title = it["value"].string val segment = it["data"].string
url = getUrlWithoutBaseUrl(itemUrl + segment)
title = it["value"].string
// Guess thumbnails // Guess thumbnails
// thumbnail_url = "$baseUrl/uploads/manga/$segment/cover/cover_250x350.jpg" // thumbnail_url = "$baseUrl/uploads/manga/$segment/cover/cover_250x350.jpg"
} }
}, false) }, false)
} else { } else {
internalMangaParse(response) internalMangaParse(response)
} }
@ -139,20 +136,31 @@ class MyMangaReaderCMSSource(
if (document.location().contains("page=1")) latestTitles.clear() if (document.location().contains("page=1")) latestTitles.clear()
val mangas = document.select(latestUpdatesSelector()).map { element -> latestUpdatesFromElement(element) } val mangas = document.select(latestUpdatesSelector())
.map { element ->
if (element.hasClass("manga-item")) latestUpdatesFromElement(element) else gridLatestUpdatesFromElement(element)
}
.distinctBy { manga -> manga.title } .distinctBy { manga -> manga.title }
.filterNot { manga -> manga.title in latestTitles } .filterNot { manga -> manga.title in latestTitles }
.also { list -> latestTitles.addAll(list.map { it.title }) } .also { list -> latestTitles.addAll(list.map { it.title }) }
return MangasPage(mangas, document.select(latestUpdatesNextPageSelector()) != null) return MangasPage(mangas, document.select(latestUpdatesNextPageSelector()) != null)
} }
private fun latestUpdatesSelector() = "div.mangalist div.manga-item" private fun latestUpdatesSelector() = "div.mangalist div.manga-item, div.grid-manga tr"
private fun latestUpdatesNextPageSelector() = "a[rel=next]" private fun latestUpdatesNextPageSelector() = "a[rel=next]"
private fun latestUpdatesFromElement(element: Element): SManga = SManga.create().apply { private fun latestUpdatesFromElement(element: Element): SManga = SManga.create().apply {
url = element.select("a").first().attr("abs:href").substringAfter(baseUrl) // intentionally not using setUrlWithoutDomain url = element.select("a").first().attr("abs:href").substringAfter(baseUrl) // intentionally not using setUrlWithoutDomain
title = element.select("a").first().text().trim() title = element.select("a").first().text().trim()
thumbnail_url = "$baseUrl/uploads/manga/${url.substringAfterLast('/')}/cover/cover_250x350.jpg" thumbnail_url = "$baseUrl/uploads/manga/${url.substringAfterLast('/')}/cover/cover_250x350.jpg"
} }
// MangaYu, for instance, needs this
private fun gridLatestUpdatesFromElement(element: Element): SManga = SManga.create().apply {
element.select("a.chart-title").let {
setUrlWithoutDomain(it.attr("href"))
title = it.text()
}
thumbnail_url = element.select("img").attr("abs:src")
}
private fun internalMangaParse(response: Response): MangasPage { private fun internalMangaParse(response: Response): MangasPage {
val document = response.asJsoup() val document = response.asJsoup()