Minor optimizations

This commit is contained in:
Jace 2022-08-22 07:52:43 +08:00
parent d148bfbdef
commit 14e8cf2f0f
3 changed files with 24 additions and 22 deletions

View File

@ -1,5 +1,5 @@
// use an integer for version numbers // use an integer for version numbers
version = 1 version = 2
cloudstream { cloudstream {

View File

@ -27,7 +27,7 @@ class JavFreeProvider : MainAPI() {
@JsonProperty("active") val active: Int? @JsonProperty("active") val active: Int?
) )
fun String.cleanText() : String = this.trim().removePrefix("Watch JAV Free") private fun String.cleanText() : String = this.trim().removePrefix("Watch JAV Free")
.removeSuffix("HD Free Online on JAVFree.SH").trim() .removeSuffix("HD Free Online on JAVFree.SH").trim()
.removePrefix("Watch JAV").trim() .removePrefix("Watch JAV").trim()
@ -39,26 +39,25 @@ class JavFreeProvider : MainAPI() {
val document = Jsoup.parse(html) val document = Jsoup.parse(html)
val all = ArrayList<HomePageList>() val all = ArrayList<HomePageList>()
val mainbody = document.getElementsByTag("body").select("div#page") document.getElementsByTag("body").select("div#page")
.select("div#content").select("div#primary") .select("div#content").select("div#primary")
.select("main") .select("main")
.select("section").forEach { it2 ->
mainbody.select("section").forEach { it2 ->
// Fetch row title // Fetch row title
val title = it2?.select("h2.widget-title")?.text() ?: "Unnamed Row" val title = it2?.select("h2.widget-title")?.text() ?: "Unnamed Row"
// Fetch list of items and map // Fetch list of items and map
it2.select("div.videos-list") it2.select("div.videos-list").select("article")
.select("article").let { inner -> .let { inner ->
val elements: List<SearchResponse> = inner.map { val elements: List<SearchResponse> = inner.mapNotNull {
val aa = it.select("a").firstOrNull() val aa = it.select("a").firstOrNull()
val link = fixUrl(aa?.attr("href") ?: "") val link = fixUrlNull(aa?.attr("href")) ?: return@mapNotNull null
val name = aa?.attr("title") ?: "<No Title>" val name = aa?.attr("title") ?: "<No Title>"
var image = aa?.select("div")?.select("img")?.attr("data-src") ?: "" var image = aa?.select("div")?.select("img")?.attr("data-src")
if (image == "") { if (image.isNullOrBlank()) {
image = aa?.select("div")?.select("video")?.attr("poster") ?: "" image = aa?.select("div")?.select("video")?.attr("poster")
} }
val year = null val year = null
@ -85,21 +84,24 @@ class JavFreeProvider : MainAPI() {
} }
override suspend fun search(query: String): List<SearchResponse> { override suspend fun search(query: String): List<SearchResponse> {
val url = "$mainUrl/search/movie/${query}" val searchUrl = "$mainUrl/search/movie/${query}"
val html = app.get(url).text val document = app.get(searchUrl).document
val document = Jsoup.parse(html).select("div.videos-list").select("article[id^=post]") .select("div.videos-list").select("article[id^=post]")
return document.map { return document.mapNotNull {
val aa = it.select("a") val aa = it?.select("a") ?: return@mapNotNull null
val url = fixUrlNull(aa.attr("href")) ?: return@mapNotNull null
val title = aa.attr("title") val title = aa.attr("title")
val href = fixUrl(aa.attr("href"))
val year = null val year = null
val image = aa.select("div.post-thumbnail.thumbs-rotation") var image = aa.select("div.post-thumbnail.thumbs-rotation")
.select("img").attr("data-src") .select("img").attr("data-src")
if (image.isNullOrBlank()) {
image = aa.select("div").select("video").attr("poster").toString()
}
MovieSearchResponse( MovieSearchResponse(
name = title, name = title,
url = href, url = url,
apiName = this.name, apiName = this.name,
type = tvType, type = tvType,
posterUrl = image, posterUrl = image,
@ -174,7 +176,7 @@ class JavFreeProvider : MainAPI() {
return true return true
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() //e.printStackTrace()
logError(e) logError(e)
} }
return false return false

View File

@ -5,7 +5,7 @@ version = 1
cloudstream { cloudstream {
// All of these properties are optional, you can safely remove them // All of these properties are optional, you can safely remove them
description = "High quality JAV subbed" description = "High quality JAV with English sub"
authors = listOf("Jace") authors = listOf("Jace")
/** /**