Parse episode list and date
This commit is contained in:
parent
e52b320927
commit
e8f63f1fdc
|
@ -1,5 +1,6 @@
|
|||
package com.lagradost
|
||||
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.lagradost.cloudstream3.*
|
||||
|
@ -7,6 +8,7 @@ import com.lagradost.cloudstream3.utils.AppUtils
|
|||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||
import com.lagradost.cloudstream3.utils.loadExtractor
|
||||
import org.jsoup.select.Elements
|
||||
import java.time.LocalDateTime
|
||||
|
||||
class PinoyMoviesHub : MainAPI() {
|
||||
//private val TAG = "Dev"
|
||||
|
@ -64,8 +66,7 @@ class PinoyMoviesHub : MainAPI() {
|
|||
.getResults(this.name)
|
||||
}
|
||||
|
||||
override suspend fun load(url: String): MovieLoadResponse {
|
||||
//TODO: Load polishing
|
||||
override suspend fun load(url: String): LoadResponse {
|
||||
val doc = app.get(url).document
|
||||
val body = doc.getElementsByTag("body").firstOrNull()
|
||||
val sheader = body?.selectFirst("div.sheader")
|
||||
|
@ -80,21 +81,43 @@ class PinoyMoviesHub : MainAPI() {
|
|||
val descript = body?.selectFirst("div#info div.wp-content")?.text()
|
||||
val year = body?.selectFirst("span.date")?.text()?.trim()?.takeLast(4)?.toIntOrNull()
|
||||
|
||||
//TODO: Parse episodes
|
||||
val episodes = body?.select("div.page-content-listing.single-page")
|
||||
?.first()?.select("li")
|
||||
val episodeList = episodes?.mapNotNull {
|
||||
val innerA = it?.selectFirst("a") ?: return@mapNotNull null
|
||||
val eplink = innerA.attr("href") ?: return@mapNotNull null
|
||||
val epCount = innerA.text().trim().filter { a -> a.isDigit() }.toIntOrNull()
|
||||
val imageEl = innerA.selectFirst("img")
|
||||
val epPoster = imageEl?.attr("src") ?: imageEl?.attr("data-src")
|
||||
Episode(
|
||||
name = innerA.text(),
|
||||
data = eplink,
|
||||
posterUrl = epPoster,
|
||||
episode = epCount,
|
||||
)
|
||||
//Parse episodes
|
||||
val episodeList = body?.selectFirst("div#episodes")
|
||||
?.select("li")
|
||||
?.mapNotNull {
|
||||
var epCount: Int? = null
|
||||
var seasCount: Int? = null
|
||||
val divEp = it?.selectFirst("div.episodiotitle") ?: return@mapNotNull null
|
||||
val firstA = divEp.selectFirst("a")
|
||||
|
||||
it.selectFirst("div.numerando")?.text()
|
||||
?.split("-")?.mapNotNull { seasonEps ->
|
||||
seasonEps.trim().toIntOrNull()
|
||||
}?.let { divEpSeason ->
|
||||
if (divEpSeason.isNotEmpty()) {
|
||||
if (divEpSeason.size > 1) {
|
||||
epCount = divEpSeason[0]
|
||||
seasCount = divEpSeason[1]
|
||||
} else {
|
||||
epCount = divEpSeason[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val eplink = firstA?.attr("href") ?: return@mapNotNull null
|
||||
val imageEl = it.selectFirst("img")
|
||||
val epPoster = imageEl?.attr("src") ?: imageEl?.attr("data-src")
|
||||
val date = it.selectFirst("span.date")?.text()
|
||||
|
||||
val ep = Episode(
|
||||
name = firstA.text(),
|
||||
data = eplink,
|
||||
posterUrl = epPoster,
|
||||
episode = epCount,
|
||||
season = seasCount,
|
||||
)
|
||||
ep.addDate(parseDateFromString(date))
|
||||
ep
|
||||
} ?: listOf()
|
||||
|
||||
val dataUrl = doc.selectFirst("link[rel='shortlink']")
|
||||
|
@ -102,6 +125,19 @@ class PinoyMoviesHub : MainAPI() {
|
|||
?.substringAfter("?p=") ?: ""
|
||||
//Log.i(TAG, "Result => (dataUrl) ${dataUrl}")
|
||||
|
||||
if (episodeList.isNotEmpty()) {
|
||||
return TvSeriesLoadResponse(
|
||||
name = title,
|
||||
url = url,
|
||||
apiName = this.name,
|
||||
type = TvType.TvSeries,
|
||||
posterUrl = poster,
|
||||
year = year,
|
||||
plot = descript,
|
||||
episodes = episodeList
|
||||
)
|
||||
}
|
||||
|
||||
//Log.i(TAG, "Result => (id) ${id}")
|
||||
return MovieLoadResponse(
|
||||
name = title,
|
||||
|
@ -166,7 +202,10 @@ class PinoyMoviesHub : MainAPI() {
|
|||
val link = fixUrlNull(firstA?.attr("href")) ?: return@mapNotNull null
|
||||
val qualString = divPoster?.select("span.quality")?.text()?.trim() ?: ""
|
||||
val qual = getQualityFromString(qualString)
|
||||
val tvtype = if (qualString.equals("TV")) { TvType.TvSeries } else { TvType.Movie }
|
||||
var tvtype = if (qualString.equals("TV")) { TvType.TvSeries } else { TvType.Movie }
|
||||
if (link.replace("$mainUrl/", "").startsWith("tvshow")) {
|
||||
tvtype = TvType.TvSeries
|
||||
}
|
||||
|
||||
val name = divData?.selectFirst("a")?.text() ?: ""
|
||||
val year = divData?.selectFirst("span")?.text()
|
||||
|
@ -203,6 +242,57 @@ class PinoyMoviesHub : MainAPI() {
|
|||
} ?: listOf()
|
||||
}
|
||||
|
||||
private fun parseDateFromString(text: String?): String? {
|
||||
if (text.isNullOrBlank()) {
|
||||
return null
|
||||
}
|
||||
var day = ""
|
||||
var month = ""
|
||||
var year = ""
|
||||
val dateSplit = text.split(".")
|
||||
if (dateSplit.isNotEmpty()) {
|
||||
if (dateSplit.size > 1) {
|
||||
val yearday = dateSplit[1].trim()
|
||||
year = yearday.takeLast(4)
|
||||
day = yearday.trim().trim(',')
|
||||
|
||||
month = with (dateSplit[0].lowercase()) {
|
||||
when {
|
||||
startsWith("jan") -> "01"
|
||||
startsWith("feb") -> "02"
|
||||
startsWith("mar") -> "03"
|
||||
startsWith("apr") -> "04"
|
||||
startsWith("may") -> "05"
|
||||
startsWith("jun") -> "06"
|
||||
startsWith("jul") -> "07"
|
||||
startsWith("aug") -> "08"
|
||||
startsWith("sep") -> "09"
|
||||
startsWith("oct") -> "10"
|
||||
startsWith("nov") -> "11"
|
||||
startsWith("dec") -> "12"
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
year = dateSplit[0].trim().takeLast(4)
|
||||
}
|
||||
}
|
||||
if (day.isBlank()) {
|
||||
day = "01"
|
||||
}
|
||||
if (month.isBlank()) {
|
||||
month = "01"
|
||||
}
|
||||
if (year.isBlank()) {
|
||||
year = if (Build.VERSION.SDK_INT >= 26) {
|
||||
LocalDateTime.now().year.toString()
|
||||
} else {
|
||||
"0001"
|
||||
}
|
||||
}
|
||||
return "$year-$month-$day"
|
||||
}
|
||||
|
||||
private data class Response(
|
||||
@JsonProperty("embed_url") val embed_url: String?
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue