mirror of
https://github.com/recloudstream/cloudstream-extensions-multilingual.git
synced 2024-08-15 03:15:14 +00:00
Parse episode list and date
This commit is contained in:
parent
e52b320927
commit
e8f63f1fdc
1 changed files with 108 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
||||||
package com.lagradost
|
package com.lagradost
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.lagradost.cloudstream3.*
|
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.ExtractorLink
|
||||||
import com.lagradost.cloudstream3.utils.loadExtractor
|
import com.lagradost.cloudstream3.utils.loadExtractor
|
||||||
import org.jsoup.select.Elements
|
import org.jsoup.select.Elements
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
class PinoyMoviesHub : MainAPI() {
|
class PinoyMoviesHub : MainAPI() {
|
||||||
//private val TAG = "Dev"
|
//private val TAG = "Dev"
|
||||||
|
@ -64,8 +66,7 @@ class PinoyMoviesHub : MainAPI() {
|
||||||
.getResults(this.name)
|
.getResults(this.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun load(url: String): MovieLoadResponse {
|
override suspend fun load(url: String): LoadResponse {
|
||||||
//TODO: Load polishing
|
|
||||||
val doc = app.get(url).document
|
val doc = app.get(url).document
|
||||||
val body = doc.getElementsByTag("body").firstOrNull()
|
val body = doc.getElementsByTag("body").firstOrNull()
|
||||||
val sheader = body?.selectFirst("div.sheader")
|
val sheader = body?.selectFirst("div.sheader")
|
||||||
|
@ -80,21 +81,43 @@ class PinoyMoviesHub : MainAPI() {
|
||||||
val descript = body?.selectFirst("div#info div.wp-content")?.text()
|
val descript = body?.selectFirst("div#info div.wp-content")?.text()
|
||||||
val year = body?.selectFirst("span.date")?.text()?.trim()?.takeLast(4)?.toIntOrNull()
|
val year = body?.selectFirst("span.date")?.text()?.trim()?.takeLast(4)?.toIntOrNull()
|
||||||
|
|
||||||
//TODO: Parse episodes
|
//Parse episodes
|
||||||
val episodes = body?.select("div.page-content-listing.single-page")
|
val episodeList = body?.selectFirst("div#episodes")
|
||||||
?.first()?.select("li")
|
?.select("li")
|
||||||
val episodeList = episodes?.mapNotNull {
|
?.mapNotNull {
|
||||||
val innerA = it?.selectFirst("a") ?: return@mapNotNull null
|
var epCount: Int? = null
|
||||||
val eplink = innerA.attr("href") ?: return@mapNotNull null
|
var seasCount: Int? = null
|
||||||
val epCount = innerA.text().trim().filter { a -> a.isDigit() }.toIntOrNull()
|
val divEp = it?.selectFirst("div.episodiotitle") ?: return@mapNotNull null
|
||||||
val imageEl = innerA.selectFirst("img")
|
val firstA = divEp.selectFirst("a")
|
||||||
val epPoster = imageEl?.attr("src") ?: imageEl?.attr("data-src")
|
|
||||||
Episode(
|
it.selectFirst("div.numerando")?.text()
|
||||||
name = innerA.text(),
|
?.split("-")?.mapNotNull { seasonEps ->
|
||||||
data = eplink,
|
seasonEps.trim().toIntOrNull()
|
||||||
posterUrl = epPoster,
|
}?.let { divEpSeason ->
|
||||||
episode = epCount,
|
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()
|
} ?: listOf()
|
||||||
|
|
||||||
val dataUrl = doc.selectFirst("link[rel='shortlink']")
|
val dataUrl = doc.selectFirst("link[rel='shortlink']")
|
||||||
|
@ -102,6 +125,19 @@ class PinoyMoviesHub : MainAPI() {
|
||||||
?.substringAfter("?p=") ?: ""
|
?.substringAfter("?p=") ?: ""
|
||||||
//Log.i(TAG, "Result => (dataUrl) ${dataUrl}")
|
//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}")
|
//Log.i(TAG, "Result => (id) ${id}")
|
||||||
return MovieLoadResponse(
|
return MovieLoadResponse(
|
||||||
name = title,
|
name = title,
|
||||||
|
@ -166,7 +202,10 @@ class PinoyMoviesHub : MainAPI() {
|
||||||
val link = fixUrlNull(firstA?.attr("href")) ?: return@mapNotNull null
|
val link = fixUrlNull(firstA?.attr("href")) ?: return@mapNotNull null
|
||||||
val qualString = divPoster?.select("span.quality")?.text()?.trim() ?: ""
|
val qualString = divPoster?.select("span.quality")?.text()?.trim() ?: ""
|
||||||
val qual = getQualityFromString(qualString)
|
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 name = divData?.selectFirst("a")?.text() ?: ""
|
||||||
val year = divData?.selectFirst("span")?.text()
|
val year = divData?.selectFirst("span")?.text()
|
||||||
|
@ -203,6 +242,57 @@ class PinoyMoviesHub : MainAPI() {
|
||||||
} ?: listOf()
|
} ?: 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(
|
private data class Response(
|
||||||
@JsonProperty("embed_url") val embed_url: String?
|
@JsonProperty("embed_url") val embed_url: String?
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue