Fixed mapper not working due to collision

This commit is contained in:
CranberrySoup 2024-04-26 01:18:57 +02:00
parent 6a4122bee6
commit a007b579a8
2 changed files with 91 additions and 24 deletions

View File

@ -37,6 +37,10 @@ import kotlin.math.absoluteValue
**/ **/
const val AllLanguagesName = "universal" const val AllLanguagesName = "universal"
//val baseHeader = mapOf("User-Agent" to USER_AGENT)
val mapper = JsonMapper.builder().addModule(kotlinModule())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build()!!
object APIHolder { object APIHolder {
val unixTime: Long val unixTime: Long
get() = System.currentTimeMillis() / 1000L get() = System.currentTimeMillis() / 1000L
@ -114,7 +118,8 @@ object APIHolder {
fun LoadResponse.getId(): Int { fun LoadResponse.getId(): Int {
// this fixes an issue with outdated api as getLoadResponseIdFromUrl might be fucked // this fixes an issue with outdated api as getLoadResponseIdFromUrl might be fucked
return (if (this is ResultViewModel2.LoadResponseFromSearch) this.id else null) ?: getLoadResponseIdFromUrl(url, apiName) return (if (this is ResultViewModel2.LoadResponseFromSearch) this.id else null)
?: getLoadResponseIdFromUrl(url, apiName)
} }
/** /**
@ -215,10 +220,15 @@ object APIHolder {
} ?: false } ?: false
val matchingTypes = types?.any { it.name.equals(media.format, true) } == true val matchingTypes = types?.any { it.name.equals(media.format, true) } == true
if(lessAccurate) matchingTitles || matchingTypes && matchingYears else matchingTitles && matchingTypes && matchingYears if (lessAccurate) matchingTitles || matchingTypes && matchingYears else matchingTitles && matchingTypes && matchingYears
} ?: return null } ?: return null
Tracker(res.idMal, res.id.toString(), res.coverImage?.extraLarge ?: res.coverImage?.large, res.bannerImage) Tracker(
res.idMal,
res.id.toString(),
res.coverImage?.extraLarge ?: res.coverImage?.large,
res.bannerImage
)
} catch (t: Throwable) { } catch (t: Throwable) {
logError(t) logError(t)
null null
@ -859,6 +869,7 @@ enum class TvType(value: Int?) {
Others(12), Others(12),
Music(13), Music(13),
AudioBook(14), AudioBook(14),
/** Wont load the built in player, make your own interaction */ /** Wont load the built in player, make your own interaction */
CustomMedia(15), CustomMedia(15),
} }
@ -1246,13 +1257,15 @@ interface LoadResponse {
fun LoadResponse.getImdbId(): String? { fun LoadResponse.getImdbId(): String? {
return normalSafeApiCall { return normalSafeApiCall {
SimklApi.readIdFromString(this.syncData[simklIdPrefix])?.get(SimklApi.Companion.SyncServices.Imdb) SimklApi.readIdFromString(this.syncData[simklIdPrefix])
?.get(SimklApi.Companion.SyncServices.Imdb)
} }
} }
fun LoadResponse.getTMDbId(): String? { fun LoadResponse.getTMDbId(): String? {
return normalSafeApiCall { return normalSafeApiCall {
SimklApi.readIdFromString(this.syncData[simklIdPrefix])?.get(SimklApi.Companion.SyncServices.Tmdb) SimklApi.readIdFromString(this.syncData[simklIdPrefix])
?.get(SimklApi.Companion.SyncServices.Tmdb)
} }
} }
@ -1536,8 +1549,26 @@ data class TorrentLoadResponse(
posterHeaders: Map<String, String>? = null, posterHeaders: Map<String, String>? = null,
backgroundPosterUrl: String? = null, backgroundPosterUrl: String? = null,
) : this( ) : this(
name, url, apiName, magnet, torrent, plot, type, posterUrl, year, rating, tags, duration, trailers, name,
recommendations, actors, comingSoon, syncData, posterHeaders, backgroundPosterUrl, null url,
apiName,
magnet,
torrent,
plot,
type,
posterUrl,
year,
rating,
tags,
duration,
trailers,
recommendations,
actors,
comingSoon,
syncData,
posterHeaders,
backgroundPosterUrl,
null
) )
} }
@ -1589,7 +1620,8 @@ data class AnimeLoadResponse(
return this.episodes.maxOf { (_, episodes) -> return this.episodes.maxOf { (_, episodes) ->
episodes.count { episodeData -> episodes.count { episodeData ->
// Prioritize display season as actual season may be something random to fit multiple seasons into one. // Prioritize display season as actual season may be something random to fit multiple seasons into one.
val episodeSeason = displayMap[episodeData.season] ?: episodeData.season ?: Int.MIN_VALUE val episodeSeason =
displayMap[episodeData.season] ?: episodeData.season ?: Int.MIN_VALUE
// Count all episodes from season 1 to below the current season. // Count all episodes from season 1 to below the current season.
episodeSeason in 1..<season episodeSeason in 1..<season
} }
@ -1626,9 +1658,31 @@ data class AnimeLoadResponse(
seasonNames: List<SeasonData>? = null, seasonNames: List<SeasonData>? = null,
backgroundPosterUrl: String? = null, backgroundPosterUrl: String? = null,
) : this( ) : this(
engName, japName, name, url, apiName, type, posterUrl, year, episodes, showStatus, plot, tags, engName,
synonyms, rating, duration, trailers, recommendations, actors, comingSoon, syncData, posterHeaders, japName,
nextAiring, seasonNames, backgroundPosterUrl, null name,
url,
apiName,
type,
posterUrl,
year,
episodes,
showStatus,
plot,
tags,
synonyms,
rating,
duration,
trailers,
recommendations,
actors,
comingSoon,
syncData,
posterHeaders,
nextAiring,
seasonNames,
backgroundPosterUrl,
null
) )
} }
@ -1760,7 +1814,7 @@ data class MovieLoadResponse(
backgroundPosterUrl: String? = null, backgroundPosterUrl: String? = null,
) : this( ) : this(
name, url, apiName, type, dataUrl, posterUrl, year, plot, rating, tags, duration, trailers, name, url, apiName, type, dataUrl, posterUrl, year, plot, rating, tags, duration, trailers,
recommendations, actors, comingSoon, syncData, posterHeaders, backgroundPosterUrl,null recommendations, actors, comingSoon, syncData, posterHeaders, backgroundPosterUrl, null
) )
} }
@ -1903,7 +1957,8 @@ data class TvSeriesLoadResponse(
return episodes.count { episodeData -> return episodes.count { episodeData ->
// Prioritize display season as actual season may be something random to fit multiple seasons into one. // Prioritize display season as actual season may be something random to fit multiple seasons into one.
val episodeSeason = displayMap[episodeData.season] ?: episodeData.season ?: Int.MIN_VALUE val episodeSeason =
displayMap[episodeData.season] ?: episodeData.season ?: Int.MIN_VALUE
// Count all episodes from season 1 to below the current season. // Count all episodes from season 1 to below the current season.
episodeSeason in 1..<season episodeSeason in 1..<season
} + episode } + episode
@ -1936,9 +1991,28 @@ data class TvSeriesLoadResponse(
seasonNames: List<SeasonData>? = null, seasonNames: List<SeasonData>? = null,
backgroundPosterUrl: String? = null, backgroundPosterUrl: String? = null,
) : this( ) : this(
name, url, apiName, type, episodes, posterUrl, year, plot, showStatus, rating, tags, duration, name,
trailers, recommendations, actors, comingSoon, syncData, posterHeaders, nextAiring, seasonNames, url,
backgroundPosterUrl, null apiName,
type,
episodes,
posterUrl,
year,
plot,
showStatus,
rating,
tags,
duration,
trailers,
recommendations,
actors,
comingSoon,
syncData,
posterHeaders,
nextAiring,
seasonNames,
backgroundPosterUrl,
null
) )
} }
@ -2002,6 +2076,7 @@ data class AniSearch(
@JsonProperty("extraLarge") var extraLarge: String? = null, @JsonProperty("extraLarge") var extraLarge: String? = null,
@JsonProperty("large") var large: String? = null, @JsonProperty("large") var large: String? = null,
) )
data class Title( data class Title(
@JsonProperty("romaji") var romaji: String? = null, @JsonProperty("romaji") var romaji: String? = null,
@JsonProperty("english") var english: String? = null, @JsonProperty("english") var english: String? = null,

View File

@ -1,14 +1,6 @@
package com.lagradost.cloudstream3 package com.lagradost.cloudstream3
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.kotlinModule
const val USER_AGENT = const val USER_AGENT =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
//val baseHeader = mapOf("User-Agent" to USER_AGENT)
val mapper = JsonMapper.builder().addModule(kotlinModule())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build()!!
class ErrorLoadingException(message: String? = null) : Exception(message) class ErrorLoadingException(message: String? = null) : Exception(message)