Rule34video update (#1129)

This commit is contained in:
Nitin Dahale
2023-01-03 18:59:16 +05:30
committed by GitHub
parent 07ac55f953
commit 631d74100f
2 changed files with 32 additions and 68 deletions

View File

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

View File

@ -26,7 +26,7 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override val name = "Rule34Video" override val name = "Rule34Video"
override val baseUrl = "https://rule34video.com/" override val baseUrl = "https://rule34video.com"
override val lang = "en" override val lang = "en"
@ -76,19 +76,12 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override fun videoListParse(response: Response): List<Video> { override fun videoListParse(response: Response): List<Video> {
val document = response.asJsoup() val document = response.asJsoup()
return document.select("div.video_tools div:nth-child(3) div a.tag_item")
val videoLinks = document.select("div.video_tools div:nth-child(3) div a.tag_item") .map { element ->
.map { val url = element.attr("href")
it.attr("href") + it.text() val quality = element.text().substringAfter(" ")
.replace("MP4", "") Video(url, quality, url)
} }
val videoList = mutableListOf<Video>()
for (video in videoLinks) {
videoList.add(Video(video.split(" ")[0], video.split(" ")[1], video.split(" ")[0]))
}
return videoList
} }
override fun videoListSelector() = throw Exception("not used") override fun videoListSelector() = throw Exception("not used")
@ -98,47 +91,31 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override fun videoFromElement(element: Element) = throw Exception("not used") override fun videoFromElement(element: Element) = throw Exception("not used")
override fun List<Video>.sort(): List<Video> { override fun List<Video>.sort(): List<Video> {
val quality = preferences.getString("preferred_quality", "720p") val quality = preferences.getString("preferred_quality", "720p") ?: return this
if (quality != null) { return this.sortedWith(compareByDescending { it.quality == quality })
val newList = mutableListOf<Video>()
var preferred = 0
for (video in this) {
if (video.quality == quality) {
newList.add(preferred, video)
preferred++
} else {
newList.add(video)
}
}
return newList
}
return this
} }
// Search // Search
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 orderFilter = filters.find { it is OrderFilter } as OrderFilter
val catBy = filters.find { it is CategoryBy } as CategoryBy val categoryFilter = filters.find { it is CategoryBy } as CategoryBy
val newSort = when (sortedBy.toUriPart()) { val sortType = when (orderFilter.toUriPart()) {
"latest-updates" -> "post_date" "latest-updates" -> "post_date"
"most-popular" -> "video_viewed" "most-popular" -> "video_viewed"
"top-rated" -> "rating" "top-rated" -> "rating"
else -> "" else -> ""
} }
val tagFilter = try {
verifyTag = true val tagFilter: String = if (filters.find { it is TagFilter } is TagFilter) {
(filters.find { it is TagFilter } as TagFilter).state (filters.find { it is TagFilter } as TagFilter).state
} catch (e: Exception) { } else {
verifyTag = false
"" ""
} }
tagDocument = if (tagFilter.isNotBlank()) client.newCall(GET("$baseUrl/search_ajax.php?tag=$tagFilter", headers)).execute().asJsoup() else Document("") val url = "$baseUrl/search_ajax.php?tag=${tagFilter.ifBlank { "." }}"
val response = client.newCall(GET(url, headers)).execute()
tagDocument = response.asJsoup()
val tagSearch = try { val tagSearch = try {
filters.find { it is TagSearch } as TagSearch filters.find { it is TagSearch } as TagSearch
@ -146,22 +123,14 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
TagSearch(arrayOf()).apply { state = 0 } TagSearch(arrayOf()).apply { state = 0 }
} }
return when { return if (query.isNotEmpty()) {
query.isNotEmpty() -> { GET("$baseUrl/search/$query/?flag1=${categoryFilter.toUriPart()}&sort_by=$sortType&from_videos=$page&tag_ids=all%2C${tagSearch.toUriPart()}")
GET("$baseUrl/search/$query/?flag1=${catBy.toUriPart()}&sort_by=$newSort&from_videos=$page", headers) // with search } else {
} GET("$baseUrl/search/?flag1=${categoryFilter.toUriPart()}&sort_by=$sortType&from_videos=$page&tag_ids=all%2C${tagSearch.toUriPart()}")
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
}
} }
} }
override fun searchAnimeSelector(): String = popularAnimeSelector() override fun searchAnimeSelector(): String = popularAnimeSelector()
override fun searchAnimeFromElement(element: Element): SAnime = popularAnimeFromElement(element) override fun searchAnimeFromElement(element: Element): SAnime = popularAnimeFromElement(element)
override fun searchAnimeNextPageSelector(): String = "div.item.pager.next a" override fun searchAnimeNextPageSelector(): String = "div.item.pager.next a"
@ -172,7 +141,8 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
anime.author = document.select("#tab_video_info div:nth-child(3) div div:nth-child(2) a").joinToString { it.text() } anime.author = document.select("#tab_video_info div:nth-child(3) div div:nth-child(2) a").joinToString { it.text() }
anime.description = document.select("#tab_video_info div:nth-child(2) div em").text() + anime.description = document.select("#tab_video_info div:nth-child(2) div em").text() +
"\n\nViews : ${document.select("#tab_video_info div.info.row div:nth-child(2) span").text().replace((" "), ",")}\n" + "\n\nViews : ${document.select("#tab_video_info div.info.row div:nth-child(2) span").text().replace((" "), ",")}\n" +
"Duration : ${document.select("#tab_video_info div.info.row div:nth-child(3) span").text()}\n" "Duration : ${document.select("#tab_video_info div.info.row div:nth-child(3) span").text()}\n" +
"Quality : ${document.select("div.video_tools div:nth-child(3) div a.tag_item").joinToString { it.text().substringAfter(" ") }}\n"
anime.genre = document.select("div.video_tools div:nth-child(4) div a").joinToString { anime.genre = document.select("div.video_tools div:nth-child(4) div a").joinToString {
if (it.text() != "+ | Suggest") it.text() else "" if (it.text() != "+ | Suggest") it.text() else ""
} }
@ -193,22 +163,17 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
key = "preferred_quality" key = "preferred_quality"
title = "Preferred quality" title = "Preferred quality"
entries = arrayOf("2160p", "1080p", "720p", "480p", "360p") entries = arrayOf("2160p", "1080p", "720p", "480p", "360p")
entryValues = arrayOf("2160p", "1080p", "720p", "480p", "360p") entryValues = entries
setDefaultValue("1080p") setDefaultValue("1080p")
summary = "%s" summary = "%s"
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String preferences.edit().putString(key, newValue as String).commit()
val index = findIndexOfValue(selected)
val entry = entryValues[index] as String
preferences.edit().putString(key, entry).commit()
} }
} }
screen.addPreference(videoQualityPref) screen.addPreference(videoQualityPref)
} }
// Filters // Filters
private var verifyTag = false
private var tagDocument = Document("") private var tagDocument = Document("")
private fun tagsResults(document: Document): Array<Pair<String, String>> { private fun tagsResults(document: Document): Array<Pair<String, String>> {
@ -227,21 +192,20 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
OrderFilter(), OrderFilter(),
CategoryBy(), CategoryBy(),
AnimeFilter.Separator(), AnimeFilter.Separator(),
AnimeFilter.Header("Tags Search (Experimental)"), AnimeFilter.Header("Entered a \"tag\", click on \"filter\" then Click \"reset\" to load tags."),
AnimeFilter.Header("Click in \"filter\" to make te search and click in \"reset\" to see the results."),
TagFilter(), TagFilter(),
if (verifyTag) TagSearch(tagsResults(tagDocument)) else AnimeFilter.Separator(), TagSearch(tagsResults(tagDocument))
) )
private class TagFilter : AnimeFilter.Text("Tag", "") private class TagFilter : AnimeFilter.Text("Click \"reset\" without any text to load all A-Z tags.", "")
private class TagSearch(results: Array<Pair<String, String>>) : UriPartFilter( private class TagSearch(results: Array<Pair<String, String>>) : UriPartFilter(
"Category Filter", "Tag Filter ",
results results
) )
private class CategoryBy : UriPartFilter( private class CategoryBy : UriPartFilter(
"Category Filter", "Category Filter ",
arrayOf( arrayOf(
Pair("All", ""), Pair("All", ""),
Pair("Futa", "15"), Pair("Futa", "15"),
@ -250,7 +214,7 @@ class Rule34Video : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
) )
private class OrderFilter : UriPartFilter( private class OrderFilter : UriPartFilter(
"Order", "Sort By ",
arrayOf( arrayOf(
Pair("Latest", "latest-updates"), Pair("Latest", "latest-updates"),
Pair("Most Viewed", "most-popular"), Pair("Most Viewed", "most-popular"),