MyReadingManga - some refactoring, added language filter (#3741)
This commit is contained in:
parent
0703445cab
commit
fdec2f1009
|
@ -5,7 +5,7 @@ ext {
|
||||||
extName = 'MyReadingManga'
|
extName = 'MyReadingManga'
|
||||||
pkgNameSuffix = 'all.myreadingmanga'
|
pkgNameSuffix = 'all.myreadingmanga'
|
||||||
extClass = '.MyReadingMangaFactory'
|
extClass = '.MyReadingMangaFactory'
|
||||||
extVersionCode = 35
|
extVersionCode = 36
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.extension.all.myreadingmanga
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.webkit.URLUtil
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||||
import eu.kanade.tachiyomi.source.model.Filter
|
import eu.kanade.tachiyomi.source.model.Filter
|
||||||
|
@ -67,7 +68,9 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin
|
||||||
var fqIndex = 0
|
var fqIndex = 0
|
||||||
val uri = Uri.parse("$baseUrl/search/").buildUpon()
|
val uri = Uri.parse("$baseUrl/search/").buildUpon()
|
||||||
.appendQueryParameter("wpsolr_q", query)
|
.appendQueryParameter("wpsolr_q", query)
|
||||||
.appendQueryParameter("wpsolr_fq[$fqIndex]", "lang_str:$siteLang")
|
@Suppress("NullableBooleanElvis")
|
||||||
|
if ((filters.find { it is EnforceLanguageFilter } as? Filter.CheckBox)?.state ?: true)
|
||||||
|
uri.appendQueryParameter("wpsolr_fq[$fqIndex]", "lang_str:$siteLang")
|
||||||
.appendQueryParameter("wpsolr_page", page.toString())
|
.appendQueryParameter("wpsolr_page", page.toString())
|
||||||
filters.forEach {
|
filters.forEach {
|
||||||
if (it is UriFilter) {
|
if (it is UriFilter) {
|
||||||
|
@ -100,21 +103,22 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin
|
||||||
return manga
|
return manga
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val extensionRegex = Regex("""\.(jpg|png|jpeg)""")
|
||||||
|
|
||||||
private fun getImage(element: Element): String {
|
private fun getImage(element: Element): String {
|
||||||
var url =
|
return when {
|
||||||
when {
|
element.attr("data-src").contains(extensionRegex) -> element.attr("abs:data-src")
|
||||||
element.attr("data-src").endsWith(".jpg") || element.attr("data-src").endsWith(".png") || element.attr("data-src").endsWith(".jpeg") -> element.attr("data-src")
|
element.attr("src").contains(extensionRegex) -> element.attr("abs:src")
|
||||||
element.attr("src").endsWith(".jpg") || element.attr("src").endsWith(".png") || element.attr("src").endsWith(".jpeg") -> element.attr("src")
|
else -> element.attr("abs:data-lazy-src")
|
||||||
else -> element.attr("data-lazy-src")
|
|
||||||
}
|
}
|
||||||
if (url.startsWith("//")) {
|
|
||||||
url = "https:$url"
|
|
||||||
}
|
|
||||||
return url
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes resizing
|
// removes resizing
|
||||||
private fun getThumbnail(thumbnailUrl: String) = thumbnailUrl.substringBeforeLast("-") + "." + thumbnailUrl.substringAfterLast(".")
|
private fun getThumbnail(thumbnailUrl: String?): String? {
|
||||||
|
thumbnailUrl ?: return null
|
||||||
|
val url = thumbnailUrl.substringBeforeLast("-") + "." + thumbnailUrl.substringAfterLast(".")
|
||||||
|
return if (URLUtil.isValidUrl(url)) url else null
|
||||||
|
}
|
||||||
|
|
||||||
// cleans up the name removing author and language from the title
|
// cleans up the name removing author and language from the title
|
||||||
private fun cleanTitle(title: String) = title.substringBeforeLast("[").substringAfterLast("]").substringBeforeLast("(").trim()
|
private fun cleanTitle(title: String) = title.substringBeforeLast("[").substringAfterLast("]").substringBeforeLast("(").trim()
|
||||||
|
@ -123,7 +127,7 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin
|
||||||
|
|
||||||
// Manga Details
|
// Manga Details
|
||||||
override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
|
override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
|
||||||
val needCover = manga.thumbnail_url.isNullOrEmpty()
|
val needCover = manga.thumbnail_url?.let { !client.newCall(GET(it, headers)).execute().isSuccessful } ?: true
|
||||||
|
|
||||||
return client.newCall(mangaDetailsRequest(manga))
|
return client.newCall(mangaDetailsRequest(manga))
|
||||||
.asObservableSuccess()
|
.asObservableSuccess()
|
||||||
|
@ -132,25 +136,28 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun mangaDetailsParse(document: Document, needCover: Boolean): SManga {
|
private fun mangaDetailsParse(document: Document, needCover: Boolean = true): SManga {
|
||||||
val manga = SManga.create()
|
return SManga.create().apply {
|
||||||
manga.author = cleanAuthor(document.select("h1").text())
|
author = cleanAuthor(document.select("h1").text())
|
||||||
manga.artist = cleanAuthor(document.select("h1").text())
|
artist = author
|
||||||
manga.genre = document.select(".entry-header p a[href*=genre]").joinToString(", ") { it.text() }
|
genre = document.select(".entry-header p a[href*=genre]").joinToString { it.text() }
|
||||||
|
val basicDescription = document.select("h1").text()
|
||||||
|
// too troublesome to achieve 100% accuracy assigning scanlator group during chapterListParse
|
||||||
|
val scanlatedBy = document.select(".entry-terms:has(a[href*=group])").firstOrNull()
|
||||||
|
?.select("a[href*=group]")?.joinToString(prefix = "Scanlated by: ") { it.text() }
|
||||||
val extendedDescription = document.select(".entry-content p:not(p:containsOwn(|)):not(.chapter-class + p)")?.joinToString("\n") { it.text() }
|
val extendedDescription = document.select(".entry-content p:not(p:containsOwn(|)):not(.chapter-class + p)")?.joinToString("\n") { it.text() }
|
||||||
manga.description = document.select("h1").text() + if (extendedDescription.isNullOrEmpty()) "" else "\n\n$extendedDescription"
|
description = listOfNotNull(basicDescription, scanlatedBy, extendedDescription).joinToString("\n")
|
||||||
manga.status = when (document.select("a[href*=status]")?.first()?.text()) {
|
status = when (document.select("a[href*=status]")?.first()?.text()) {
|
||||||
"Ongoing" -> SManga.ONGOING
|
"Ongoing" -> SManga.ONGOING
|
||||||
"Completed" -> SManga.COMPLETED
|
"Completed" -> SManga.COMPLETED
|
||||||
else -> SManga.UNKNOWN
|
else -> SManga.UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needCover) {
|
if (needCover) {
|
||||||
manga.thumbnail_url = getThumbnail(client.newCall(GET("$baseUrl/search/?search=${document.location()}", headers))
|
thumbnail_url = getThumbnail(getImage(client.newCall(GET("$baseUrl/search/?search=${document.location()}", headers))
|
||||||
.execute().asJsoup().select("div.wdm_results div.p_content img").first().attr("abs:src"))
|
.execute().asJsoup().select("div.wdm_results div.p_content img").first()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return manga
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mangaDetailsParse(document: Document) = throw Exception("Not used")
|
override fun mangaDetailsParse(document: Document) = throw Exception("Not used")
|
||||||
|
@ -167,9 +174,8 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin
|
||||||
val mangaUrl = document.baseUri()
|
val mangaUrl = document.baseUri()
|
||||||
val chfirstname = document.select(".chapter-class a[href*=$mangaUrl]")?.first()?.text()?.ifEmpty { "Ch. 1" }?.capitalize()
|
val chfirstname = document.select(".chapter-class a[href*=$mangaUrl]")?.first()?.text()?.ifEmpty { "Ch. 1" }?.capitalize()
|
||||||
?: "Ch. 1"
|
?: "Ch. 1"
|
||||||
val scangroup = document.select(".entry-terms a[href*=group]")?.first()?.text()
|
|
||||||
// create first chapter since its on main manga page
|
// create first chapter since its on main manga page
|
||||||
chapters.add(createChapter("1", document.baseUri(), date, chfirstname, scangroup))
|
chapters.add(createChapter("1", document.baseUri(), date, chfirstname))
|
||||||
// see if there are multiple chapters or not
|
// see if there are multiple chapters or not
|
||||||
document.select(chapterListSelector())?.let { it ->
|
document.select(chapterListSelector())?.let { it ->
|
||||||
it.forEach {
|
it.forEach {
|
||||||
|
@ -177,7 +183,7 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin
|
||||||
val pageNumber = it.text()
|
val pageNumber = it.text()
|
||||||
val chname = document.select(".chapter-class a[href$=/$pageNumber/]")?.text()?.ifEmpty { "Ch. $pageNumber" }?.capitalize()
|
val chname = document.select(".chapter-class a[href$=/$pageNumber/]")?.text()?.ifEmpty { "Ch. $pageNumber" }?.capitalize()
|
||||||
?: "Ch. $pageNumber"
|
?: "Ch. $pageNumber"
|
||||||
chapters.add(createChapter(it.text(), document.baseUri(), date, chname, scangroup))
|
chapters.add(createChapter(it.text(), document.baseUri(), date, chname))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,33 +192,27 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseDate(date: String): Long {
|
private fun parseDate(date: String): Long {
|
||||||
return SimpleDateFormat("MMM dd, yyyy", Locale.US).parse(date).time
|
return SimpleDateFormat("MMM dd, yyyy", Locale.US).parse(date)?.time ?: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createChapter(pageNumber: String, mangaUrl: String, date: Long, chname: String, scangroup: String?): SChapter {
|
private fun createChapter(pageNumber: String, mangaUrl: String, date: Long, chname: String): SChapter {
|
||||||
val chapter = SChapter.create()
|
val chapter = SChapter.create()
|
||||||
chapter.setUrlWithoutDomain("$mangaUrl/$pageNumber")
|
chapter.setUrlWithoutDomain("$mangaUrl/$pageNumber")
|
||||||
chapter.name = chname
|
chapter.name = chname
|
||||||
chapter.date_upload = date
|
chapter.date_upload = date
|
||||||
chapter.scanlator = scangroup
|
|
||||||
return chapter
|
return chapter
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterFromElement(element: Element) = throw Exception("Not used")
|
override fun chapterFromElement(element: Element) = throw Exception("Not used")
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
override fun pageListParse(response: Response): List<Page> {
|
|
||||||
val body = response.asJsoup()
|
override fun pageListParse(document: Document): List<Page> {
|
||||||
val pages = mutableListOf<Page>()
|
return document.select("div > img").mapIndexed { i, img ->
|
||||||
val elements = body.select("div>img")
|
Page(i, "", getImage(img))
|
||||||
for (i in 0 until elements.size) {
|
|
||||||
pages.add(Page(i, "", getImage(elements[i])))
|
|
||||||
}
|
}
|
||||||
return pages
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageListParse(document: Document) = throw Exception("Not used")
|
|
||||||
override fun imageUrlRequest(page: Page) = throw Exception("Not used")
|
|
||||||
override fun imageUrlParse(document: Document) = throw Exception("Not used")
|
override fun imageUrlParse(document: Document) = throw Exception("Not used")
|
||||||
|
|
||||||
// Filter Parsing, grabs pages as document and filters out Genres, Popular Tags, and Categories, Parings, and Scan Groups
|
// Filter Parsing, grabs pages as document and filters out Genres, Popular Tags, and Categories, Parings, and Scan Groups
|
||||||
|
@ -254,6 +254,7 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin
|
||||||
// Generates the filter lists for app
|
// Generates the filter lists for app
|
||||||
override fun getFilterList(): FilterList {
|
override fun getFilterList(): FilterList {
|
||||||
return FilterList(
|
return FilterList(
|
||||||
|
EnforceLanguageFilter(),
|
||||||
GenreFilter(returnFilter(getCache(cachedPagesUrls["genres"]!!), ".tagcloud a[href*=/genre/]")),
|
GenreFilter(returnFilter(getCache(cachedPagesUrls["genres"]!!), ".tagcloud a[href*=/genre/]")),
|
||||||
TagFilter(returnFilter(getCache(cachedPagesUrls["tags"]!!), ".tagcloud a[href*=/tag/]")),
|
TagFilter(returnFilter(getCache(cachedPagesUrls["tags"]!!), ".tagcloud a[href*=/tag/]")),
|
||||||
CatFilter(returnFilter(getCache(cachedPagesUrls["categories"]!!), ".links a")),
|
CatFilter(returnFilter(getCache(cachedPagesUrls["categories"]!!), ".links a")),
|
||||||
|
@ -262,6 +263,8 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class EnforceLanguageFilter : Filter.CheckBox("Enforce language", true)
|
||||||
|
|
||||||
private class GenreFilter(GENRES: Array<String>) : UriSelectFilter("Genre", "genre_str", arrayOf("Any", *GENRES))
|
private class GenreFilter(GENRES: Array<String>) : UriSelectFilter("Genre", "genre_str", arrayOf("Any", *GENRES))
|
||||||
private class TagFilter(POPTAG: Array<String>) : UriSelectFilter("Popular Tags", "tags", arrayOf("Any", *POPTAG))
|
private class TagFilter(POPTAG: Array<String>) : UriSelectFilter("Popular Tags", "tags", arrayOf("Any", *POPTAG))
|
||||||
private class CatFilter(CATID: Array<String>) : UriSelectFilter("Categories", "categories", arrayOf("Any", *CATID))
|
private class CatFilter(CATID: Array<String>) : UriSelectFilter("Categories", "categories", arrayOf("Any", *CATID))
|
||||||
|
|
Loading…
Reference in New Issue