forked from recloudstream/cloudstream
auto track anilist/mal
This commit is contained in:
parent
3e2c2a5c86
commit
4596afee06
1 changed files with 102 additions and 64 deletions
|
@ -25,6 +25,7 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.getMalId
|
||||||
import com.lagradost.cloudstream3.LoadResponse.Companion.isMovie
|
import com.lagradost.cloudstream3.LoadResponse.Companion.isMovie
|
||||||
import com.lagradost.cloudstream3.metaproviders.SyncRedirector
|
import com.lagradost.cloudstream3.metaproviders.SyncRedirector
|
||||||
import com.lagradost.cloudstream3.mvvm.*
|
import com.lagradost.cloudstream3.mvvm.*
|
||||||
|
import com.lagradost.cloudstream3.syncproviders.AccountManager
|
||||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.Kitsu
|
import com.lagradost.cloudstream3.syncproviders.providers.Kitsu
|
||||||
import com.lagradost.cloudstream3.ui.APIRepository
|
import com.lagradost.cloudstream3.ui.APIRepository
|
||||||
|
@ -1422,11 +1423,12 @@ class ResultViewModel2 : ViewModel() {
|
||||||
meta: SyncAPI.SyncResult?,
|
meta: SyncAPI.SyncResult?,
|
||||||
syncs: Map<String, String>? = null
|
syncs: Map<String, String>? = null
|
||||||
): Pair<LoadResponse, Boolean> {
|
): Pair<LoadResponse, Boolean> {
|
||||||
if (meta == null) return resp to false
|
//if (meta == null) return resp to false
|
||||||
var updateEpisodes = false
|
var updateEpisodes = false
|
||||||
val out = resp.apply {
|
val out = resp.apply {
|
||||||
Log.i(TAG, "applyMeta")
|
Log.i(TAG, "applyMeta")
|
||||||
|
|
||||||
|
if (meta != null) {
|
||||||
duration = duration ?: meta.duration
|
duration = duration ?: meta.duration
|
||||||
rating = rating ?: meta.publicScore
|
rating = rating ?: meta.publicScore
|
||||||
tags = tags ?: meta.genres
|
tags = tags ?: meta.genres
|
||||||
|
@ -1438,12 +1440,7 @@ class ResultViewModel2 : ViewModel() {
|
||||||
nextAiring = nextAiring ?: meta.nextAiring
|
nextAiring = nextAiring ?: meta.nextAiring
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((k, v) in syncs ?: emptyMap()) {
|
|
||||||
syncData[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
val realRecommendations = ArrayList<SearchResponse>()
|
val realRecommendations = ArrayList<SearchResponse>()
|
||||||
// TODO: fix
|
|
||||||
val apiNames = apis.filter {
|
val apiNames = apis.filter {
|
||||||
it.name.contains("gogoanime", true) ||
|
it.name.contains("gogoanime", true) ||
|
||||||
it.name.contains("9anime", true)
|
it.name.contains("9anime", true)
|
||||||
|
@ -1459,8 +1456,50 @@ class ResultViewModel2 : ViewModel() {
|
||||||
|
|
||||||
recommendations = recommendations?.union(realRecommendations)?.toList()
|
recommendations = recommendations?.union(realRecommendations)?.toList()
|
||||||
?: realRecommendations
|
?: realRecommendations
|
||||||
|
}
|
||||||
|
|
||||||
argamap({
|
for ((k, v) in syncs ?: emptyMap()) {
|
||||||
|
syncData[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
argamap(
|
||||||
|
{
|
||||||
|
if (this !is AnimeLoadResponse) return@argamap
|
||||||
|
val res = APIHolder.getTracker(
|
||||||
|
listOfNotNull(
|
||||||
|
this.engName,
|
||||||
|
this.name,
|
||||||
|
this.japName
|
||||||
|
).distinct(), TrackerType.getTypes(this.type), this.year
|
||||||
|
)
|
||||||
|
|
||||||
|
val ids = arrayOf(
|
||||||
|
AccountManager.malApi.idPrefix to res?.malId?.toString(),
|
||||||
|
AccountManager.aniListApi.idPrefix to res?.aniId
|
||||||
|
)
|
||||||
|
|
||||||
|
if (ids.any { (id, new) ->
|
||||||
|
val current = syncData[id]
|
||||||
|
new != null && current != null && current != new
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
// getTracker fucked up as it conflicts with current implementation
|
||||||
|
return@argamap
|
||||||
|
}
|
||||||
|
|
||||||
|
// set all the new data, prioritise old correct data
|
||||||
|
ids.forEach { (id, new) ->
|
||||||
|
new?.let {
|
||||||
|
syncData[id] = syncData[id] ?: it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set posters, might fuck up due to headers idk
|
||||||
|
posterUrl = posterUrl ?: res?.image
|
||||||
|
backgroundPosterUrl = backgroundPosterUrl ?: res?.cover
|
||||||
|
},
|
||||||
|
{
|
||||||
|
if(meta == null) return@argamap
|
||||||
addTrailer(meta.trailers)
|
addTrailer(meta.trailers)
|
||||||
}, {
|
}, {
|
||||||
if (this !is AnimeLoadResponse) return@argamap
|
if (this !is AnimeLoadResponse) return@argamap
|
||||||
|
@ -1486,7 +1525,6 @@ class ResultViewModel2 : ViewModel() {
|
||||||
current.getOrNull(index)?.let { currentEp ->
|
current.getOrNull(index)?.let { currentEp ->
|
||||||
current[index] = currentEp.apply {
|
current[index] = currentEp.apply {
|
||||||
updateCount++
|
updateCount++
|
||||||
val currentBack = this
|
|
||||||
this.description = this.description ?: node.description?.en
|
this.description = this.description ?: node.description?.en
|
||||||
this.name = this.name ?: node.titles?.canonical
|
this.name = this.name ?: node.titles?.canonical
|
||||||
this.episode =
|
this.episode =
|
||||||
|
|
Loading…
Reference in a new issue