Mangalib site update. Add prefs to image server (#2594)
Co-authored-by: Pavel Mosein <p.mosein@edadeal.ru>
This commit is contained in:
parent
5ea83b7087
commit
ab6d4d0a2e
|
@ -5,7 +5,7 @@ ext {
|
|||
appName = 'Tachiyomi: MangaLib'
|
||||
pkgNameSuffix = 'ru.libmanga'
|
||||
extClass = '.LibManga'
|
||||
extVersionCode = 14
|
||||
extVersionCode = 15
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,34 @@
|
|||
package eu.kanade.tachiyomi.extension.ru.libmanga
|
||||
|
||||
import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import android.support.v7.preference.ListPreference
|
||||
import android.support.v7.preference.PreferenceScreen
|
||||
import com.github.salomonbrys.kotson.*
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonParser
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||
import eu.kanade.tachiyomi.source.model.*
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import okhttp3.*
|
||||
import org.jsoup.nodes.Element
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import android.util.Base64.decode as base64Decode
|
||||
|
||||
|
||||
class LibManga : HttpSource() {
|
||||
class LibManga : ConfigurableSource, HttpSource() {
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_${id}_2", 0x0000)
|
||||
}
|
||||
|
||||
override val name: String = "Mangalib"
|
||||
|
||||
|
@ -36,6 +47,42 @@ class LibManga : HttpSource() {
|
|||
|
||||
private val jsonParser = JsonParser()
|
||||
|
||||
private var server: String? = preferences.getString(SERVER_PREF, null)
|
||||
|
||||
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
|
||||
val serverPref = androidx.preference.ListPreference(screen.context).apply {
|
||||
key = SERVER_PREF
|
||||
title = SERVER_PREF_Title
|
||||
entries = arrayOf("Основной", "Второй (тестовый)", "Сжатия (эконом трафика)")
|
||||
entryValues = arrayOf("secondary", "fourth", "compress")
|
||||
summary = "%s"
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
server = newValue.toString()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
screen.addPreference(serverPref)
|
||||
}
|
||||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
val serverPref = ListPreference(screen.context).apply {
|
||||
key = SERVER_PREF
|
||||
title = SERVER_PREF_Title
|
||||
entries = arrayOf("Основной", "Второй (тестовый)", "Сжатия (эконом трафика)")
|
||||
entryValues = arrayOf("secondary", "fourth", "compress")
|
||||
summary = "%s"
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
server = newValue.toString()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
screen.addPreference(serverPref)
|
||||
}
|
||||
|
||||
override fun latestUpdatesRequest(page: Int) = GET(baseUrl, headers)
|
||||
|
||||
private val latestUpdatesSelector = "div.updates__left"
|
||||
|
@ -130,8 +177,7 @@ class LibManga : HttpSource() {
|
|||
body.select(".info-list__row:has(strong:contains(Перевод))")
|
||||
.first()
|
||||
.select("span.m-label")
|
||||
.text())
|
||||
{
|
||||
.text()) {
|
||||
"продолжается" -> SManga.ONGOING
|
||||
"завершен" -> SManga.COMPLETED
|
||||
else -> SManga.UNKNOWN
|
||||
|
@ -150,10 +196,26 @@ class LibManga : HttpSource() {
|
|||
}
|
||||
|
||||
private fun chapterFromElement(element: Element): SChapter {
|
||||
val chapterLink = element.select("div.chapter-item__name > a").first()
|
||||
|
||||
val chapter = SChapter.create()
|
||||
|
||||
val chapterLink = element.select("div.chapter-item__name > a").first()
|
||||
if (chapterLink != null) {
|
||||
chapter.setUrlWithoutDomain(chapterLink.attr("href"))
|
||||
chapter.name = chapterLink.text()
|
||||
} 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)
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
return chapter
|
||||
|
@ -176,11 +238,12 @@ class LibManga : HttpSource() {
|
|||
.replace(";", "")
|
||||
|
||||
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 imageServerUrl: String = when(chapInfoJson["imgServer"].string){
|
||||
"compress" -> "https://img3.mangalib.me/"
|
||||
else -> "https://img2.mangalib.me/"
|
||||
}
|
||||
val serverToUse = if (this.server == null) defaultServer else this.server
|
||||
val imageServerUrl: String = servers[serverToUse].string
|
||||
|
||||
// Get pages
|
||||
val baseStr = document.select("span.pp")
|
||||
|
@ -195,7 +258,7 @@ class LibManga : HttpSource() {
|
|||
|
||||
val pages = mutableListOf<Page>()
|
||||
pagesJson.forEach { page ->
|
||||
pages.add(Page(page["p"].int, "", imageServerUrl + chapInfoJson["imgUrl"].string + page["u"].string))
|
||||
pages.add(Page(page["p"].int, "", imageServerUrl + imgUrl + page["u"].string))
|
||||
}
|
||||
|
||||
return pages
|
||||
|
@ -371,6 +434,6 @@ class LibManga : HttpSource() {
|
|||
|
||||
companion object {
|
||||
private const val SERVER_PREF_Title = "Сервер изображений"
|
||||
private const val SERVER_PREF = "imageServer"
|
||||
private const val SERVER_PREF = "MangaLibImageServer"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue