mainApi changes

This commit is contained in:
LagradOst 2022-04-10 02:14:36 +02:00
parent 641025fa2d
commit f4d160f997
13 changed files with 94 additions and 65 deletions

View file

@ -698,25 +698,25 @@ data class TvSeriesSearchResponse(
) : SearchResponse
interface LoadResponse {
val name: String
val url: String
val apiName: String
val type: TvType
var name: String
var url: String
var apiName: String
var type: TvType
var posterUrl: String?
val year: Int?
var year: Int?
var plot: String?
var rating: Int? // 1-1000
var tags: List<String>?
var duration: Int? // in minutes
var trailerUrl: String?
var trailers: List<String>?
var recommendations: List<SearchResponse>?
var actors: List<ActorData>?
var comingSoon: Boolean
var syncData: MutableMap<String, String>
companion object {
val malIdPrefix = malApi.idPrefix
val aniListIdPrefix = aniListApi.idPrefix
private val malIdPrefix = malApi.idPrefix
private val aniListIdPrefix = aniListApi.idPrefix
@JvmName("addActorNames")
fun LoadResponse.addActors(actors: List<String>?) {
@ -750,6 +750,18 @@ interface LoadResponse {
addImdbId(imdbUrlToIdNullable(url))
}
/**better to set trailers directly instead of calling this multiple times*/
fun LoadResponse.addTrailer(trailerUrl: String?) {
if (trailerUrl == null) return
if (this.trailers == null) {
this.trailers = listOf(trailerUrl)
} else {
val update = this.trailers?.toMutableList()
update?.add(trailerUrl)
this.trailers = update
}
}
fun LoadResponse.addImdbId(id: String?) {
// TODO add imdb sync
}
@ -763,10 +775,21 @@ interface LoadResponse {
}
fun LoadResponse.addTMDbId(id: String?) {
// TODO add TMDb sync
}
fun LoadResponse.setDuration(input: String?) {
fun LoadResponse.addRating(text: String?) {
addRating(text.toRatingInt())
}
fun LoadResponse.addRating(value: Int?) {
if (value ?: return < 0 || value > 1000) {
return
}
this.rating = value
}
fun LoadResponse.addDuration(input: String?) {
val cleanInput = input?.trim()?.replace(" ", "") ?: return
Regex("([0-9]*)h.*?([0-9]*)m").find(cleanInput)?.groupValues?.let { values ->
if (values.size == 3) {
@ -816,7 +839,7 @@ data class TorrentLoadResponse(
override var rating: Int? = null,
override var tags: List<String>? = null,
override var duration: Int? = null,
override var trailerUrl: String? = null,
override var trailers: List<String>? = null,
override var recommendations: List<SearchResponse>? = null,
override var actors: List<ActorData>? = null,
override var comingSoon: Boolean = false,
@ -843,7 +866,7 @@ data class AnimeLoadResponse(
override var rating: Int? = null,
override var duration: Int? = null,
override var trailerUrl: String? = null,
override var trailers: List<String>? = null,
override var recommendations: List<SearchResponse>? = null,
override var actors: List<ActorData>? = null,
override var comingSoon: Boolean = false,
@ -898,7 +921,7 @@ data class MovieLoadResponse(
override var rating: Int? = null,
override var tags: List<String>? = null,
override var duration: Int? = null,
override var trailerUrl: String? = null,
override var trailers: List<String>? = null,
override var recommendations: List<SearchResponse>? = null,
override var actors: List<ActorData>? = null,
override var comingSoon: Boolean = false,
@ -912,6 +935,14 @@ fun <T> MainAPI.newMovieLoadResponse(
data: T?,
initializer: MovieLoadResponse.() -> Unit = { }
): MovieLoadResponse {
// just in case
if (data is String) return newMovieLoadResponse(
name,
url,
type,
dataUrl = data,
initializer = initializer
)
val dataUrl = data?.toJson() ?: ""
val builder = MovieLoadResponse(
name = name,
@ -955,9 +986,9 @@ data class Episode(
var date: Long? = null,
)
fun Episode.addDate(date: String?, fomat: String = "yyyy-MM-dd") {
fun Episode.addDate(date: String?, format: String = "yyyy-MM-dd") {
try {
this.date = SimpleDateFormat(fomat)?.parse(date ?: return)?.time
this.date = SimpleDateFormat(format)?.parse(date ?: return)?.time
} catch (e: Exception) {
logError(e)
}
@ -967,7 +998,7 @@ fun Episode.addDate(date: Date?) {
this.date = date?.time
}
fun <T> MainAPI.newEpisode(
fun MainAPI.newEpisode(
url: String,
initializer: Episode.() -> Unit = { },
fix: Boolean = true,
@ -983,6 +1014,11 @@ fun <T> MainAPI.newEpisode(
data: T,
initializer: Episode.() -> Unit = { }
): Episode {
if (data is String) return newEpisode(
url = data,
initializer = initializer
) // just in case java is wack
val builder = Episode(
data = data?.toJson() ?: throw ErrorLoadingException("invalid newEpisode")
)
@ -1005,7 +1041,7 @@ data class TvSeriesLoadResponse(
override var rating: Int? = null,
override var tags: List<String>? = null,
override var duration: Int? = null,
override var trailerUrl: String? = null,
override var trailers: List<String>? = null,
override var recommendations: List<SearchResponse>? = null,
override var actors: List<ActorData>? = null,
override var comingSoon: Boolean = false,
@ -1041,4 +1077,4 @@ fun fetchUrls(text: String?): List<String> {
}
fun String?.toRatingInt(): Int? =
this?.trim()?.toDoubleOrNull()?.absoluteValue?.times(1000f)?.toInt()
this?.replace(" ", "")?.trim()?.toDoubleOrNull()?.absoluteValue?.times(1000f)?.toInt()

View file

@ -5,6 +5,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.mvvm.suspendSafeApiCall
import com.lagradost.cloudstream3.network.AppResponse
import com.lagradost.cloudstream3.utils.ExtractorLink
@ -306,7 +307,7 @@ class AnimePaheProvider : MainAPI() {
addMalId(malId)
addAniListId(anilistId)
this.trailerUrl = trailer
addTrailer(trailer)
}
}
}

View file

@ -3,6 +3,8 @@ package com.lagradost.cloudstream3.animeproviders
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
import com.lagradost.cloudstream3.LoadResponse.Companion.addRating
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.Qualities
import org.json.JSONObject
@ -123,7 +125,7 @@ class AnimeWorldProvider : MainAPI() {
val type: TvType = getType(widget.select("dd").first()?.text())
val genres = widget.select(".meta").select("a[href*=\"/genre/\"]").map { it.text() }
val rating: Int? = widget.select("#average-vote").text().toFloatOrNull()?.times(1000)?.toInt()
val rating = widget.select("#average-vote")?.text()
val trailerUrl = document.select(".trailer[data-url]").attr("data-url")
val malId = document.select("#mal-button").attr("href")
@ -174,9 +176,9 @@ class AnimeWorldProvider : MainAPI() {
tags = genres
addMalId(malId)
addAniListId(anlId)
this.rating = rating
addRating(rating)
this.duration = duration
this.trailerUrl = trailerUrl
addTrailer(trailerUrl)
this.recommendations = recommendations
this.comingSoon = comingSoon
}

View file

@ -2,6 +2,7 @@ package com.lagradost.cloudstream3.metaproviders
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.syncproviders.OAuth2API
class MultiAnimeProvider : MainAPI() {
@ -36,7 +37,7 @@ class MultiAnimeProvider : MainAPI() {
plot = res.synopsis
tags = res.genres
rating = res.publicScore
trailerUrl = res.trailerUrl
addTrailer(res.trailerUrl)
addAniListId(res.id.toIntOrNull())
}
}

View file

@ -97,9 +97,7 @@ class AkwamProvider : MainAPI() {
val synopsis = doc.select("div.widget-body p:first-child").text()
val rating = doc.select("span.mx-2").text().split("/").lastOrNull()?.replace(" ", "")
?.toDoubleOrNull()
?.times(1000)?.toInt()
val rating = doc.select("span.mx-2").text().split("/").lastOrNull()?.toRatingInt()
val tags = doc.select("div.font-size-16.d-flex.align-items-center.mt-3 > a").map {
it.text()

View file

@ -1,7 +1,7 @@
package com.lagradost.cloudstream3.movieproviders
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.setDuration
import com.lagradost.cloudstream3.LoadResponse.Companion.addDuration
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.loadExtractor
@ -111,8 +111,7 @@ class AllMoviesForYouProvider : MainAPI() {
val title = document.selectFirst("h1.Title").text()
val descipt = document.selectFirst("div.Description > p").text()
val rating =
document.selectFirst("div.Vote > div.post-ratings > span")?.text()?.toFloatOrNull()
?.times(1000)?.toInt()
document.selectFirst("div.Vote > div.post-ratings > span")?.text()?.toRatingInt()
val year = document.selectFirst("span.Date")?.text()
val duration = document.selectFirst("span.Time").text()
val backgroundPoster =
@ -180,7 +179,7 @@ class AllMoviesForYouProvider : MainAPI() {
this.year = year?.toIntOrNull()
this.plot = descipt
this.rating = rating
setDuration(duration)
addDuration(duration)
}
}
}

View file

@ -265,8 +265,7 @@ open class BflixProvider() : MainAPI() {
year = null
)
}
val rating = soup.selectFirst(".info span.imdb").text().toFloatOrNull()
?.times(1000)?.toInt()
val rating = soup.selectFirst(".info span.imdb")?.text()?.toRatingInt()
val durationdoc = soup.selectFirst("div.info div.meta").toString()
val durationregex = Regex("((\\d+) min)")
val yearegex = Regex("<span>(\\d+)<\\/span>")

View file

@ -1,7 +1,7 @@
package com.lagradost.cloudstream3.movieproviders
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.setDuration
import com.lagradost.cloudstream3.LoadResponse.Companion.addDuration
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.loadExtractor
@ -175,7 +175,7 @@ class PelisflixProvider : MainAPI() {
this.year = year?.toIntOrNull()
this.plot = descipt
this.rating = rating
setDuration(duration)
addDuration(duration)
}
}
}

View file

@ -1,7 +1,7 @@
package com.lagradost.cloudstream3.movieproviders
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.setDuration
import com.lagradost.cloudstream3.LoadResponse.Companion.addDuration
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.loadExtractor
@ -92,8 +92,7 @@ class SeriesflixProvider : MainAPI() {
val descRegex = Regex("(Recuerda.*Seriesflix.)")
val descipt = document.selectFirst("div.Description > p").text().replace(descRegex, "")
val rating =
document.selectFirst("div.Vote > div.post-ratings > span")?.text()?.toFloatOrNull()
?.times(1000)?.toInt()
document.selectFirst("div.Vote > div.post-ratings > span")?.text()?.toRatingInt()
val year = document.selectFirst("span.Date")?.text()
// ?: does not work
val duration = try {
@ -172,7 +171,7 @@ class SeriesflixProvider : MainAPI() {
this.year = year?.toIntOrNull()
this.plot = descipt
this.rating = rating
setDuration(duration)
addDuration(duration)
}
}
}

View file

@ -6,7 +6,8 @@ import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.APIHolder.getCaptchaToken
import com.lagradost.cloudstream3.APIHolder.unixTimeMS
import com.lagradost.cloudstream3.LoadResponse.Companion.addActors
import com.lagradost.cloudstream3.LoadResponse.Companion.setDuration
import com.lagradost.cloudstream3.LoadResponse.Companion.addDuration
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.animeproviders.ZoroProvider
import com.lagradost.cloudstream3.mvvm.suspendSafeApiCall
import com.lagradost.cloudstream3.network.AppResponse
@ -217,12 +218,12 @@ open class SflixProvider : MainAPI() {
this.year = year
this.posterUrl = posterUrl
this.plot = plot
setDuration(duration)
addDuration(duration)
addActors(cast)
this.tags = tags
this.recommendations = recommendations
this.comingSoon = comingSoon
this.trailerUrl = youtubeTrailer
addTrailer(youtubeTrailer)
this.rating = rating
}
} else {
@ -273,11 +274,11 @@ open class SflixProvider : MainAPI() {
this.posterUrl = posterUrl
this.year = year
this.plot = plot
setDuration(duration)
addDuration(duration)
addActors(cast)
this.tags = tags
this.recommendations = recommendations
this.trailerUrl = youtubeTrailer
addTrailer(youtubeTrailer)
this.rating = rating
}
}

View file

@ -1,6 +1,8 @@
package com.lagradost.cloudstream3.movieproviders
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addRating
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.extractorApis
@ -61,33 +63,24 @@ class FrenchStreamProvider : MainAPI() {
val listEpisode = soup.select("div.elink")
if (isMovie) {
val trailer = soup.selectFirst("div.fleft > span > a")?.attr("href")
val date = soup.select("ul.flist-col > li")?.getOrNull(2)?.text()?.toIntOrNull()
val ratingAverage = soup.select("div.fr-count > div")?.text()?.toIntOrNull()
val tags = soup.select("ul.flist-col > li")?.getOrNull(1)
val tagsList = tags?.select("a")
?.mapNotNull { // all the tags like action, thriller ...; unused variable
it?.text()
}
return MovieLoadResponse(
title,
url,
this.name,
TvType.Movie,
url,
poster,
date,
description,
ratingAverage,
tagsList,
null,
trailer
)
return newMovieLoadResponse(title,url,TvType.Movie,url) {
this.posterUrl = poster
addRating(soup.select("div.fr-count > div")?.text())
this.year = soup.select("ul.flist-col > li")?.getOrNull(2)?.text()?.toIntOrNull()
this.tags = tagsList
this.plot = description
addTrailer(soup.selectFirst("div.fleft > span > a")?.attr("href"))
}
} else // a tv serie
{
//println(listEpisode)
//println("listeEpisode:")
val episode_list = if ("<a" !in (listEpisode[0]).toString()) { // check if VF is empty
val episodeList = if ("<a" !in (listEpisode[0]).toString()) { // check if VF is empty
listEpisode[1] // no vf, return vostfr
}
else {
@ -96,7 +89,7 @@ class FrenchStreamProvider : MainAPI() {
//println(url)
val episodes = episode_list.select("a").map { a ->
val episodes = episodeList.select("a").map { a ->
val epNum = a.text().split("Episode")[1].trim().toIntOrNull()
val epTitle = if (a.text()?.toString() != null)
if (a.text().contains("Episode")) {
@ -131,8 +124,6 @@ class FrenchStreamProvider : MainAPI() {
null,
description,
ShowStatus.Ongoing,
null,
null
)
}
}

View file

@ -10,6 +10,7 @@ import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
import com.lagradost.cloudstream3.APIHolder.getApiFromUrlNull
import com.lagradost.cloudstream3.APIHolder.getId
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.safeApiCall
import com.lagradost.cloudstream3.syncproviders.SyncAPI
@ -123,7 +124,7 @@ class ResultViewModel : ViewModel() {
rating = rating ?: meta.publicScore
tags = tags ?: meta.genres
plot = if (plot.isNullOrBlank()) meta.synopsis else plot
trailerUrl = trailerUrl ?: meta.trailerUrl
addTrailer(meta.trailerUrl)
posterUrl = posterUrl ?: meta.posterUrl ?: meta.backgroundPosterUrl
actors = actors ?: meta.actors
}

View file

@ -222,6 +222,7 @@ object AppUtils {
/** Any object as json string */
fun Any.toJson(): String {
if(this is String) return this
return mapper.writeValueAsString(this)
}