forked from recloudstream/cloudstream
added sync to more sites
This commit is contained in:
parent
a897160d37
commit
cf1fc3ce3e
3 changed files with 69 additions and 15 deletions
|
@ -518,13 +518,13 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
|||
setFormatText(result_meta_rating, R.string.rating_format, rating?.div(1000f))
|
||||
}
|
||||
|
||||
private fun setMalSync(id: String?): Boolean {
|
||||
syncModel.setMalId(id ?: return false)
|
||||
private fun setMalSync(id: Int?): Boolean {
|
||||
syncModel.setMalId(id?.toString() ?: return false)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun setAniListSync(id: String?): Boolean {
|
||||
syncModel.setAniListId(id ?: return false)
|
||||
private fun setAniListSync(id: Int?): Boolean {
|
||||
syncModel.setAniListId(id?.toString() ?: return false)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -637,6 +637,7 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
|||
startAction = arguments?.getInt("startAction") ?: START_ACTION_NORMAL
|
||||
startValue = arguments?.getInt("startValue") ?: START_VALUE_NORMAL
|
||||
|
||||
syncModel.addFromUrl(url)
|
||||
|
||||
val api = getApiFromName(apiName)
|
||||
if (media_route_button != null) {
|
||||
|
@ -1037,7 +1038,6 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> =
|
||||
EpisodeAdapter(
|
||||
ArrayList(),
|
||||
|
@ -1523,12 +1523,11 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
|||
if (SettingsFragment.accountEnabled)
|
||||
if (d is AnimeLoadResponse) {
|
||||
if (
|
||||
setMalSync(d.malId?.toString())
|
||||
setMalSync(d.malId)
|
||||
||
|
||||
setAniListSync(d.anilistId?.toString())
|
||||
setAniListSync(d.anilistId)
|
||||
) {
|
||||
syncModel.updateMetadata()
|
||||
syncModel.updateUserData()
|
||||
syncModel.updateMetaAndUser()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.SyncApis
|
|||
import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.aniListApi
|
||||
import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.malApi
|
||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||
import com.lagradost.cloudstream3.utils.SyncUtil
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
|
@ -28,12 +29,22 @@ class SyncViewModel : ViewModel() {
|
|||
// prefix, id
|
||||
private val syncIds = hashMapOf<String, String>()
|
||||
|
||||
fun setMalId(id: String) {
|
||||
syncIds[malApi.idPrefix] = id
|
||||
fun setMalId(id: String?) {
|
||||
syncIds[malApi.idPrefix] = id ?: return
|
||||
}
|
||||
|
||||
fun setAniListId(id: String) {
|
||||
syncIds[aniListApi.idPrefix] = id
|
||||
fun setAniListId(id: String?) {
|
||||
syncIds[aniListApi.idPrefix] = id ?: return
|
||||
}
|
||||
|
||||
fun addFromUrl(url : String?) = viewModelScope.launch {
|
||||
SyncUtil.getIdsFromUrl(url)?.let { (malId, aniListId) ->
|
||||
setMalId(malId)
|
||||
setAniListId(aniListId)
|
||||
if(malId != null || aniListId != null) {
|
||||
updateMetaAndUser()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setEpisodesDelta(delta: Int) {
|
||||
|
@ -124,4 +135,9 @@ class SyncViewModel : ViewModel() {
|
|||
_metaResponse.postValue(lastError)
|
||||
setEpisodesDelta(0)
|
||||
}
|
||||
|
||||
fun updateMetaAndUser() {
|
||||
updateMetadata()
|
||||
updateUserData()
|
||||
}
|
||||
}
|
|
@ -8,9 +8,49 @@ import com.lagradost.cloudstream3.mvvm.logError
|
|||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object SyncUtil {
|
||||
private val regexs = listOf(
|
||||
Regex("""(9anime)\.(?:to|center|id)/watch/(?:.*?)\.([^/?]*)"""),
|
||||
Regex("""(gogoanime|gogoanimes)\..*?/category/([^/?]*)"""),
|
||||
Regex("""(twist\.moe)/a/([^/?]*)"""),
|
||||
)
|
||||
|
||||
private const val GOGOANIME = "Gogoanime"
|
||||
private const val NINE_ANIME = "9anime"
|
||||
private const val TWIST_MOE = "Twistmoe"
|
||||
|
||||
private val matchList =
|
||||
mapOf(
|
||||
"9anime" to NINE_ANIME,
|
||||
"gogoanime" to GOGOANIME,
|
||||
"gogoanimes" to GOGOANIME,
|
||||
"twist.moe" to TWIST_MOE
|
||||
)
|
||||
|
||||
suspend fun getIdsFromUrl(url: String?): Pair<String?, String?>? {
|
||||
if (url == null) return null
|
||||
|
||||
for (regex in regexs) {
|
||||
regex.find(url)?.let { match ->
|
||||
if (match.groupValues.size == 3) {
|
||||
val site = match.groupValues[1]
|
||||
val slug = match.groupValues[2]
|
||||
matchList[site]?.let { realSite ->
|
||||
getIdsFromSlug(slug, realSite)?.let {
|
||||
return it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** first. Mal, second. Anilist,
|
||||
* valid sites are: Gogoanime, Twistmoe and 9anime*/
|
||||
suspend fun getIdsFromSlug(slug: String, site : String = "Gogoanime"): Pair<String?, String?>? {
|
||||
private suspend fun getIdsFromSlug(
|
||||
slug: String,
|
||||
site: String = "GogoanimeGogoanime"
|
||||
): Pair<String?, String?>? {
|
||||
try {
|
||||
//Gogoanime, Twistmoe and 9anime
|
||||
val url =
|
||||
|
@ -81,5 +121,4 @@ object SyncUtil {
|
|||
@JsonProperty("updatedAt") val updatedAt: String?,
|
||||
@JsonProperty("deletedAt") val deletedAt: String?
|
||||
)
|
||||
|
||||
}
|
Loading…
Reference in a new issue