From b93693883ce71d271093b17d298dbbfa0cbaa8cd Mon Sep 17 00:00:00 2001 From: Claudemirovsky <63046606+Claudemirovsky@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:23:47 -0300 Subject: [PATCH] feat(de/animebase): Add VidGuard extractor + implement search filters (#2244) --- src/de/animebase/build.gradle | 3 +- .../animeextension/de/animebase/AnimeBase.kt | 56 +++- .../de/animebase/AnimeBaseFilters.kt | 285 ++++++++++++++++++ .../animebase/extractors/VidGuardExtractor.kt | 124 ++++++++ 4 files changed, 457 insertions(+), 11 deletions(-) create mode 100644 src/de/animebase/src/eu/kanade/tachiyomi/animeextension/de/animebase/AnimeBaseFilters.kt create mode 100644 src/de/animebase/src/eu/kanade/tachiyomi/animeextension/de/animebase/extractors/VidGuardExtractor.kt diff --git a/src/de/animebase/build.gradle b/src/de/animebase/build.gradle index f6973bb477..763a656a4c 100644 --- a/src/de/animebase/build.gradle +++ b/src/de/animebase/build.gradle @@ -7,8 +7,9 @@ ext { extName = 'Anime-Base' pkgNameSuffix = 'de.animebase' extClass = '.AnimeBase' - extVersionCode = 14 + extVersionCode = 15 libVersion = '13' + containsNsfw = true } dependencies { diff --git a/src/de/animebase/src/eu/kanade/tachiyomi/animeextension/de/animebase/AnimeBase.kt b/src/de/animebase/src/eu/kanade/tachiyomi/animeextension/de/animebase/AnimeBase.kt index 1ad53bb73d..a2b4431e06 100644 --- a/src/de/animebase/src/eu/kanade/tachiyomi/animeextension/de/animebase/AnimeBase.kt +++ b/src/de/animebase/src/eu/kanade/tachiyomi/animeextension/de/animebase/AnimeBase.kt @@ -4,8 +4,10 @@ import android.app.Application import androidx.preference.ListPreference import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.animeextension.de.animebase.extractors.UnpackerExtractor +import eu.kanade.tachiyomi.animeextension.de.animebase.extractors.VidGuardExtractor import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource import eu.kanade.tachiyomi.animesource.model.AnimeFilterList +import eu.kanade.tachiyomi.animesource.model.AnimesPage import eu.kanade.tachiyomi.animesource.model.SAnime import eu.kanade.tachiyomi.animesource.model.SEpisode import eu.kanade.tachiyomi.animesource.model.Video @@ -67,6 +69,8 @@ class AnimeBase : ConfigurableAnimeSource, ParsedAnimeHttpSource() { override fun latestUpdatesNextPageSelector() = null // =============================== Search =============================== + override fun getFilterList() = AnimeBaseFilters.FILTER_LIST + private val searchToken by lazy { client.newCall(GET("$baseUrl/searching", headers)).execute() .use { it.asJsoup() } @@ -75,20 +79,49 @@ class AnimeBase : ConfigurableAnimeSource, ParsedAnimeHttpSource() { } override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request { - val body = FormBody.Builder() - .add("_token", searchToken) - .add("_token", searchToken) - .add("name_serie", query) - .add("jahr", "") - .build() - return POST("$baseUrl/searching", headers, body) + val params = AnimeBaseFilters.getSearchParameters(filters) + + return when { + params.list.isEmpty() -> { + val body = FormBody.Builder() + .add("_token", searchToken) + .add("_token", searchToken) + .add("name_serie", query) + .add("jahr", params.year.toIntOrNull()?.toString() ?: "") + .apply { + params.languages.forEach { add("dubsub[]", it) } + params.genres.forEach { add("genre[]", it) } + }.build() + POST("$baseUrl/searching", headers, body) + } + + else -> { + GET("$baseUrl/${params.list}${params.letter}?page=$page", headers) + } + } + } + + override fun searchAnimeParse(response: Response): AnimesPage { + val doc = response.use { it.asJsoup() } + + return when { + doc.location().contains("/searching") -> { + val animes = doc.select(searchAnimeSelector()).map(::searchAnimeFromElement) + AnimesPage(animes, false) + } + else -> { // pages like filmlist or animelist + val animes = doc.select(popularAnimeSelector()).map(::popularAnimeFromElement) + val hasNext = doc.selectFirst(searchAnimeNextPageSelector()) != null + AnimesPage(animes, hasNext) + } + } } - override fun searchAnimeSelector(): String = "div.col-lg-9.col-md-8 div.box-body a" + override fun searchAnimeSelector() = "div.col-lg-9.col-md-8 div.box-body > a" override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element) - override fun searchAnimeNextPageSelector() = null + override fun searchAnimeNextPageSelector() = "ul.pagination li > a[rel=next]" // =========================== Anime Details ============================ override fun animeDetailsParse(document: Document) = SAnime.create().apply { @@ -154,6 +187,7 @@ class AnimeBase : ConfigurableAnimeSource, ParsedAnimeHttpSource() { "Voe.SX" to "https://voe.sx/e/", "Lulustream" to "https://lulustream.com/e/", "VTube" to "https://vtbe.to/embed-", + "VidGuard" to "https://vembed.net/e/", ) } @@ -182,13 +216,14 @@ class AnimeBase : ConfigurableAnimeSource, ParsedAnimeHttpSource() { video.audioTracks, ) } - }.getOrElse { emptyList() } + }.onFailure { it.printStackTrace() }.getOrElse { emptyList() } }.flatten().ifEmpty { throw Exception("No videos xDDDDDD") } } private val streamWishExtractor by lazy { StreamWishExtractor(client, headers) } private val voeExtractor by lazy { VoeExtractor(client) } private val unpackerExtractor by lazy { UnpackerExtractor(client, headers) } + private val vidguardExtractor by lazy { VidGuardExtractor(client) } private fun getVideosFromHoster(hoster: String, urlpart: String): List