cloudstream/app/src/main/java/com/lagradost/cloudstream3/metaproviders/AnilistRedirector.kt
LagradOst 918136f8f0
Opensubs dev into master (#1136)
* [Feature][WIP] Add option to download subtitles from Opensubtitles.org (#1082)

Co-authored-by: Jace <54625750+Jacekun@users.noreply.github.com>
Co-authored-by: Jace <jaceorwell@gmail.com>
Co-authored-by: LagradOst <11805592+LagradOst@users.noreply.github.com>
2022-06-07 16:38:24 +00:00

30 lines
No EOL
1.1 KiB
Kotlin

package com.lagradost.cloudstream3.metaproviders
import com.lagradost.cloudstream3.ErrorLoadingException
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.SyncApis
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.aniListApi
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.malApi
import com.lagradost.cloudstream3.utils.SyncUtil
object SyncRedirector {
val syncApis = SyncApis
suspend fun redirect(url: String, preferredUrl: String): String {
for (api in syncApis) {
if (url.contains(api.mainUrl)) {
val otherApi = when (api.name) {
aniListApi.name -> "anilist"
malApi.name -> "myanimelist"
else -> return url
}
return SyncUtil.getUrlsFromId(api.getIdFromUrl(url), otherApi).firstOrNull { realUrl ->
realUrl.contains(preferredUrl)
} ?: run {
throw ErrorLoadingException("Page does not exist on $preferredUrl")
}
}
}
return url
}
}