[ru] libmanga fix 18+ mangas w/o authorization (#4259)

* [ru] libmanga fix 18+ mangas w/o authorization

* Remove logs from libmanga

Co-authored-by: pavkazzz <me@pavkazzz.ru>
This commit is contained in:
Pavka 2020-09-01 00:47:40 +03:00 committed by GitHub
parent e51b2a7b3a
commit 3e495f969a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 51 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'MangaLib'
pkgNameSuffix = 'ru.libmanga'
extClass = '.LibManga'
extVersionCode = 19
extVersionCode = 20
libVersion = '1.2'
}

View File

@ -6,7 +6,6 @@ import android.support.v7.preference.ListPreference
import android.support.v7.preference.PreferenceScreen
import com.github.salomonbrys.kotson.array
import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.int
import com.github.salomonbrys.kotson.nullArray
import com.github.salomonbrys.kotson.nullString
import com.github.salomonbrys.kotson.obj
@ -55,18 +54,26 @@ class LibManga : ConfigurableSource, HttpSource() {
override fun headersBuilder() = Headers.Builder().apply {
add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)")
add("Accept", "*/*")
add("Accept", "image/webp,*/*;q=0.8")
}
private val jsonParser = JsonParser()
private var server: String? = preferences.getString(SERVER_PREF, null)
private val defaultServer = "https://img2.emanga.ru"
private val servers = mapOf(
"secondary" to "https://img2.emanga.ru",
"fourth" to "https://img4.imgslib.ru",
"compress" to "https://img3.ranobelib.me"
)
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
val serverPref = androidx.preference.ListPreference(screen.context).apply {
key = SERVER_PREF
title = SERVER_PREF_Title
entries = arrayOf("Основной", "Второй (тестовый)", "Сжатия (эконом трафика)")
entries = arrayOf("Основной", "Второй (тестовый)", "Третий (эконом трафика)")
entryValues = arrayOf("secondary", "fourth", "compress")
summary = "%s"
@ -83,7 +90,7 @@ class LibManga : ConfigurableSource, HttpSource() {
val serverPref = ListPreference(screen.context).apply {
key = SERVER_PREF
title = SERVER_PREF_Title
entries = arrayOf("Основной", "Второй (тестовый)", "Сжатия (эконом трафика)")
entries = arrayOf("Основной", "Второй (тестовый)", "Третий (эконом трафика)")
entryValues = arrayOf("secondary", "fourth", "compress")
summary = "%s"
@ -96,6 +103,10 @@ class LibManga : ConfigurableSource, HttpSource() {
screen.addPreference(serverPref)
}
private fun imageServerUrl(): String {
return this.servers.getOrDefault(this.server, this.defaultServer)
}
override fun latestUpdatesRequest(page: Int) = GET(baseUrl, headers)
private val latestUpdatesSelector = "div.updates__left"
@ -220,22 +231,10 @@ class LibManga : ConfigurableSource, HttpSource() {
private fun chapterFromElement(element: Element): SChapter {
val chapter = SChapter.create()
val chapterLink = element.select("div.chapter-item__name > a").first()
if (chapterLink != null) {
chapter.setUrlWithoutDomain(chapterLink.attr("href"))
} else {
// Found multiple translate. Get first one for now
val volume = element.attr("data-volume")
val number = element.attr("data-number")
val teams = jsonParser.parse(element.attr("data-teams"))
val team = teams[0]["slug"].nullString
val baseUrl = "${element.baseUri()}/v$volume/c$number"
val url = if (team != null) "$baseUrl/$team" else baseUrl
chapter.setUrlWithoutDomain(url)
}
val id = element.attr("data-id")
val slug = element.baseUri().replace("$baseUrl/", "")
val url = "/download/$id?slug=$slug"
chapter.setUrlWithoutDomain(url)
chapter.name = element.select("div.chapter-item__name").first().text()
chapter.date_upload = SimpleDateFormat("dd.MM.yyyy", Locale.US)
.parse(element.select("div.chapter-item__date").text()).time
@ -250,38 +249,16 @@ class LibManga : ConfigurableSource, HttpSource() {
}
override fun pageListParse(response: Response): List<Page> {
val document = response.asJsoup()
val chapInfo = document
.select("script:containsData(window.__info)")
.first()
.html()
.trim()
.removePrefix("window.__info = ")
.split(";")
.first()
val chapInfoJson = jsonParser.parse(chapInfo).obj
val servers = chapInfoJson["servers"].asJsonObject
val defaultServer: String = chapInfoJson["img"]["server"].string
val imgUrl: String = chapInfoJson["img"]["url"].string
val serverToUse = if (this.server == null) defaultServer else this.server
val imageServerUrl: String = servers[serverToUse].string
// Get pages
val pagesArr = document
.select("script:containsData(window.__pg)")
.first()
.html()
.trim()
.removePrefix("window.__pg = ")
.removeSuffix(";")
val pagesJson = jsonParser.parse(pagesArr).array
val body = response.body()!!.string()
val slug = response.request().url().queryParameter("slug")
val json = jsonParser.parse(body)
val images = json["images"].array
val chapterslug = json["chapter"]["slug"].string
val pages = mutableListOf<Page>()
pagesJson.forEach { page ->
pages.add(Page(page["p"].int, "", imageServerUrl + imgUrl + page["u"].string))
images.forEachIndexed { index, page ->
val url = "${this.imageServerUrl()}/manga/$slug/chapters/$chapterslug/${page.string}"
pages.add(Page(index, "", url))
}
return pages