Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(de/animebase): Add VidGuard extractor + implement search filters #2244

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/de/animebase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ ext {
extName = 'Anime-Base'
pkgNameSuffix = 'de.animebase'
extClass = '.AnimeBase'
extVersionCode = 14
extVersionCode = 15
libVersion = '13'
containsNsfw = true
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() }
Expand All @@ -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 {
Expand Down Expand Up @@ -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/",
)
}

Expand Down Expand Up @@ -182,20 +216,22 @@ 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<Video> {
val url = hosterSettings.get(hoster)!! + urlpart
return when (hoster) {
"Streamwish" -> streamWishExtractor.videosFromUrl(url)
"Voe.SX" -> voeExtractor.videoFromUrl(url)?.let(::listOf)
"VTube", "Lulustream" -> unpackerExtractor.videosFromUrl(url, hoster)
"VidGuard" -> vidguardExtractor.videosFromUrl(url)
else -> null
} ?: emptyList()
}
Expand Down
Loading