Added Filters [Rule34Video] (#783)

This commit is contained in:
Diego Peña Y Lillo
2022-08-19 08:12:54 -04:00
committed by GitHub
parent 713dad68a2
commit 225eaacc02
2 changed files with 79 additions and 72 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Rule34Video' extName = 'Rule34Video'
pkgNameSuffix = 'en.rule34video' pkgNameSuffix = 'en.rule34video'
extClass = '.Rule34Video' extClass = '.Rule34Video'
extVersionCode = 2 extVersionCode = 3
libVersion = '13' libVersion = '13'
containsNsfw = true containsNsfw = true
} }

View File

@ -120,42 +120,49 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
private var cat = false private var cat = false
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request { override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
val sortedBy = filters.find { it is OrderFilter } as OrderFilter
val catBy = filters.find { it is CategoryBy } as CategoryBy
val newSort = when (sortedBy.toUriPart()) {
"latest-updates" -> "post_date"
val sortedBy = getSearchParameters(filters).split(":")[0] "most-popular" -> "video_viewed"
val catBy = getSearchParameters(filters).split(":")[1]
return if (query.isNotEmpty()) { "top-rated" -> "rating"
else -> ""
}
val tagFilter = try {
verifyTag = true
(filters.find { it is TagFilter } as TagFilter).state
} catch (e: Exception) {
verifyTag = false
""
}
cat = false tagDocument = if (tagFilter.isNotBlank()) client.newCall(GET("$baseUrl/search_ajax.php?tag=$tagFilter", headers)).execute().asJsoup() else Document("")
var newSort = ""
when (sortedBy) { val tagSearch = try {
"latest-updates" -> { filters.find { it is TagSearch } as TagSearch
newSort = "post_date" } catch (e: Exception) {
} TagSearch(arrayOf()).apply { state = 0 }
"most-popular" -> { }
newSort = "video_viewed"
} return when {
"top-rated" -> { query.isNotEmpty() -> {
newSort = "rating" GET("$baseUrl/search/$query/?flag1=${catBy.toUriPart()}&sort_by=$newSort&from_videos=$page", headers) // with search
} }
tagSearch.state != 0 -> GET("$baseUrl/search/?tag_ids=all,${tagSearch.toUriPart()}&sort_by=$newSort&from_videos=$page") // with tag search
sortedBy.state != 0 || catBy.state != 0 -> {
GET("$baseUrl/search/?flag1=${catBy.toUriPart()}&sort_by=${sortedBy.toUriPart()}&from_videos=$page", headers) // with sort and category
}
else -> {
GET("$baseUrl/latest-updates/$page/", headers) // without search
} }
GET("$baseUrl/search/$query/?flag1=$catBy&sort_by=$newSort&from_videos=$page", headers) // with search
} else {
cat = true
GET("$baseUrl/$sortedBy/$page/?flag1=$catBy", headers) // without search
} }
} }
override fun searchAnimeSelector(): String = "div.item.thumb" override fun searchAnimeSelector(): String = popularAnimeSelector()
override fun searchAnimeFromElement(element: Element): SAnime { override fun searchAnimeFromElement(element: Element): SAnime = popularAnimeFromElement(element)
val anime = SAnime.create()
anime.setUrlWithoutDomain(element.select("a.th").attr("href"))
anime.title = element.select("a.th div.thumb_title").text()
anime.thumbnail_url = element.select("a.th div.img img").attr("data-original")
return anime
}
override fun searchAnimeNextPageSelector(): String = "div.item.pager.next a" override fun searchAnimeNextPageSelector(): String = "div.item.pager.next a"
@ -201,58 +208,58 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
} }
// Filters // Filters
private var verifyTag = false
private var tagDocument = Document("")
private data class View(val name: String, val id: String) private fun tagsResults(document: Document): Array<Pair<String, String>> {
private class ViewList(Views: Array<String>) : AnimeFilter.Select<String>("Order", Views) val tagList = mutableListOf(Pair("<Select>", ""))
private val viewBy = getView().map { tagList.addAll(
it.name document.select("div.item").map {
}.toTypedArray() val tagValue = it.select("input").attr("value")
private fun getView() = listOf( val tagName = it.select("label").text()
View("Latest", "latest-updates"), Pair(tagName, tagValue)
View("Most Viewed", "most-popular"), }
View("Top Rated", "top-rated"), )
return tagList.toTypedArray()
) }
private data class Category(val name: String, val id: String)
private class CategoryList(Categories: Array<String>) : AnimeFilter.Select<String>("Category", Categories)
private val categoryBy = getCategory().map {
it.name
}.toTypedArray()
private fun getCategory() = listOf(
Category("All", ""),
Category("Futa", "15"),
Category("Gay", "192"),
)
override fun getFilterList(): AnimeFilterList = AnimeFilterList( override fun getFilterList(): AnimeFilterList = AnimeFilterList(
AnimeFilter.Header("Might not work in first try."), OrderFilter(),
CategoryBy(),
AnimeFilter.Separator(), AnimeFilter.Separator(),
ViewList(viewBy), AnimeFilter.Header("Tags Search (Experimental)"),
CategoryList(categoryBy), AnimeFilter.Header("Click in \"filter\" to make te search and click in \"reset\" to see the results."),
TagFilter(),
if (verifyTag) TagSearch(tagsResults(tagDocument)) else AnimeFilter.Separator(),
) )
private fun getSearchParameters(filters: AnimeFilterList): String { private class TagFilter : AnimeFilter.Text("Tag", "")
var viewBy = ""
var categoryBy = ""
filters.forEach { filter -> private class TagSearch(results: Array<Pair<String, String>>) : UriPartFilter(
when (filter) { "Category Filter",
results
)
is ViewList -> { // ---Order private class CategoryBy : UriPartFilter(
viewBy = getView()[filter.state].id "Category Filter",
} arrayOf(
Pair("All", ""),
Pair("Futa", "15"),
Pair("Gay", "192"),
)
)
is CategoryList -> { // ---Category private class OrderFilter : UriPartFilter(
if (cat) { "Order",
categoryBy = getCategory()[filter.state].id arrayOf(
} Pair("Latest", "latest-updates"),
} Pair("Most Viewed", "most-popular"),
Pair("Top Rated", "top-rated"),
)
)
else -> {} private open class UriPartFilter(displayName: String, val vals: Array<Pair<String, String>>) :
} AnimeFilter.Select<String>(displayName, vals.map { it.first }.toTypedArray()) {
} fun toUriPart() = vals[state].second
return "$viewBy:$categoryBy"
} }
} }