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,85 +1423,122 @@ 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")
|
||||||
|
|
||||||
duration = duration ?: meta.duration
|
if (meta != null) {
|
||||||
rating = rating ?: meta.publicScore
|
duration = duration ?: meta.duration
|
||||||
tags = tags ?: meta.genres
|
rating = rating ?: meta.publicScore
|
||||||
plot = if (plot.isNullOrBlank()) meta.synopsis else plot
|
tags = tags ?: meta.genres
|
||||||
posterUrl = posterUrl ?: meta.posterUrl ?: meta.backgroundPosterUrl
|
plot = if (plot.isNullOrBlank()) meta.synopsis else plot
|
||||||
actors = actors ?: meta.actors
|
posterUrl = posterUrl ?: meta.posterUrl ?: meta.backgroundPosterUrl
|
||||||
|
actors = actors ?: meta.actors
|
||||||
|
|
||||||
if (this is EpisodeResponse) {
|
if (this is EpisodeResponse) {
|
||||||
nextAiring = nextAiring ?: meta.nextAiring
|
nextAiring = nextAiring ?: meta.nextAiring
|
||||||
|
}
|
||||||
|
|
||||||
|
val realRecommendations = ArrayList<SearchResponse>()
|
||||||
|
val apiNames = apis.filter {
|
||||||
|
it.name.contains("gogoanime", true) ||
|
||||||
|
it.name.contains("9anime", true)
|
||||||
|
}.map {
|
||||||
|
it.name
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.recommendations?.forEach { rec ->
|
||||||
|
apiNames.forEach { name ->
|
||||||
|
realRecommendations.add(rec.copy(apiName = name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recommendations = recommendations?.union(realRecommendations)?.toList()
|
||||||
|
?: realRecommendations
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((k, v) in syncs ?: emptyMap()) {
|
for ((k, v) in syncs ?: emptyMap()) {
|
||||||
syncData[k] = v
|
syncData[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
val realRecommendations = ArrayList<SearchResponse>()
|
argamap(
|
||||||
// TODO: fix
|
{
|
||||||
val apiNames = apis.filter {
|
if (this !is AnimeLoadResponse) return@argamap
|
||||||
it.name.contains("gogoanime", true) ||
|
val res = APIHolder.getTracker(
|
||||||
it.name.contains("9anime", true)
|
listOfNotNull(
|
||||||
}.map {
|
this.engName,
|
||||||
it.name
|
this.name,
|
||||||
}
|
this.japName
|
||||||
|
).distinct(), TrackerType.getTypes(this.type), this.year
|
||||||
meta.recommendations?.forEach { rec ->
|
|
||||||
apiNames.forEach { name ->
|
|
||||||
realRecommendations.add(rec.copy(apiName = name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
recommendations = recommendations?.union(realRecommendations)?.toList()
|
|
||||||
?: realRecommendations
|
|
||||||
|
|
||||||
argamap({
|
|
||||||
addTrailer(meta.trailers)
|
|
||||||
}, {
|
|
||||||
if (this !is AnimeLoadResponse) return@argamap
|
|
||||||
val map =
|
|
||||||
Kitsu.getEpisodesDetails(
|
|
||||||
getMalId(),
|
|
||||||
getAniListId(),
|
|
||||||
isResponseRequired = false
|
|
||||||
)
|
)
|
||||||
if (map.isNullOrEmpty()) return@argamap
|
|
||||||
updateEpisodes = DubStatus.values().map { dubStatus ->
|
val ids = arrayOf(
|
||||||
val current =
|
AccountManager.malApi.idPrefix to res?.malId?.toString(),
|
||||||
this.episodes[dubStatus]?.mapIndexed { index, episode ->
|
AccountManager.aniListApi.idPrefix to res?.aniId
|
||||||
episode.apply {
|
)
|
||||||
this.episode = this.episode ?: (index + 1)
|
|
||||||
}
|
if (ids.any { (id, new) ->
|
||||||
}?.sortedBy { it.episode ?: 0 }?.toMutableList()
|
val current = syncData[id]
|
||||||
if (current.isNullOrEmpty()) return@map false
|
new != null && current != null && current != new
|
||||||
val episodeNumbers = current.map { ep -> ep.episode!! }
|
}
|
||||||
var updateCount = 0
|
) {
|
||||||
map.forEach { (episode, node) ->
|
// getTracker fucked up as it conflicts with current implementation
|
||||||
episodeNumbers.binarySearch(episode).let { index ->
|
return@argamap
|
||||||
current.getOrNull(index)?.let { currentEp ->
|
}
|
||||||
current[index] = currentEp.apply {
|
|
||||||
updateCount++
|
// set all the new data, prioritise old correct data
|
||||||
val currentBack = this
|
ids.forEach { (id, new) ->
|
||||||
this.description = this.description ?: node.description?.en
|
new?.let {
|
||||||
this.name = this.name ?: node.titles?.canonical
|
syncData[id] = syncData[id] ?: it
|
||||||
this.episode =
|
}
|
||||||
this.episode ?: node.num ?: episodeNumbers[index]
|
}
|
||||||
this.posterUrl =
|
|
||||||
this.posterUrl ?: node.thumbnail?.original?.url
|
// 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)
|
||||||
|
}, {
|
||||||
|
if (this !is AnimeLoadResponse) return@argamap
|
||||||
|
val map =
|
||||||
|
Kitsu.getEpisodesDetails(
|
||||||
|
getMalId(),
|
||||||
|
getAniListId(),
|
||||||
|
isResponseRequired = false
|
||||||
|
)
|
||||||
|
if (map.isNullOrEmpty()) return@argamap
|
||||||
|
updateEpisodes = DubStatus.values().map { dubStatus ->
|
||||||
|
val current =
|
||||||
|
this.episodes[dubStatus]?.mapIndexed { index, episode ->
|
||||||
|
episode.apply {
|
||||||
|
this.episode = this.episode ?: (index + 1)
|
||||||
|
}
|
||||||
|
}?.sortedBy { it.episode ?: 0 }?.toMutableList()
|
||||||
|
if (current.isNullOrEmpty()) return@map false
|
||||||
|
val episodeNumbers = current.map { ep -> ep.episode!! }
|
||||||
|
var updateCount = 0
|
||||||
|
map.forEach { (episode, node) ->
|
||||||
|
episodeNumbers.binarySearch(episode).let { index ->
|
||||||
|
current.getOrNull(index)?.let { currentEp ->
|
||||||
|
current[index] = currentEp.apply {
|
||||||
|
updateCount++
|
||||||
|
this.description = this.description ?: node.description?.en
|
||||||
|
this.name = this.name ?: node.titles?.canonical
|
||||||
|
this.episode =
|
||||||
|
this.episode ?: node.num ?: episodeNumbers[index]
|
||||||
|
this.posterUrl =
|
||||||
|
this.posterUrl ?: node.thumbnail?.original?.url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
this.episodes[dubStatus] = current
|
||||||
this.episodes[dubStatus] = current
|
updateCount > 0
|
||||||
updateCount > 0
|
}.any { it }
|
||||||
}.any { it }
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return out to updateEpisodes
|
return out to updateEpisodes
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue