Fixes to pornhub

This commit is contained in:
KillerDogeEmpire 2024-02-12 17:27:17 -08:00
parent 8d30295490
commit 56e5460ced
2 changed files with 98 additions and 123 deletions

View file

@ -1,12 +1,12 @@
// use an integer for version numbers // use an integer for version numbers
version = 5 version = 6
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 = "Cornhub" description = "Cornhub"
authors = listOf("Stormunblessed", "Jace") authors = listOf("Stormunblessed", "Jace", "KillerDogeEmpire")
/** /**
* Status int as the following: * Status int as the following:

View file

@ -1,142 +1,117 @@
package com.jacekun package com.jacekun
import com.lagradost.cloudstream3.MainAPI import android.util.Log
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.network.WebViewResolver
import com.lagradost.cloudstream3.utils.*
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addActors
class Pornhub : MainAPI() { class PornHub : MainAPI() {
private val globalTvType = TvType.NSFW
override var mainUrl = "https://www.pornhub.com" override var mainUrl = "https://www.pornhub.com"
override var name = "Pornhub" override var name = "PornHub"
override val hasMainPage = true override val hasMainPage = true
override val hasChromecastSupport = true override var lang = "en"
override val hasQuickSearch = false
override val hasDownloadSupport = true override val hasDownloadSupport = true
override val vpnStatus = VPNStatus.MightBeNeeded //Cause it's a big site override val hasChromecastSupport = true
override val supportedTypes = setOf(TvType.NSFW) override val supportedTypes = setOf(TvType.NSFW)
override val vpnStatus = VPNStatus.MightBeNeeded
override val mainPage = mainPageOf( override val mainPage = mainPageOf(
"$mainUrl/video?page=" to "Main Page", "${mainUrl}/video?o=mr&hd=1&page=" to "Recently Featured",
"${mainUrl}/video?o=tr&t=w&hd=1&page=" to "Top Rated",
"${mainUrl}/video?o=mv&t=w&hd=1&page=" to "Most Viewed",
"${mainUrl}/video?o=ht&t=w&hd=1&page=" to "Hottest",
"${mainUrl}/video?p=professional&hd=1&page=" to "Professional",
"${mainUrl}/video?o=lg&hd=1&page=" to "Longest",
"${mainUrl}/video?p=homemade&hd=1&page=" to "Homemade",
"${mainUrl}/video?o=cm&t=w&hd=1&page=" to "Newest",
) )
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
try { val document = app.get(request.data + page).document
val categoryData = request.data val home = document.select("li.pcVideoListItem").mapNotNull { it.toSearchResult() }
val categoryName = request.name
val pagedLink = if (page > 0) categoryData + page else categoryData
val soup = app.get(pagedLink).document
val home = soup.select("div.sectionWrapper div.wrap").mapNotNull {
if (it == null) { return@mapNotNull null }
val title = it.selectFirst("span.title a")?.text() ?: ""
val link = fixUrlNull(it.selectFirst("a")?.attr("href")) ?: return@mapNotNull null
val img = fetchImgUrl(it.selectFirst("img"))
MovieSearchResponse(
name = title,
url = link,
apiName = this.name,
type = globalTvType,
posterUrl = img
)
}
if (home.isNotEmpty()) {
return newHomePageResponse( return newHomePageResponse(
list = HomePageList( list = HomePageList(
name = categoryName, name = request.name,
list = home, list = home,
isHorizontalImages = true isHorizontalImages = true
), ),
hasNext = true hasNext = true
) )
} else {
throw ErrorLoadingException("No homepage data found!")
} }
} catch (e: Exception) {
//e.printStackTrace() private fun Element.toSearchResult(): SearchResponse? {
logError(e) val title = this.selectFirst("a")?.attr("title") ?: return null
} val link = this.selectFirst("a")?.attr("href") ?: return null
throw ErrorLoadingException() val posterUrl = fixUrlNull(this.selectFirst("img.thumb")?.attr("src"))
return newMovieSearchResponse(title, link, TvType.Movie) { this.posterUrl = posterUrl }
} }
override suspend fun search(query: String): List<SearchResponse> { override suspend fun search(query: String): List<SearchResponse> {
val url = "$mainUrl/video/search?search=${query}" val document = app.get("${mainUrl}/video/search?search=${query}").document
val document = app.get(url).document
return document.select("div.sectionWrapper div.wrap").mapNotNull { return document.select("li.pcVideoListItem").mapNotNull { it.toSearchResult() }
if (it == null) { return@mapNotNull null }
val title = it.selectFirst("span.title a")?.text() ?: return@mapNotNull null
val link = fixUrlNull(it.selectFirst("a")?.attr("href")) ?: return@mapNotNull null
val image = fetchImgUrl(it.selectFirst("img"))
MovieSearchResponse(
name = title,
url = link,
apiName = this.name,
type = globalTvType,
posterUrl = image
)
}.distinctBy { it.url }
} }
override suspend fun load(url: String): LoadResponse { override suspend fun quickSearch(query: String): List<SearchResponse> = search(query)
val soup = app.get(url).document
val title = soup.selectFirst(".title span")?.text() ?: "" override suspend fun load(url: String): LoadResponse? {
val poster: String? = soup.selectFirst("div.video-wrapper .mainPlayerDiv img")?.attr("src") ?: val document = app.get(url).document
soup.selectFirst("head meta[property=og:image]")?.attr("content")
val tags = soup.select("div.categoriesWrapper a") val title = document.selectFirst("h1.title span[class='inlineFree']")?.text()?.trim() ?: return null
.map { it?.text()?.trim().toString().replace(", ","") } val description = title
return MovieLoadResponse( val poster = fixUrlNull(document.selectFirst("div.mainPlayerDiv img")?.attr("src"))
name = title, val year = Regex("""uploadDate\": \"(\d+)""").find(document.html())?.groupValues?.get(1)?.toIntOrNull()
url = url, val tags = document.select("div.categoriesWrapper a[data-label='Category']").map { it?.text()?.trim().toString().replace(", ","") }
apiName = this.name, val rating = document.selectFirst("span.percent")?.text()?.first()?.toString()?.toRatingInt()
type = globalTvType, val duration = Regex("duration' : '(.*)',").find(document.html())?.groupValues?.get(1)?.toIntOrNull()
dataUrl = url, val actors = document.select("div.pornstarsWrapper a[data-label='Pornstar']").mapNotNull {
posterUrl = poster, Actor(it.text().trim(), it.select("img").attr("src"))
tags = tags,
plot = title
)
} }
override suspend fun loadLinks(
data: String, val recommendations = document.selectXpath("//a[contains(@class, 'img')]").mapNotNull {
isCasting: Boolean, val recName = it?.attr("title")?.trim() ?: return@mapNotNull null
subtitleCallback: (SubtitleFile) -> Unit, val recHref = fixUrlNull(it.attr("href")) ?: return@mapNotNull null
callback: (ExtractorLink) -> Unit val recPosterUrl = fixUrlNull(it.selectFirst("img")?.attr("src"))
): Boolean { newMovieSearchResponse(recName, recHref, TvType.NSFW) {
app.get( this.posterUrl = recPosterUrl
url = data, }
interceptor = WebViewResolver( }
Regex("(master\\.m3u8\\?.*)")
) return newMovieLoadResponse(title, url, TvType.NSFW, url) {
).let { response -> this.posterUrl = poster
M3u8Helper().m3u8Generation( this.year = year
M3u8Helper.M3u8Stream( this.plot = description
response.url, this.tags = tags
headers = response.headers.toMap() this.rating = rating
), true this.duration = duration
).apmap { stream -> this.recommendations = recommendations
callback( addActors(actors)
}
}
override suspend fun loadLinks(data: String, isCasting: Boolean, subtitleCallback: (SubtitleFile) -> Unit, callback: (ExtractorLink) -> Unit): Boolean {
Log.d("PHub", "url » ${data}")
val source = app.get(data).text
val extracted_value = Regex("""([^\"]*master.m3u8?.[^\"]*)""").find(source)?.groups?.last()?.value ?: return false
val m3u_link = extracted_value.replace("\\", "")
Log.d("PHub", "extracted_value » ${extracted_value}")
Log.d("PHub", "m3u_link » ${m3u_link}")
callback.invoke(
ExtractorLink( ExtractorLink(
source = name, source = this.name,
name = "${this.name} m3u8", name = this.name,
url = stream.streamUrl, url = m3u_link,
referer = mainUrl, referer = "${mainUrl}/",
quality = getQualityFromName(stream.quality?.toString()), quality = Qualities.Unknown.value,
isM3u8 = true isM3u8 = true
) )
) )
}
}
return true return true
} }
private fun fetchImgUrl(imgsrc: Element?): String? {
return try { imgsrc?.attr("data-src")
?: imgsrc?.attr("data-mediabook")
?: imgsrc?.attr("alt")
?: imgsrc?.attr("data-mediumthumb")
?: imgsrc?.attr("data-thumb_url")
?: imgsrc?.attr("src")
} catch (e:Exception) { null }
}
} }