Applied PR suggestions.

- Fetch movie Id from episode link on loadLinks
This commit is contained in:
Jace 2022-10-08 16:12:16 +08:00
parent e8f63f1fdc
commit b6b0d0623d

View file

@ -1,14 +1,14 @@
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.*
import com.lagradost.cloudstream3.utils.AppUtils 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.nodes.Document
import org.jsoup.select.Elements import org.jsoup.select.Elements
import java.time.LocalDateTime import java.util.Calendar
class PinoyMoviesHub : MainAPI() { class PinoyMoviesHub : MainAPI() {
//private val TAG = "Dev" //private val TAG = "Dev"
@ -67,6 +67,7 @@ class PinoyMoviesHub : MainAPI() {
} }
override suspend fun load(url: String): LoadResponse { override suspend fun load(url: String): LoadResponse {
val apiName = this.name
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")
@ -109,46 +110,45 @@ class PinoyMoviesHub : MainAPI() {
val epPoster = imageEl?.attr("src") ?: imageEl?.attr("data-src") val epPoster = imageEl?.attr("src") ?: imageEl?.attr("data-src")
val date = it.selectFirst("span.date")?.text() val date = it.selectFirst("span.date")?.text()
val ep = Episode( newEpisode(
name = firstA.text(), data = eplink
data = eplink, ) {
posterUrl = epPoster, this.name = firstA.text()
episode = epCount, this.posterUrl = epPoster
season = seasCount, this.episode = epCount
) this.season = seasCount
ep.addDate(parseDateFromString(date)) this.addDate(parseDateFromString(date))
ep }
} ?: listOf() } ?: emptyList()
val dataUrl = doc.selectFirst("link[rel='shortlink']") val dataUrl = doc.getMovieId() ?: throw Exception("Movie Id is Null!")
?.attr("href")
?.substringAfter("?p=") ?: ""
//Log.i(TAG, "Result => (dataUrl) ${dataUrl}")
if (episodeList.isNotEmpty()) { if (episodeList.isNotEmpty()) {
return TvSeriesLoadResponse( return newTvSeriesLoadResponse(
name = title, name = title,
url = url, url = url,
apiName = this.name,
type = TvType.TvSeries, type = TvType.TvSeries,
posterUrl = poster,
year = year,
plot = descript,
episodes = episodeList episodes = episodeList
) ) {
this.apiName = apiName
this.posterUrl = poster
this.year = year
this.plot = descript
}
} }
//Log.i(TAG, "Result => (id) ${id}") //Log.i(TAG, "Result => (id) ${id}")
return MovieLoadResponse( return newMovieLoadResponse(
name = title, name = title,
url = url, url = url,
dataUrl = dataUrl, dataUrl = dataUrl,
apiName = this.name,
type = TvType.Movie, type = TvType.Movie,
posterUrl = poster, ) {
year = year, this.apiName = apiName
plot = descript, this.posterUrl = poster
) this.year = year
this.plot = descript
}
} }
override suspend fun loadLinks( override suspend fun loadLinks(
@ -158,11 +158,18 @@ class PinoyMoviesHub : MainAPI() {
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
): Boolean { ): Boolean {
//Log.i(TAG, "Loading ajax request..") var movieId = data
//If episode link, fetch movie id first
if (movieId.startsWith(mainUrl)) {
movieId = app.get(data).document.getMovieId() ?: throw Exception("Movie Id is Null!")
}
val requestLink = "${mainUrl}/wp-admin/admin-ajax.php" val requestLink = "${mainUrl}/wp-admin/admin-ajax.php"
val action = "doo_player_ajax" val action = "doo_player_ajax"
val nume = "1" val nume = "1"
val type = "movie" val type = "movie"
//Log.i(TAG, "Loading ajax request..")
val doc = app.post( val doc = app.post(
url = requestLink, url = requestLink,
referer = mainUrl, referer = mainUrl,
@ -172,14 +179,13 @@ class PinoyMoviesHub : MainAPI() {
), ),
data = mapOf( data = mapOf(
Pair("action", action), Pair("action", action),
Pair("post", data), Pair("post", movieId),
Pair("nume", nume), Pair("nume", nume),
Pair("type", type) Pair("type", type)
) )
) )
//Log.i(TAG, "Response (${doc.code}) => ${doc.text}") //Log.i(TAG, "Response (${doc.code}) => ${doc.text}")
AppUtils.tryParseJson<Response?>(doc.text)?.let { AppUtils.tryParseJson<Response?>(doc.text)?.embed_url?.let { streamLink ->
val streamLink = it.embed_url ?: ""
//Log.i(TAG, "Response (streamLink) => ${streamLink}") //Log.i(TAG, "Response (streamLink) => ${streamLink}")
if (streamLink.isNotBlank()) { if (streamLink.isNotBlank()) {
loadExtractor( loadExtractor(
@ -188,9 +194,16 @@ class PinoyMoviesHub : MainAPI() {
callback = callback, callback = callback,
subtitleCallback = subtitleCallback subtitleCallback = subtitleCallback
) )
return true
} }
} }
return true return false
}
private fun Document.getMovieId(): String? {
return this.selectFirst("link[rel='shortlink']")
?.attr("href")
?.substringAfter("?p=")
} }
private fun Elements?.getResults(apiName: String): List<SearchResponse> { private fun Elements?.getResults(apiName: String): List<SearchResponse> {
@ -284,11 +297,7 @@ class PinoyMoviesHub : MainAPI() {
month = "01" month = "01"
} }
if (year.isBlank()) { if (year.isBlank()) {
year = if (Build.VERSION.SDK_INT >= 26) { year = Calendar.getInstance().get(Calendar.YEAR).toString()
LocalDateTime.now().year.toString()
} else {
"0001"
}
} }
return "$year-$month-$day" return "$year-$month-$day"
} }