[RU]LibGroup back redirect 18+ register (#12190)

* [RU]LibGroup back redirect 18+ register

* catalogHeaders another 419

* global 419

* minimize requests/newCalls

* check over intercepter overloaded

* not 404 but 18+
This commit is contained in:
Ejan 2022-06-15 19:10:59 +05:00 committed by GitHub
parent d7f162058f
commit 3e74c11917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 36 deletions

View File

@ -16,15 +16,6 @@ class HentaiLib : LibGroup("HentaiLib", "https://hentailib.me", "ru") {
override val client: OkHttpClient = super.client.newBuilder()
.addInterceptor(::imageContentTypeIntercept)
.addInterceptor { chain ->
val originalRequest = chain.request()
if (originalRequest.url.toString().contains(baseUrl))
if (!network.cloudflareClient.newCall(GET(baseUrl, headers))
.execute().body!!.string().contains("m-menu__user-info")
)
throw IOException("Для просмотра 18+ контента необходима авторизация через WebView")
return@addInterceptor chain.proceed(originalRequest)
}
.build()
private var csrfToken: String = ""

View File

@ -27,16 +27,6 @@ class MangaLib : LibGroup("MangaLib", "https://mangalib.me", "ru") {
override val client: OkHttpClient = super.client.newBuilder()
.addInterceptor(::imageContentTypeIntercept)
.addInterceptor { chain ->
val originalRequest = chain.request()
val response = chain.proceed(originalRequest)
if (originalRequest.url.toString().contains(baseUrl))
if (!network.cloudflareClient.newCall(GET(baseUrl, headers))
.execute().body!!.string().contains("m-menu__user-info") && response.code == 404
)
throw IOException("Для просмотра 18+ контента необходима авторизация через WebView")
return@addInterceptor response
}
.build()
private var csrfToken: String = ""

View File

@ -9,7 +9,7 @@ class LibGenerator: ThemeSourceGenerator {
override val themeClass = "LibGroup"
override val baseVersionCode: Int = 4
override val baseVersionCode: Int = 5
override val sources = listOf(
SingleLang("MangaLib", "https://mangalib.me", "ru", overrideVersionCode = 74),

View File

@ -21,6 +21,7 @@ import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.util.asJsoup
import java.io.IOException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
@ -79,6 +80,12 @@ abstract class LibGroup(
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(1, TimeUnit.MINUTES)
.rateLimit(2)
.addInterceptor { chain ->
val response = chain.proceed(chain.request())
if (response.code == 419)
throw IOException("HTTP error ${response.code}. Для завершения авторизации необходимо перезапустить приложение с полной остановкой.")
return@addInterceptor response
}
.build()
override fun headersBuilder() = Headers.Builder().apply {
@ -119,12 +126,7 @@ abstract class LibGroup(
private fun fetchLatestMangaFromApi(page: Int): Observable<MangasPage> {
return client.newCall(POST("$baseUrl/latest-updates?page=$page", catalogHeaders()))
.asObservable().doOnNext { response ->
if (!response.isSuccessful) {
response.close()
if (response.code == 419) throw Exception("Для завершения авторизации необходимо перезапустить приложение с полной остановкой.") else throw Exception("HTTP error ${response.code}")
}
}
.asObservableSuccess()
.map { response ->
latestUpdatesParse(response)
}
@ -159,12 +161,7 @@ abstract class LibGroup(
private fun fetchPopularMangaFromApi(page: Int): Observable<MangasPage> {
return client.newCall(POST("$baseUrl/filterlist?dir=desc&sort=views&page=$page", catalogHeaders()))
.asObservable().doOnNext { response ->
if (!response.isSuccessful) {
response.close()
if (response.code == 419) throw Exception("Для завершения авторизации необходимо перезапустить приложение с полной остановкой.") else throw Exception("HTTP error ${response.code}")
}
}
.asObservableSuccess()
.map { response ->
popularMangaParse(response)
}
@ -215,10 +212,8 @@ abstract class LibGroup(
rawCategory.isNotBlank() -> rawCategory
else -> "Манга"
}
var rawAgeStop = document.select(".media-short-info .media-short-info__item[data-caution]").text()
if (rawAgeStop.isEmpty()) {
rawAgeStop = "0+"
}
val rawAgeStop = document.select(".media-short-info .media-short-info__item[data-caution]").text()
val ratingValue = document.select(".media-rating__value").last().text().toFloat() * 2
val ratingVotes = document.select(".media-rating__votes").last().text()
@ -281,9 +276,23 @@ abstract class LibGroup(
return manga
}
override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
return client.newCall(mangaDetailsRequest(manga))
.asObservable().doOnNext { response ->
if (!response.isSuccessful) {
if (response.code == 404 && response.asJsoup().select("#show-login-button").isNotEmpty()) throw Exception("HTTP error ${response.code}. Для просмотра 18+ контента необходима авторизация через WebView") else throw Exception("HTTP error ${response.code}")
}
}
.map { response ->
mangaDetailsParse(response)
}
}
// Chapters
override fun chapterListParse(response: Response): List<SChapter> {
val document = response.asJsoup()
val rawAgeStop = document.select(".media-short-info .media-short-info__item[data-caution]").text()
if (rawAgeStop == "18+" && document.select("#show-login-button").isNotEmpty())
throw Exception("Для просмотра 18+ контента необходима авторизация через WebView")
val redirect = document.html()
if (redirect.contains("paper empty section")) {
return emptyList()
@ -312,6 +321,18 @@ abstract class LibGroup(
return chapters ?: emptyList()
}
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
return client.newCall(mangaDetailsRequest(manga))
.asObservable().doOnNext { response ->
if (!response.isSuccessful) {
if (response.code == 404 && response.asJsoup().select("#show-login-button").isNotEmpty()) throw Exception("HTTP error ${response.code}. Для просмотра 18+ контента необходима авторизация через WebView") else throw Exception("HTTP error ${response.code}")
}
}
.map { response ->
chapterListParse(response)
}
}
private fun sortChaptersByTranslator
(sortingList: String?, chaptersList: JsonArray?, slug: String, branches: List<JsonElement>): List<SChapter>? {
var chapters: List<SChapter>? = null
@ -396,6 +417,14 @@ abstract class LibGroup(
override fun pageListParse(response: Response): List<Page> {
val document = response.asJsoup()
//redirect Регистрация 18+
val redirect = document.html()
if (!redirect.contains("window.__info")) {
if (redirect.contains("hold-transition login-page")) {
throw Exception("Для просмотра 18+ контента необходима авторизация через WebView")
}
}
val chapInfo = document
.select("script:containsData(window.__info)")
.first()