From 3e495f969ae314f0d5315f2c47362f6df8475be9 Mon Sep 17 00:00:00 2001
From: Pavka
Date: Tue, 1 Sep 2020 00:47:40 +0300
Subject: [PATCH] [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
---
src/ru/libmanga/build.gradle | 2 +-
.../extension/ru/libmanga/LibManga.kt | 77 +++++++------------
2 files changed, 28 insertions(+), 51 deletions(-)
diff --git a/src/ru/libmanga/build.gradle b/src/ru/libmanga/build.gradle
index 6387f994c..10f55c20a 100644
--- a/src/ru/libmanga/build.gradle
+++ b/src/ru/libmanga/build.gradle
@@ -5,7 +5,7 @@ ext {
extName = 'MangaLib'
pkgNameSuffix = 'ru.libmanga'
extClass = '.LibManga'
- extVersionCode = 19
+ extVersionCode = 20
libVersion = '1.2'
}
diff --git a/src/ru/libmanga/src/eu/kanade/tachiyomi/extension/ru/libmanga/LibManga.kt b/src/ru/libmanga/src/eu/kanade/tachiyomi/extension/ru/libmanga/LibManga.kt
index a302ddb16..c1bb8df2f 100644
--- a/src/ru/libmanga/src/eu/kanade/tachiyomi/extension/ru/libmanga/LibManga.kt
+++ b/src/ru/libmanga/src/eu/kanade/tachiyomi/extension/ru/libmanga/LibManga.kt
@@ -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 {
- 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()
- 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