Update MRM Filter Code (#2305)

* Update MRM Filter Code

* Code Reformat
This commit is contained in:
happywillow0 2020-02-28 18:11:11 -05:00 committed by GitHub
parent 39ffa659ed
commit 86792746dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 26 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: MyReadingManga' appName = 'Tachiyomi: MyReadingManga'
pkgNameSuffix = 'all.myreadingmanga' pkgNameSuffix = 'all.myreadingmanga'
extClass = '.MyReadingMangaFactory' extClass = '.MyReadingMangaFactory'
extVersionCode = 31 extVersionCode = 32
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -1,17 +1,20 @@
package eu.kanade.tachiyomi.extension.all.myreadingmanga package eu.kanade.tachiyomi.extension.all.myreadingmanga
import android.net.Uri import android.net.Uri
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.* import eu.kanade.tachiyomi.source.model.*
import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.* import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import rx.Observable import rx.Observable
import java.io.IOException import java.io.IOException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
open class MyReadingManga(override val lang: String) : ParsedHttpSource() { open class MyReadingManga(override val lang: String) : ParsedHttpSource() {
@ -200,7 +203,8 @@ open class MyReadingManga(override val lang: String) : ParsedHttpSource() {
val date = parseDate(document.select(".entry-time").text()) val date = parseDate(document.select(".entry-time").text())
val mangaUrl = document.baseUri() val mangaUrl = document.baseUri()
val chfirstname = document.select(".chapter-class a[href*=$mangaUrl]")?.first()?.text()?.ifEmpty { "Ch. 1" }?.capitalize() ?:"Ch. 1" val chfirstname = document.select(".chapter-class a[href*=$mangaUrl]")?.first()?.text()?.ifEmpty { "Ch. 1" }?.capitalize()
?: "Ch. 1"
val scangroup = document.select(".entry-terms a[href*=group]")?.first()?.text() 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, scangroup))
@ -209,7 +213,8 @@ open class MyReadingManga(override val lang: String) : ParsedHttpSource() {
it.forEach { it.forEach {
if (!it.text().contains("Next »", true)) { if (!it.text().contains("Next »", true)) {
val pageNumber = it.text() val pageNumber = it.text()
val chname = document.select(".chapter-class a[href$=/$pageNumber/]")?.text()?.ifEmpty { "Ch. $pageNumber" }?.capitalize() ?:"Ch. $pageNumber" val chname = document.select(".chapter-class a[href$=/$pageNumber/]")?.text()?.ifEmpty { "Ch. $pageNumber" }?.capitalize()
?: "Ch. $pageNumber"
chapters.add(createChapter(it.text(), document.baseUri(), date, chname, scangroup)) chapters.add(createChapter(it.text(), document.baseUri(), date, chname, scangroup))
} }
} }
@ -253,11 +258,30 @@ open class MyReadingManga(override val lang: String) : ParsedHttpSource() {
//Filter Parsing, grabs home page as document and filters out Genres, Popular Tags, and Catagorys //Filter Parsing, grabs home page as document and filters out Genres, Popular Tags, and Catagorys
private val getFilter:Document? = try { network.client.newCall(GET(baseUrl, headers)).execute().asJsoup() } catch (e: IOException) {null}
private fun returnFilter (css: String, attributekey: String): Array<Pair<String, String>> = if (getFilter?.select(".cf-browser-verification").isNullOrEmpty()) { private val filterDoc = getFilterDoc(baseUrl)
getFilter?.select(css)?.map { Pair(it.attr(attributekey).substringBeforeLast("/").substringAfterLast("/"), it.text()) }?.toTypedArray() ?: arrayOf(Pair("","Error getting filters")) private val categoryDoc = getFilterDoc("$baseUrl/cats/")
} else { private val pairingDoc = getFilterDoc("$baseUrl/pairing/")
private val scangroupDoc = getFilterDoc("$baseUrl/group/")
private fun getFilterDoc(url: String): Document? {
return try {
network.client.newCall(GET(url, headers)).execute().asJsoup()
} catch (e: IOException) {
null
}
}
private fun returnFilter(document: Document?, css: String, attributekey: String): Array<Pair<String, String>> {
val captchacheck = !document?.select(".cf-captcha-container").isNullOrEmpty()
val cfcheck = !document?.select(".cf-browser-verification").isNullOrEmpty()
return if (captchacheck) {
arrayOf(Pair("", "Solve captcha and force restart app"))
} else if (cfcheck) {
arrayOf(Pair("", "Open 'Latest' and force restart app")) arrayOf(Pair("", "Open 'Latest' and force restart app"))
} else {
document?.select(css)?.map { Pair(it.attr(attributekey).substringBeforeLast("/").substringAfterLast("/"), it.text()) }?.toTypedArray()
?: arrayOf(Pair("", "Error getting filters"))
}
} }
//Generates the filter lists for app //Generates the filter lists for app
@ -266,16 +290,20 @@ open class MyReadingManga(override val lang: String) : ParsedHttpSource() {
//MRM does not support genre filtering and text search at the same time //MRM does not support genre filtering and text search at the same time
Filter.Header("NOTE: Filters are ignored if using text search."), Filter.Header("NOTE: Filters are ignored if using text search."),
Filter.Header("Only one filter can be used at a time."), Filter.Header("Only one filter can be used at a time."),
GenreFilter(returnFilter(".tagcloud a[href*=/genre/]", "href")), GenreFilter(returnFilter(filterDoc, ".tagcloud a[href*=/genre/]", "href")),
TagFilter(returnFilter(".tagcloud a[href*=/tag/]","href")), TagFilter(returnFilter(filterDoc, ".tagcloud a[href*=/tag/]", "href")),
CatFilter(returnFilter(".level-0", "value")) CatFilter(returnFilter(categoryDoc, ".links a", "abs:href")),
PairingFilter(returnFilter(pairingDoc, ".links a", "abs:href")),
ScanGroupFilter(returnFilter(scangroupDoc, ".links a", "abs:href"))
) )
return filterList return filterList
} }
private class GenreFilter(GENRES: Array<Pair<String, String>>) : UriSelectFilterPath("Genre", "genre", arrayOf(Pair("", "Any"), *GENRES)) private class GenreFilter(GENRES: Array<Pair<String, String>>) : UriSelectFilterPath("Genre", "genre", arrayOf(Pair("", "Any"), *GENRES))
private class TagFilter(POPTAG: Array<Pair<String, String>>) : UriSelectFilterPath("Popular Tags", "tag", arrayOf(Pair("", "Any"), *POPTAG)) private class TagFilter(POPTAG: Array<Pair<String, String>>) : UriSelectFilterPath("Popular Tags", "tag", arrayOf(Pair("", "Any"), *POPTAG))
private class CatFilter(CATID: Array<Pair<String, String>>) : UriSelectFilterQuery("Categories", "cat", arrayOf(Pair("","Any"), *CATID)) private class CatFilter(CATID: Array<Pair<String, String>>) : UriSelectFilterShortPath("Categories", "cat", arrayOf(Pair("", "Any"), *CATID))
private class PairingFilter(PAIR: Array<Pair<String, String>>) : UriSelectFilterPath("Pairing", "pairing", arrayOf(Pair("", "Any"), *PAIR))
private class ScanGroupFilter(GROUP: Array<Pair<String, String>>) : UriSelectFilterPath("Scanlation Group", "group", arrayOf(Pair("", "Any"), *GROUP))
/** /**
* Class that creates a select filter. Each entry in the dropdown has a name and a display name. * Class that creates a select filter. Each entry in the dropdown has a name and a display name.
@ -293,13 +321,15 @@ open class MyReadingManga(override val lang: String) : ParsedHttpSource() {
.appendPath(vals[state].first) .appendPath(vals[state].first)
} }
} }
private open class UriSelectFilterQuery(displayName: String, val uriParam: String, val vals: Array<Pair<String, String>>,
private open class UriSelectFilterShortPath(displayName: String, val uriParam: String, val vals: Array<Pair<String, String>>,
val firstIsUnspecified: Boolean = true, val firstIsUnspecified: Boolean = true,
defaultValue: Int = 0) : defaultValue: Int = 0) :
Filter.Select<String>(displayName, vals.map { it.second }.toTypedArray(), defaultValue), UriFilter { Filter.Select<String>(displayName, vals.map { it.second }.toTypedArray(), defaultValue), UriFilter {
override fun addToUri(uri: Uri.Builder) { override fun addToUri(uri: Uri.Builder) {
if (state != 0 || !firstIsUnspecified) if (state != 0 || !firstIsUnspecified)
uri.appendQueryParameter(uriParam, vals[state].first) uri.appendPath(vals[state].first)
} }
} }
@ -311,3 +341,4 @@ open class MyReadingManga(override val lang: String) : ParsedHttpSource() {
} }
} }