From b1e252455f477baedfb7d27eb64b3ff75ba45763 Mon Sep 17 00:00:00 2001 From: Ejan <35057681+e-shl@users.noreply.github.com> Date: Wed, 20 Apr 2022 02:55:19 +0500 Subject: [PATCH] [RU]Lib fix mobile parse in #11516 (#11520) * [RU]Lib fix mobile parse in #11516 * authorization message * other error * lost --- src/ru/libhentai/build.gradle | 2 +- .../extension/ru/libhentai/LibHentai.kt | 18 ++++++++++++------ src/ru/libmanga/build.gradle | 2 +- .../extension/ru/libmanga/LibManga.kt | 16 +++++++++++----- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/ru/libhentai/build.gradle b/src/ru/libhentai/build.gradle index e2e1e5e61..cdaf7c24b 100644 --- a/src/ru/libhentai/build.gradle +++ b/src/ru/libhentai/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'HentaiLib' pkgNameSuffix = 'ru.libhentai' extClass = '.LibHentai' - extVersionCode = 12 + extVersionCode = 13 isNsfw = true } diff --git a/src/ru/libhentai/src/eu/kanade/tachiyomi/extension/ru/libhentai/LibHentai.kt b/src/ru/libhentai/src/eu/kanade/tachiyomi/extension/ru/libhentai/LibHentai.kt index 60a5fbb5f..c19482737 100644 --- a/src/ru/libhentai/src/eu/kanade/tachiyomi/extension/ru/libhentai/LibHentai.kt +++ b/src/ru/libhentai/src/eu/kanade/tachiyomi/extension/ru/libhentai/LibHentai.kt @@ -8,6 +8,7 @@ import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST +import eu.kanade.tachiyomi.network.asObservable import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.Filter @@ -63,7 +64,7 @@ class LibHentai : ConfigurableSource, HttpSource() { override val baseUrl = "https://hentailib.me" override fun headersBuilder() = Headers.Builder().apply { - //User-Agent required for authorization through third-party accounts (mobile version for correct display in WebView) + // User-Agent required for authorization through third-party accounts (mobile version for correct display in WebView) add("User-Agent", "Mozilla/5.0 (Linux; Android 10; SM-G980F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Mobile Safari/537.36") add("Accept", "image/webp,*/*;q=0.8") add("Referer", baseUrl) @@ -91,7 +92,7 @@ class LibHentai : ConfigurableSource, HttpSource() { val originalRequest = chain.request() if (originalRequest.url.toString().contains(baseUrl)) if (!authClient.newCall(GET(baseUrl, headers)) - .execute().body!!.string().contains("header-right-menu__avatar") + .execute().body!!.string().contains("m-menu__user-info") ) throw Exception("Для просмотра 18+ контента необходима авторизация через WebView") return@addInterceptor chain.proceed(originalRequest) @@ -150,7 +151,12 @@ class LibHentai : ConfigurableSource, HttpSource() { private fun fetchPopularMangaFromApi(page: Int): Observable { return client.newCall(POST("$baseUrl/filterlist?dir=desc&sort=views&page=$page", catalogHeaders())) - .asObservableSuccess() + .asObservable().doOnNext { response -> + if (!response.isSuccessful) { + response.close() + if (response.code == 419) throw Exception("Для завершения авторизации необходимо перезапустить приложение с полной остановкой.") else throw Exception("HTTP error ${response.code}") + } + } .map { response -> popularMangaParse(response) } @@ -203,8 +209,8 @@ class LibHentai : ConfigurableSource, HttpSource() { rawAgeStop = "0+" } - val ratingValue = document.select(".media-rating.media-rating_lg div.media-rating__value").text().toFloat() * 2 - val ratingVotes = document.select(".media-rating.media-rating_lg div.media-rating__votes").text() + val ratingValue = document.select(".media-rating__value").last().text().toFloat() * 2 + val ratingVotes = document.select(".media-rating__votes").last().text() val ratingStar = when { ratingValue > 9.5 -> "★★★★★" ratingValue > 8.5 -> "★★★★✬" @@ -224,7 +230,7 @@ class LibHentai : ConfigurableSource, HttpSource() { isEng.equals("eng") && dataManga!!.jsonObject["engName"]?.jsonPrimitive?.content.orEmpty().isNotEmpty() -> dataManga.jsonObject["engName"]!!.jsonPrimitive.content else -> dataManga!!.jsonObject["name"]!!.jsonPrimitive.content } - manga.thumbnail_url = document.select(".media-sidebar__cover > img").attr("src") + manga.thumbnail_url = document.select(".media-header__cover").attr("src") manga.author = body.select("div.media-info-list__title:contains(Автор) + div").text() manga.artist = body.select("div.media-info-list__title:contains(Художник) + div").text() manga.status = if (document.html().contains("paper empty section") diff --git a/src/ru/libmanga/build.gradle b/src/ru/libmanga/build.gradle index ac3e876e8..729d7a87f 100644 --- a/src/ru/libmanga/build.gradle +++ b/src/ru/libmanga/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'MangaLib' pkgNameSuffix = 'ru.libmanga' extClass = '.LibManga' - extVersionCode = 68 + extVersionCode = 69 } dependencies { diff --git a/src/ru/libmanga/src/eu/kanade/tachiyomi/extension/ru/libmanga/LibManga.kt b/src/ru/libmanga/src/eu/kanade/tachiyomi/extension/ru/libmanga/LibManga.kt index d305b8022..39fc60af3 100644 --- a/src/ru/libmanga/src/eu/kanade/tachiyomi/extension/ru/libmanga/LibManga.kt +++ b/src/ru/libmanga/src/eu/kanade/tachiyomi/extension/ru/libmanga/LibManga.kt @@ -8,6 +8,7 @@ import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST +import eu.kanade.tachiyomi.network.asObservable import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.Filter @@ -84,7 +85,7 @@ class LibManga : ConfigurableSource, HttpSource() { override val baseUrl: String = domain.toString() override fun headersBuilder() = Headers.Builder().apply { - //User-Agent required for authorization through third-party accounts (mobile version for correct display in WebView) + // User-Agent required for authorization through third-party accounts (mobile version for correct display in WebView) add("User-Agent", "Mozilla/5.0 (Linux; Android 10; SM-G980F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Mobile Safari/537.36") add("Accept", "image/webp,*/*;q=0.8") add("Referer", baseUrl) @@ -143,7 +144,12 @@ class LibManga : ConfigurableSource, HttpSource() { private fun fetchPopularMangaFromApi(page: Int): Observable { return client.newCall(POST("$baseUrl/filterlist?dir=desc&sort=views&page=$page", catalogHeaders())) - .asObservableSuccess() + .asObservable().doOnNext { response -> + if (!response.isSuccessful) { + response.close() + if (response.code == 419) throw Exception("Для завершения авторизации необходимо перезапустить приложение с полной остановкой.") else throw Exception("HTTP error ${response.code}") + } + } .map { response -> popularMangaParse(response) } @@ -196,8 +202,8 @@ class LibManga : ConfigurableSource, HttpSource() { rawAgeStop = "0+" } - val ratingValue = document.select(".media-rating.media-rating_lg div.media-rating__value").text().toFloat() * 2 - val ratingVotes = document.select(".media-rating.media-rating_lg div.media-rating__votes").text() + val ratingValue = document.select(".media-rating__value").last().text().toFloat() * 2 + val ratingVotes = document.select(".media-rating__votes").last().text() val ratingStar = when { ratingValue > 9.5 -> "★★★★★" ratingValue > 8.5 -> "★★★★✬" @@ -217,7 +223,7 @@ class LibManga : ConfigurableSource, HttpSource() { isEng.equals("eng") && dataManga!!.jsonObject["engName"]?.jsonPrimitive?.content.orEmpty().isNotEmpty() -> dataManga.jsonObject["engName"]!!.jsonPrimitive.content else -> dataManga!!.jsonObject["name"]!!.jsonPrimitive.content } - manga.thumbnail_url = document.select(".media-sidebar__cover > img").attr("src") + manga.thumbnail_url = document.select(".media-header__cover").attr("src") manga.author = body.select("div.media-info-list__title:contains(Автор) + div").text() manga.artist = body.select("div.media-info-list__title:contains(Художник) + div").text() manga.status = if (document.html().contains("paper empty section")