diff --git a/multisrc/overrides/libgroup/hentailib/src/HentaiLib.kt b/multisrc/overrides/libgroup/hentailib/src/HentaiLib.kt index c0a7ef3bb..252349ca0 100644 --- a/multisrc/overrides/libgroup/hentailib/src/HentaiLib.kt +++ b/multisrc/overrides/libgroup/hentailib/src/HentaiLib.kt @@ -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 = "" diff --git a/multisrc/overrides/libgroup/mangalib/src/MangaLib.kt b/multisrc/overrides/libgroup/mangalib/src/MangaLib.kt index f81166b5f..9215b0639 100644 --- a/multisrc/overrides/libgroup/mangalib/src/MangaLib.kt +++ b/multisrc/overrides/libgroup/mangalib/src/MangaLib.kt @@ -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 = "" diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGenerator.kt index 7d2697936..d9d0fd8cb 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGenerator.kt @@ -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), diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGroup.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGroup.kt index e5ce2fd91..6ad80f5d6 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGroup.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGroup.kt @@ -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 { 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 { 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 { + 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 { 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> { + 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): List? { var chapters: List? = null @@ -396,6 +417,14 @@ abstract class LibGroup( override fun pageListParse(response: Response): List { 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()