From 388b2213fa06652e5a0b26f0f164b59c963480aa Mon Sep 17 00:00:00 2001 From: Claudemirovsky <63046606+Claudemirovsky@users.noreply.github.com> Date: Mon, 29 Jan 2024 09:51:38 -0300 Subject: [PATCH] fix(pt/betteranime): Fix http 405 on search + add automatic login (#2839) --- src/pt/betteranime/build.gradle | 2 +- .../pt/betteranime/BAFilters.kt | 6 +- .../pt/betteranime/BetterAnime.kt | 238 ++++++++---------- .../pt/betteranime/LoginInterceptor.kt | 50 ++++ .../pt/betteranime/RecaptchaV3Bypasser.kt | 155 ++++++++++++ .../pt/betteranime/dto/BetterAnimeDto.kt | 43 +--- 6 files changed, 325 insertions(+), 169 deletions(-) create mode 100644 src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/LoginInterceptor.kt create mode 100644 src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/RecaptchaV3Bypasser.kt diff --git a/src/pt/betteranime/build.gradle b/src/pt/betteranime/build.gradle index 32edc13052..eb02af39dc 100644 --- a/src/pt/betteranime/build.gradle +++ b/src/pt/betteranime/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Better Anime' extClass = '.BetterAnime' - extVersionCode = 8 + extVersionCode = 9 } apply from: "$rootDir/common.gradle" diff --git a/src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/BAFilters.kt b/src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/BAFilters.kt index 13973d8a41..4bde7f0034 100644 --- a/src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/BAFilters.kt +++ b/src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/BAFilters.kt @@ -55,12 +55,10 @@ object BAFilters { internal fun getSearchParameters(filters: AnimeFilterList): FilterSearchParams { if (filters.isEmpty()) return FilterSearchParams() - val genres = listOf(" ") + filters.parseCheckbox(BAFiltersData.GENRES) - return FilterSearchParams( filters.asQueryPart(), filters.asQueryPart(), - genres, + filters.parseCheckbox(BAFiltersData.GENRES), ) } @@ -73,7 +71,7 @@ object BAFilters { Pair("Dublado", "dublado"), ) - val YEARS = arrayOf(EVERY) + (2023 downTo 1976).map { + val YEARS = arrayOf(EVERY) + (2024 downTo 1976).map { Pair(it.toString(), it.toString()) }.toTypedArray() diff --git a/src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/BetterAnime.kt b/src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/BetterAnime.kt index 6637897cfb..e00fe0a5aa 100644 --- a/src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/BetterAnime.kt +++ b/src/pt/betteranime/src/eu/kanade/tachiyomi/animeextension/pt/betteranime/BetterAnime.kt @@ -1,12 +1,10 @@ package eu.kanade.tachiyomi.animeextension.pt.betteranime import android.app.Application -import android.content.SharedPreferences import androidx.preference.ListPreference import androidx.preference.PreferenceScreen -import eu.kanade.tachiyomi.animeextension.pt.betteranime.dto.LivewireResponseDto +import eu.kanade.tachiyomi.animeextension.pt.betteranime.dto.ComponentsDto import eu.kanade.tachiyomi.animeextension.pt.betteranime.dto.PayloadData -import eu.kanade.tachiyomi.animeextension.pt.betteranime.dto.PayloadItem import eu.kanade.tachiyomi.animeextension.pt.betteranime.extractors.BetterAnimeExtractor import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource import eu.kanade.tachiyomi.animesource.model.AnimeFilterList @@ -19,10 +17,14 @@ import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.awaitSuccess import eu.kanade.tachiyomi.util.asJsoup -import kotlinx.serialization.encodeToString +import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive -import okhttp3.Interceptor +import kotlinx.serialization.json.buildJsonArray +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put +import kotlinx.serialization.json.putJsonArray import okhttp3.MediaType.Companion.toMediaType import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody @@ -33,7 +35,6 @@ import org.jsoup.nodes.Element import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy -import java.io.IOException class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() { @@ -46,12 +47,12 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() { override val supportsLatest = true override val client = network.client.newBuilder() - .addInterceptor(::loginInterceptor) + .addInterceptor(LoginInterceptor(network.client, baseUrl, headers)) .build() private val json: Json by injectLazy() - private val preferences: SharedPreferences by lazy { + private val preferences by lazy { Injekt.get().getSharedPreferences("source_$id", 0x0000) } @@ -64,58 +65,34 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() { // so we use the latest added anime page instead. override fun popularAnimeParse(response: Response) = latestUpdatesParse(response) - override fun popularAnimeRequest(page: Int): Request = - GET("$baseUrl/ultimosAdicionados?page=$page") + override fun popularAnimeRequest(page: Int) = GET("$baseUrl/ultimosAdicionados?page=$page", headers) override fun popularAnimeSelector() = TODO() override fun popularAnimeFromElement(element: Element) = TODO() override fun popularAnimeNextPageSelector() = TODO() - // ============================== Episodes ============================== - override fun episodeListSelector(): String = "ul#episodesList > li.list-group-item-action > a" - - override fun episodeListParse(response: Response) = - super.episodeListParse(response).reversed() + // =============================== Latest =============================== + override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/ultimosLancamentos?page=$page", headers) - override fun episodeFromElement(element: Element) = SEpisode.create().apply { - val episodeName = element.text() - setUrlWithoutDomain(element.attr("href")) - name = episodeName - episode_number = episodeName.substringAfterLast(" ").toFloatOrNull() ?: 0F - } + override fun latestUpdatesSelector() = "div.list-animes article" - // ============================ Video Links ============================= - override fun videoListParse(response: Response): List