mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
feat(Extensions): Consider time zone in Trakt durations (#1140)
This commit is contained in:
parent
7a0cd07dc1
commit
bda6673cfd
1 changed files with 43 additions and 14 deletions
|
@ -1,18 +1,39 @@
|
||||||
package com.lagradost.cloudstream3.metaproviders
|
package com.lagradost.cloudstream3.metaproviders
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import com.lagradost.cloudstream3.*
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAlias
|
import com.fasterxml.jackson.annotation.JsonAlias
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import com.lagradost.cloudstream3.APIHolder
|
||||||
import com.lagradost.cloudstream3.APIHolder.unixTimeMS
|
import com.lagradost.cloudstream3.APIHolder.unixTimeMS
|
||||||
|
import com.lagradost.cloudstream3.Actor
|
||||||
|
import com.lagradost.cloudstream3.ActorData
|
||||||
|
import com.lagradost.cloudstream3.Episode
|
||||||
|
import com.lagradost.cloudstream3.HomePageResponse
|
||||||
|
import com.lagradost.cloudstream3.LoadResponse
|
||||||
import com.lagradost.cloudstream3.LoadResponse.Companion.addImdbId
|
import com.lagradost.cloudstream3.LoadResponse.Companion.addImdbId
|
||||||
import com.lagradost.cloudstream3.LoadResponse.Companion.addTMDbId
|
import com.lagradost.cloudstream3.LoadResponse.Companion.addTMDbId
|
||||||
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
|
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
|
||||||
|
import com.lagradost.cloudstream3.MainAPI
|
||||||
|
import com.lagradost.cloudstream3.MainPageRequest
|
||||||
|
import com.lagradost.cloudstream3.NextAiring
|
||||||
|
import com.lagradost.cloudstream3.ProviderType
|
||||||
|
import com.lagradost.cloudstream3.SearchResponse
|
||||||
|
import com.lagradost.cloudstream3.ShowStatus
|
||||||
|
import com.lagradost.cloudstream3.TvType
|
||||||
|
import com.lagradost.cloudstream3.addDate
|
||||||
|
import com.lagradost.cloudstream3.app
|
||||||
|
import com.lagradost.cloudstream3.base64Decode
|
||||||
|
import com.lagradost.cloudstream3.mainPageOf
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
|
import com.lagradost.cloudstream3.newHomePageResponse
|
||||||
|
import com.lagradost.cloudstream3.newMovieLoadResponse
|
||||||
|
import com.lagradost.cloudstream3.newMovieSearchResponse
|
||||||
|
import com.lagradost.cloudstream3.newTvSeriesLoadResponse
|
||||||
|
import com.lagradost.cloudstream3.newTvSeriesSearchResponse
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
||||||
import java.util.Locale
|
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Locale
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
open class TraktProvider : MainAPI() {
|
open class TraktProvider : MainAPI() {
|
||||||
|
@ -25,7 +46,8 @@ open class TraktProvider : MainAPI() {
|
||||||
TvType.Anime,
|
TvType.Anime,
|
||||||
)
|
)
|
||||||
|
|
||||||
private val traktClientId = base64Decode("N2YzODYwYWQzNGI4ZTZmOTdmN2I5MTA0ZWQzMzEwOGI0MmQ3MTdlMTM0MmM2NGMxMTg5NGE1MjUyYTQ3NjE3Zg==")
|
private val traktClientId =
|
||||||
|
base64Decode("N2YzODYwYWQzNGI4ZTZmOTdmN2I5MTA0ZWQzMzEwOGI0MmQ3MTdlMTM0MmM2NGMxMTg5NGE1MjUyYTQ3NjE3Zg==")
|
||||||
private val traktApiUrl = base64Decode("aHR0cHM6Ly9hcGl6LnRyYWt0LnR2")
|
private val traktApiUrl = base64Decode("aHR0cHM6Ly9hcGl6LnRyYWt0LnR2")
|
||||||
|
|
||||||
override val mainPage = mainPageOf(
|
override val mainPage = mainPageOf(
|
||||||
|
@ -77,7 +99,8 @@ open class TraktProvider : MainAPI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun search(query: String): List<SearchResponse>? {
|
override suspend fun search(query: String): List<SearchResponse>? {
|
||||||
val apiResponse = getApi("$traktApiUrl/search/movie,show?extended=cloud9,full&limit=20&page=1&query=$query")
|
val apiResponse =
|
||||||
|
getApi("$traktApiUrl/search/movie,show?extended=cloud9,full&limit=20&page=1&query=$query")
|
||||||
|
|
||||||
val results = parseJson<List<MediaDetails>>(apiResponse).map { element ->
|
val results = parseJson<List<MediaDetails>>(apiResponse).map { element ->
|
||||||
element.toSearchResponse()
|
element.toSearchResponse()
|
||||||
|
@ -85,6 +108,7 @@ open class TraktProvider : MainAPI() {
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun load(url: String): LoadResponse {
|
override suspend fun load(url: String): LoadResponse {
|
||||||
|
|
||||||
val data = parseJson<Data>(url)
|
val data = parseJson<Data>(url)
|
||||||
|
@ -94,7 +118,8 @@ open class TraktProvider : MainAPI() {
|
||||||
val posterUrl = mediaDetails?.images?.poster?.firstOrNull()
|
val posterUrl = mediaDetails?.images?.poster?.firstOrNull()
|
||||||
val backDropUrl = mediaDetails?.images?.fanart?.firstOrNull()
|
val backDropUrl = mediaDetails?.images?.fanart?.firstOrNull()
|
||||||
|
|
||||||
val resActor = getApi("$traktApiUrl/$moviesOrShows/${mediaDetails?.ids?.trakt}/people?extended=cloud9,full")
|
val resActor =
|
||||||
|
getApi("$traktApiUrl/$moviesOrShows/${mediaDetails?.ids?.trakt}/people?extended=cloud9,full")
|
||||||
|
|
||||||
val actors = parseJson<People>(resActor).cast?.map {
|
val actors = parseJson<People>(resActor).cast?.map {
|
||||||
ActorData(
|
ActorData(
|
||||||
|
@ -106,12 +131,15 @@ open class TraktProvider : MainAPI() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val resRelated = getApi("$traktApiUrl/$moviesOrShows/${mediaDetails?.ids?.trakt}/related?extended=cloud9,full&limit=20")
|
val resRelated =
|
||||||
|
getApi("$traktApiUrl/$moviesOrShows/${mediaDetails?.ids?.trakt}/related?extended=cloud9,full&limit=20")
|
||||||
|
|
||||||
val relatedMedia = parseJson<List<MediaDetails>>(resRelated).map { it.toSearchResponse() }
|
val relatedMedia = parseJson<List<MediaDetails>>(resRelated).map { it.toSearchResponse() }
|
||||||
|
|
||||||
val isCartoon = mediaDetails?.genres?.contains("animation") == true || mediaDetails?.genres?.contains("anime") == true
|
val isCartoon =
|
||||||
val isAnime = isCartoon && (mediaDetails?.language == "zh" || mediaDetails?.language == "ja")
|
mediaDetails?.genres?.contains("animation") == true || mediaDetails?.genres?.contains("anime") == true
|
||||||
|
val isAnime =
|
||||||
|
isCartoon && (mediaDetails?.language == "zh" || mediaDetails?.language == "ja")
|
||||||
val isAsian = !isAnime && (mediaDetails?.language == "zh" || mediaDetails?.language == "ko")
|
val isAsian = !isAnime && (mediaDetails?.language == "zh" || mediaDetails?.language == "ko")
|
||||||
val isBollywood = mediaDetails?.country == "in"
|
val isBollywood = mediaDetails?.country == "in"
|
||||||
|
|
||||||
|
@ -163,10 +191,11 @@ open class TraktProvider : MainAPI() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
val resSeasons = getApi("$traktApiUrl/shows/${mediaDetails?.ids?.trakt.toString()}/seasons?extended=cloud9,full,episodes")
|
val resSeasons =
|
||||||
|
getApi("$traktApiUrl/shows/${mediaDetails?.ids?.trakt.toString()}/seasons?extended=cloud9,full,episodes")
|
||||||
val episodes = mutableListOf<Episode>()
|
val episodes = mutableListOf<Episode>()
|
||||||
val seasons = parseJson<List<Seasons>>(resSeasons)
|
val seasons = parseJson<List<Seasons>>(resSeasons)
|
||||||
var nextAir: NextAiring? = null
|
var nextAir: NextAiring? = null
|
||||||
|
|
||||||
seasons.forEach { season ->
|
seasons.forEach { season ->
|
||||||
|
|
||||||
|
@ -208,7 +237,7 @@ open class TraktProvider : MainAPI() {
|
||||||
rating = episode.rating?.times(10)?.roundToInt(),
|
rating = episode.rating?.times(10)?.roundToInt(),
|
||||||
description = episode.overview,
|
description = episode.overview,
|
||||||
).apply {
|
).apply {
|
||||||
this.addDate(episode.firstAired)
|
this.addDate(episode.firstAired, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
|
||||||
if (nextAir == null && this.date != null && this.date!! > unixTimeMS) {
|
if (nextAir == null && this.date != null && this.date!! > unixTimeMS) {
|
||||||
nextAir = NextAiring(
|
nextAir = NextAiring(
|
||||||
episode = this.episode!!,
|
episode = this.episode!!,
|
||||||
|
@ -251,7 +280,7 @@ open class TraktProvider : MainAPI() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getApi(url: String) : String {
|
private suspend fun getApi(url: String): String {
|
||||||
return app.get(
|
return app.get(
|
||||||
url = url,
|
url = url,
|
||||||
headers = mapOf(
|
headers = mapOf(
|
||||||
|
@ -286,14 +315,14 @@ open class TraktProvider : MainAPI() {
|
||||||
return "https://$url"
|
return "https://$url"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getWidthImageUrl(path: String?, width: String) : String? {
|
private fun getWidthImageUrl(path: String?, width: String): String? {
|
||||||
if (path == null) return null
|
if (path == null) return null
|
||||||
if (!path.contains("image.tmdb.org")) return fixPath(path)
|
if (!path.contains("image.tmdb.org")) return fixPath(path)
|
||||||
val fileName = Uri.parse(path).lastPathSegment ?: return null
|
val fileName = Uri.parse(path).lastPathSegment ?: return null
|
||||||
return "https://image.tmdb.org/t/p/${width}/${fileName}"
|
return "https://image.tmdb.org/t/p/${width}/${fileName}"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getOriginalWidthImageUrl(path: String?) : String? {
|
private fun getOriginalWidthImageUrl(path: String?): String? {
|
||||||
if (path == null) return null
|
if (path == null) return null
|
||||||
if (!path.contains("image.tmdb.org")) return fixPath(path)
|
if (!path.contains("image.tmdb.org")) return fixPath(path)
|
||||||
return getWidthImageUrl(path, "original")
|
return getWidthImageUrl(path, "original")
|
||||||
|
|
Loading…
Reference in a new issue