small fixes

This commit is contained in:
LagradOst 2023-02-01 23:28:36 +00:00 committed by GitHub
parent baea5409f1
commit 55856dbcd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,7 +19,8 @@ class StreamingcommunityProvider: MainAPI() {
TvType.Movie, TvType.Movie,
TvType.TvSeries, TvType.TvSeries,
) )
private val userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" private val userAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
val webpage = app.get(mainUrl, headers = mapOf("user-agent" to userAgent)) val webpage = app.get(mainUrl, headers = mapOf("user-agent" to userAgent))
@ -44,67 +45,63 @@ class StreamingcommunityProvider: MainAPI() {
val document = app.get(url, headers = mapOf("user-agent" to userAgent)).document val document = app.get(url, headers = mapOf("user-agent" to userAgent)).document
val films = val films =
document.selectFirst("the-search-page")!!.attr("records-json").replace(""", """"""") document.selectFirst("the-search-page")!!.attr("records-json")
.replace(""", """"""")
val searchResults = parseJson<List<VideoElement>>(films) val searchResults = parseJson<List<VideoElement>>(films)
return searchResults.apmap { result -> return searchResults.apmap { result ->
result.toSearchResponse() result.toSearchResponse()
} }
} }
override suspend fun load(url: String): LoadResponse { override suspend fun load(url: String): LoadResponse {
val document = app.get(url, headers = mapOf("user-agent" to userAgent)).document val document = app.get(url, headers = mapOf("user-agent" to userAgent)).document
val poster = Regex("url\\('(.*)'").find(document.selectFirst("div.title-wrap")?.attributes() val poster = Regex("url\\('(.*)'").find(
?.get("style") ?: "")?.groupValues?.last() //posterMap[url] document.selectFirst("div.title-wrap")?.attributes()
?.get("style") ?: ""
)?.groupValues?.lastOrNull() //posterMap[url]
val id = url.substringBefore("-").filter { it.isDigit() } val id = url.substringBefore("-").filter { it.isDigit() }
val data = app.post("$mainUrl/api/titles/preview/$id", referer = mainUrl, headers = mapOf("user-agent" to userAgent)).text val datajs = app.post(
"$mainUrl/api/titles/preview/$id",
referer = mainUrl,
headers = mapOf("user-agent" to userAgent)
).parsed<Moviedata>()
val datajs = parseJson<Moviedata>(data) val type = if (datajs.type == "movie") {
val type: TvType = if (datajs.type == "movie") {
TvType.Movie TvType.Movie
} else { } else {
TvType.TvSeries TvType.TvSeries
} }
val trailerInfoJs = document.select("slider-trailer").attr("videos") val trailerInfoJs = document.select("slider-trailer").attr("videos")
val trailerInfo = parseJson<List<TrailerElement>>(trailerInfoJs) val trailerInfo = parseJson<List<TrailerElement>>(trailerInfoJs)
val trailerUrl: String? = if (trailerInfo.isNotEmpty()) { val trailerUrl = trailerInfo.firstOrNull()?.url?.let { code ->
"https://www.youtube.com/watch?v=${trailerInfo[0].url}" "https://www.youtube.com/watch?v=$code"
} else {
null
} }
val year = datajs.releaseDate.substringBefore("-") val year = datajs.releaseDate.substringBefore("-")
val correlates = document.selectFirst("slider-title")!!.attr("titles-json") val correlates = document.selectFirst("slider-title")!!.attr("titles-json")
val correlatesData = parseJson<List<VideoElement>>(correlates) val correlatesData = parseJson<List<VideoElement>>(correlates)
val number : Int = if (correlatesData.size<=15) {correlatesData.size} else correlatesData.size-15 // Max size 15 to prevent network spam
val size = minOf(correlatesData.size, 15)
val correlatesList =correlatesData.take(number).apmap { val correlatesList = correlatesData.take(size).apmap {
it.toSearchResponse() it.toSearchResponse()
} }
if (type == TvType.TvSeries) { if (type == TvType.TvSeries) {
val name = datajs.name val name = datajs.name
val episodeList = arrayListOf<Episode>()
val episodes = val episodes =
Html.fromHtml(document.selectFirst("season-select")!!.attr("seasons")).toString() Html.fromHtml(document.selectFirst("season-select")!!.attr("seasons")).toString()
val jsonEpisodes = parseJson<List<Season>>(episodes) val jsonEpisodes = parseJson<List<Season>>(episodes)
jsonEpisodes.map { seasons -> val episodeList = jsonEpisodes.map { seasons ->
val season = seasons.number.toInt() val season = seasons.number.toInt()
val sid = seasons.title_id val sid = seasons.title_id
val episode = seasons.episodes seasons.episodes.map { ep ->
episode.map { ep ->
val href = "$mainUrl/watch/$sid?e=${ep.id}" val href = "$mainUrl/watch/$sid?e=${ep.id}"
val postImage = if (ep.images.isNotEmpty()) { val postImage = ep.images.firstOrNull()?.originalURL
ep.images.first().originalURL
} else {
""
}
episodeList.add(
newEpisode(href) { newEpisode(href) {
this.name = ep.name this.name = ep.name
@ -113,10 +110,8 @@ class StreamingcommunityProvider: MainAPI() {
this.description = ep.plot this.description = ep.plot
this.posterUrl = postImage this.posterUrl = postImage
} }
)
} }
} }.flatten()
if (episodeList.isEmpty()) throw ErrorLoadingException("No Seasons Found") if (episodeList.isEmpty()) throw ErrorLoadingException("No Seasons Found")
@ -130,10 +125,7 @@ class StreamingcommunityProvider: MainAPI() {
addTrailer(trailerUrl) addTrailer(trailerUrl)
this.recommendations = correlatesList this.recommendations = correlatesList
} }
} else { } else {
return newMovieLoadResponse( return newMovieLoadResponse(
document.selectFirst("div > div > h1")!!.text(), document.selectFirst("div > div > h1")!!.text(),
document.select("a.play-hitzone").attr("href"), document.select("a.play-hitzone").attr("href"),
@ -149,7 +141,6 @@ class StreamingcommunityProvider: MainAPI() {
addTrailer(trailerUrl) addTrailer(trailerUrl)
this.recommendations = correlatesList this.recommendations = correlatesList
} }
} }
} }
@ -195,9 +186,13 @@ class StreamingcommunityProvider: MainAPI() {
val posterUrl = "https://$ip/images/$number/$img" val posterUrl = "https://$ip/images/$number/$img"
val videoUrl = "$mainUrl/titles/$id-$name" val videoUrl = "$mainUrl/titles/$id-$name"
//posterMap[videourl] = posterurl //posterMap[videourl] = posterurl
val data = app.post("$mainUrl/api/titles/preview/$id", referer = mainUrl, headers = mapOf("user-agent" to userAgent)).text val data = app.post(
"$mainUrl/api/titles/preview/$id",
referer = mainUrl,
headers = mapOf("user-agent" to userAgent)
).text
val datajs = parseJson<Moviedata>(data) val datajs = parseJson<Moviedata>(data)
val type: TvType = if (datajs.type == "movie") { val type = if (datajs.type == "movie") {
TvType.Movie TvType.Movie
} else { } else {
TvType.TvSeries TvType.TvSeries
@ -254,25 +249,30 @@ data class Moviedata(
@JsonProperty("votes") val votes: List<Vote>, @JsonProperty("votes") val votes: List<Vote>,
@JsonProperty("runtime") val runtime: Long? = null @JsonProperty("runtime") val runtime: Long? = null
) )
data class Genre( data class Genre(
@JsonProperty("name") val name: String, @JsonProperty("name") val name: String,
@JsonProperty("pivot") val pivot: Pivot, @JsonProperty("pivot") val pivot: Pivot,
) )
data class Pivot( data class Pivot(
@JsonProperty("titleID") val titleID: Long, @JsonProperty("titleID") val titleID: Long,
@JsonProperty("genreID") val genreID: Long, @JsonProperty("genreID") val genreID: Long,
) )
data class Vote( data class Vote(
@JsonProperty("title_id") val title_id: Long, @JsonProperty("title_id") val title_id: Long,
@JsonProperty("average") val average: String, @JsonProperty("average") val average: String,
@JsonProperty("count") val count: Long, @JsonProperty("count") val count: Long,
@JsonProperty("type") val type: String, @JsonProperty("type") val type: String,
) )
data class VideoElement( data class VideoElement(
@JsonProperty("id") val id: Long, @JsonProperty("id") val id: Long,
@JsonProperty("slug") val slug: String, @JsonProperty("slug") val slug: String,
@JsonProperty("images") val images: List<Image>, @JsonProperty("images") val images: List<Image>,
) )
data class Image( data class Image(
@JsonProperty("imageable_id") val imageableID: Long, @JsonProperty("imageable_id") val imageableID: Long,
@JsonProperty("imageable_type") val imageableType: String, @JsonProperty("imageable_type") val imageableType: String,
@ -311,6 +311,7 @@ data class Season(
@JsonProperty("updated_at") val updatedAt: String? = "", @JsonProperty("updated_at") val updatedAt: String? = "",
@JsonProperty("episodes") val episodes: List<Episodejson> @JsonProperty("episodes") val episodes: List<Episodejson>
) )
data class Episodejson( data class Episodejson(
@JsonProperty("id") val id: Long, @JsonProperty("id") val id: Long,
@JsonProperty("number") val number: Long, @JsonProperty("number") val number: Long,
@ -319,6 +320,7 @@ data class Episodejson(
@JsonProperty("season_id") val seasonID: Long, @JsonProperty("season_id") val seasonID: Long,
@JsonProperty("images") val images: List<ImageSeason> @JsonProperty("images") val images: List<ImageSeason>
) )
data class ImageSeason( data class ImageSeason(
@JsonProperty("imageable_id") val imageableID: Long, @JsonProperty("imageable_id") val imageableID: Long,
@JsonProperty("imageable_type") val imageableType: String, @JsonProperty("imageable_type") val imageableType: String,
@ -328,6 +330,7 @@ data class ImageSeason(
@JsonProperty("type") val type: String, @JsonProperty("type") val type: String,
@JsonProperty("original_url") val originalURL: String @JsonProperty("original_url") val originalURL: String
) )
data class TrailerElement( data class TrailerElement(
@JsonProperty("id") val id: Long? = null, @JsonProperty("id") val id: Long? = null,
@JsonProperty("url") val url: String? = null, @JsonProperty("url") val url: String? = null,