[ru-mangalib] Realtime calculate of image server (#2317)

[ru-mangalib] Realtime calculate of image server
This commit is contained in:
Pavka 2020-02-29 20:13:39 +03:00 committed by GitHub
parent 86792746dc
commit 89c54f9cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 64 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: MangaLib'
pkgNameSuffix = 'ru.libmanga'
extClass = '.LibManga'
extVersionCode = 12
extVersionCode = 13
libVersion = '1.2'
}

View File

@ -1,34 +1,23 @@
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 : ConfigurableSource, HttpSource() {
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
class LibManga : HttpSource() {
override val name: String = "Mangalib"
@ -40,11 +29,6 @@ class LibManga : ConfigurableSource, HttpSource() {
override val baseUrl: String = "https://mangalib.me"
private var imageServerUrl: String = when(preferences.getString(SERVER_PREF, "main")){
"main" -> "https://img2.mangalib.me"
else -> "https://img3.mangalib.me"
}
override fun headersBuilder() = Headers.Builder().apply {
add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)")
add("Accept", "*/*")
@ -52,52 +36,6 @@ class LibManga : ConfigurableSource, HttpSource() {
private val jsonParser = JsonParser()
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("main", "alt")
summary = "%s"
setOnPreferenceChangeListener { _, newValue ->
imageServerUrl = when(newValue){
"main" -> "https://img2.mangalib.me"
else -> "https://img3.mangalib.me"
}
true
}
}
if(!preferences.contains(SERVER_PREF))
preferences.edit().putString(SERVER_PREF, "main").apply()
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("main", "alt")
summary = "%s"
setOnPreferenceChangeListener { _, newValue ->
imageServerUrl = when(newValue){
"main" -> "https://img2.mangalib.me"
else -> "https://img3.mangalib.me"
}
true
}
}
if(!preferences.contains(SERVER_PREF))
preferences.edit().putString(SERVER_PREF, "main").apply()
screen.addPreference(serverPref)
}
override fun latestUpdatesRequest(page: Int) = GET(baseUrl, headers)
private val latestUpdatesSelector = "div.updates__left"
@ -239,6 +177,11 @@ class LibManga : ConfigurableSource, HttpSource() {
val chapInfoJson = jsonParser.parse(chapInfo).obj
val imageServerUrl: String = when(chapInfoJson["imgServer"].string){
"compress" -> "https://img3.mangalib.me"
else -> "https://img2.mangalib.me"
}
// Get pages
val baseStr = document.select("span.pp")
.first()