[RU]Remanga PUT chapters on alt img server (#15706)
* [RU]Remanga PUT chapters on alt img server * private PUT * new notify and description exmanga * hard disable PUTing chapters
This commit is contained in:
parent
7a3125f084
commit
240a513405
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = 'Remanga'
|
extName = 'Remanga'
|
||||||
pkgNameSuffix = 'ru.remanga'
|
pkgNameSuffix = 'ru.remanga'
|
||||||
extClass = '.Remanga'
|
extClass = '.Remanga'
|
||||||
extVersionCode = 64
|
extVersionCode = 65
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
|
@ -37,12 +37,17 @@ import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
import kotlinx.serialization.json.decodeFromJsonElement
|
import kotlinx.serialization.json.decodeFromJsonElement
|
||||||
|
import okhttp3.CacheControl
|
||||||
|
import okhttp3.FormBody
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
import okhttp3.RequestBody
|
||||||
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
|
@ -55,6 +60,7 @@ import java.net.URLDecoder
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import java.util.concurrent.TimeUnit.MINUTES
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
@ -70,6 +76,20 @@ class Remanga : ConfigurableSource, HttpSource() {
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun PUT(
|
||||||
|
url: String,
|
||||||
|
headers: Headers = Headers.Builder().build(),
|
||||||
|
body: RequestBody = FormBody.Builder().build(),
|
||||||
|
cache: CacheControl = CacheControl.Builder().maxAge(10, MINUTES).build(),
|
||||||
|
): Request {
|
||||||
|
return Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.put(body)
|
||||||
|
.headers(headers)
|
||||||
|
.cacheControl(cache)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
private val baseOrig: String = "https://api.remanga.org"
|
private val baseOrig: String = "https://api.remanga.org"
|
||||||
private val baseMirr: String = "https://api.xn--80aaig9ahr.xn--c1avg" // https://реманга.орг
|
private val baseMirr: String = "https://api.xn--80aaig9ahr.xn--c1avg" // https://реманга.орг
|
||||||
private val domain: String? = preferences.getString(DOMAIN_PREF, baseOrig)
|
private val domain: String? = preferences.getString(DOMAIN_PREF, baseOrig)
|
||||||
|
@ -447,6 +467,12 @@ class Remanga : ConfigurableSource, HttpSource() {
|
||||||
scanlator = "exmanga"
|
scanlator = "exmanga"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chapter.is_paid and (chapter.is_bought == true)) {
|
||||||
|
if (exChID == null) {
|
||||||
|
url = "$url#is_bought"
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
exChID = null
|
exChID = null
|
||||||
}
|
}
|
||||||
|
@ -476,10 +502,35 @@ class Remanga : ConfigurableSource, HttpSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.N)
|
@TargetApi(Build.VERSION_CODES.N)
|
||||||
private fun pageListParse(response: Response, urlRequest: String): List<Page> {
|
private fun pageListParse(response: Response, urlChapter: String): List<Page> {
|
||||||
val body = response.body.string()
|
val body = response.body.string()
|
||||||
val heightEmptyChunks = 10
|
val heightEmptyChunks = 10
|
||||||
if (urlRequest.contains(baseUrl)) {
|
if (urlChapter.contains(exManga)) {
|
||||||
|
try {
|
||||||
|
val exPage = json.decodeFromString<SeriesExWrapperDto<List<List<PagesDto>>>>(body)
|
||||||
|
val result = mutableListOf<Page>()
|
||||||
|
exPage.data.forEach {
|
||||||
|
it.filter { page -> page.height > heightEmptyChunks }.forEach { page ->
|
||||||
|
result.add(Page(result.size, "", page.link))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
} catch (e: SerializationException) {
|
||||||
|
throw IOException("Главы больше нет на exmanga. Попробуйте обновить список глав (свайп сверху).")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (urlChapter.contains("#is_bought") and (preferences.getBoolean(exPAID_PREF, true))) {
|
||||||
|
val newHeaders = exHeaders().newBuilder()
|
||||||
|
.add("Content-Type", "application/json")
|
||||||
|
.build()
|
||||||
|
client.newCall(
|
||||||
|
PUT(
|
||||||
|
"$exManga/chapter",
|
||||||
|
newHeaders,
|
||||||
|
body.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()),
|
||||||
|
),
|
||||||
|
).execute()
|
||||||
|
}
|
||||||
return try {
|
return try {
|
||||||
val page = json.decodeFromString<SeriesWrapperDto<PageDto>>(body)
|
val page = json.decodeFromString<SeriesWrapperDto<PageDto>>(body)
|
||||||
page.content.pages.filter { it.height > heightEmptyChunks }.map {
|
page.content.pages.filter { it.height > heightEmptyChunks }.map {
|
||||||
|
@ -495,19 +546,6 @@ class Remanga : ConfigurableSource, HttpSource() {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
val exPage = json.decodeFromString<SeriesExWrapperDto<List<List<PagesDto>>>>(body)
|
|
||||||
val result = mutableListOf<Page>()
|
|
||||||
exPage.data.forEach {
|
|
||||||
it.filter { page -> page.height > heightEmptyChunks }.forEach { page ->
|
|
||||||
result.add(Page(result.size, "", page.link))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
} catch (e: SerializationException) {
|
|
||||||
throw IOException("Главы больше нет на exmanga. Попробуйте обновить список глав (свайп сверху).")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,9 +556,12 @@ class Remanga : ConfigurableSource, HttpSource() {
|
||||||
GET(chapter.url, exHeaders())
|
GET(chapter.url, exHeaders())
|
||||||
} else {
|
} else {
|
||||||
if (chapter.name.contains("\uD83D\uDCB2")) {
|
if (chapter.name.contains("\uD83D\uDCB2")) {
|
||||||
throw IOException("Глава платная. Если вы покупаете главу, то, пожалуйста, поделитесь с другими через браузерное расширение exmanga.")
|
val noEX = if (preferences.getBoolean(exPAID_PREF, true)) {
|
||||||
|
"Если вы покупаете главу, то вы делитесь с другими пользователями exmanga."
|
||||||
|
} else { "Функции exmanga отключены." }
|
||||||
|
throw IOException("Глава платная. $noEX")
|
||||||
}
|
}
|
||||||
GET(baseUrl + "/api/titles/chapters/" + chapter.url.substringAfterLast("/ch") + "/", headers)
|
GET(baseUrl + "/api/titles/chapters/" + chapter.url.substringAfterLast("/ch").substringBefore("#is_bought") + "/", headers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,12 +569,12 @@ class Remanga : ConfigurableSource, HttpSource() {
|
||||||
return client.newCall(pageListRequest(chapter))
|
return client.newCall(pageListRequest(chapter))
|
||||||
.asObservableSuccess()
|
.asObservableSuccess()
|
||||||
.map { response ->
|
.map { response ->
|
||||||
pageListParse(response, pageListRequest(chapter).url.toString())
|
pageListParse(response, chapter.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChapterUrl(chapter: SChapter): String {
|
override fun getChapterUrl(chapter: SChapter): String {
|
||||||
return if (chapter.url.contains(exManga)) chapter.url else baseUrl.replace("api.", "") + chapter.url
|
return if (chapter.url.contains(exManga)) chapter.url else baseUrl.replace("api.", "") + chapter.url.substringBefore("#is_bought")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchImageUrl(page: Page): Observable<String> = Observable.just(page.imageUrl!!)
|
override fun fetchImageUrl(page: Page): Observable<String> = Observable.just(page.imageUrl!!)
|
||||||
|
@ -840,7 +881,7 @@ class Remanga : ConfigurableSource, HttpSource() {
|
||||||
val exChapterShow = androidx.preference.CheckBoxPreference(screen.context).apply {
|
val exChapterShow = androidx.preference.CheckBoxPreference(screen.context).apply {
|
||||||
key = exPAID_PREF
|
key = exPAID_PREF
|
||||||
title = "Показывать главы из exmanga"
|
title = "Показывать главы из exmanga"
|
||||||
summary = "Показывает главы купленные другими людьми и поделившиеся ими через браузерное расширение exmanga"
|
summary = "Показывает главы купленные другими людьми и поделившиеся ими через браузерное расширение exmanga. Также отключает отправку ваших глав из Tachiyomi в exmanga."
|
||||||
setDefaultValue(true)
|
setDefaultValue(true)
|
||||||
|
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
setOnPreferenceChangeListener { _, newValue ->
|
||||||
|
|
Loading…
Reference in New Issue