sopa2day: Add year, casts, and genres. (#825)

This commit is contained in:
Jace 2022-03-20 16:56:55 +08:00 committed by GitHub
parent 6051d1430a
commit 9d94e22bfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import org.jsoup.Jsoup
import java.util.* import java.util.*
class SoaptwoDayProvider:MainAPI() { class SoaptwoDayProvider:MainAPI() {
@ -67,20 +68,44 @@ class SoaptwoDayProvider:MainAPI() {
} }
override suspend fun load(url: String): LoadResponse? { override suspend fun load(url: String): LoadResponse? {
val soup = app.get(url, timeout = 120).document val soup = app.get(url).document
val title = soup.selectFirst(".hidden-lg > div:nth-child(1) > h4").text() val title = soup.selectFirst(".hidden-lg > div:nth-child(1) > h4")?.text() ?: ""
val description = soup.selectFirst("p#wrap")?.text()?.trim() val description = soup.selectFirst("p#wrap")?.text()?.trim()
val poster = soup.selectFirst(".col-md-5 > div:nth-child(1) > div:nth-child(1) > img").attr("src") val poster = soup.selectFirst(".col-md-5 > div:nth-child(1) > div:nth-child(1) > img")?.attr("src")
val episodes = soup.select("div.alert > div > div > a").map { val episodes = soup.select("div.alert > div > div > a").mapNotNull {
val link = it.attr("href") val link = fixUrlNull(it?.attr("href")) ?: return@mapNotNull null
val name = it.text().replace(Regex("(^(\\d+)\\.)"),"") val name = it?.text()?.replace(Regex("(^(\\d+)\\.)"),"")
TvSeriesEpisode( TvSeriesEpisode(
name, name = name,
null, data = link
null,
fixUrl(link)
) )
} }
val otherInfoBody = soup.select("div.col-sm-8 div.panel-body")?.toString()
//Fetch casts
val casts = otherInfoBody?.substringAfter("Stars : ")
?.substringBefore("Genre : ")?.let {
Jsoup.parse(it)?.select("a")
}?.mapNotNull {
val castName = it?.text() ?: return@mapNotNull null
ActorData(
Actor(
name = castName
)
)
}
//Fetch year
val year = otherInfoBody?.substringAfter("<h4>Release : </h4>")
?.substringBefore("<div")?.let {
//Log.i(this.name, "Result => year string: $it")
Jsoup.parse(it)?.select("p")?.get(1)
}?.text()?.take(4)?.toIntOrNull()
//Fetch genres
val genre = otherInfoBody?.substringAfter("<h4>Genre : </h4>")
?.substringBefore("<h4>Release : </h4>")?.let {
//Log.i(this.name, "Result => genre string: $it")
Jsoup.parse(it)?.select("a")
}?.mapNotNull { it?.text()?.trim() ?: return@mapNotNull null }
val tvType = if (episodes.isEmpty()) TvType.Movie else TvType.TvSeries val tvType = if (episodes.isEmpty()) TvType.Movie else TvType.TvSeries
return when (tvType) { return when (tvType) {
TvType.TvSeries -> { TvType.TvSeries -> {
@ -90,9 +115,11 @@ class SoaptwoDayProvider:MainAPI() {
this.name, this.name,
tvType, tvType,
episodes.reversed(), episodes.reversed(),
fixUrl(poster), fixUrlNull(poster),
null, year = year,
description, description,
actors = casts,
tags = genre
) )
} }
TvType.Movie -> { TvType.Movie -> {
@ -102,9 +129,11 @@ class SoaptwoDayProvider:MainAPI() {
this.name, this.name,
tvType, tvType,
url, url,
fixUrl(poster), fixUrlNull(poster),
null, year = year,
description, description,
actors = casts,
tags = genre
) )
} }
else -> null else -> null
@ -181,10 +210,10 @@ class SoaptwoDayProvider:MainAPI() {
).text.replace("\\\"","\"").replace("\"{","{").replace("}\"","}") ).text.replace("\\\"","\"").replace("\"{","{").replace("}\"","}")
.replace("\\\\\\/","\\/") .replace("\\\\\\/","\\/")
val json = parseJson<ServerJson>(url) val json = parseJson<ServerJson>(url)
listOf( listOfNotNull(
json.stream, json.stream,
json.streambackup json.streambackup
).filterNotNull().apmap { stream -> ).apmap { stream ->
val cleanstreamurl = stream.replace("\\/","/").replace("\\\\\\","") val cleanstreamurl = stream.replace("\\/","/").replace("\\\\\\","")
if (cleanstreamurl.isNotBlank()) { if (cleanstreamurl.isNotBlank()) {
callback(ExtractorLink( callback(ExtractorLink(