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))
|
setFormatText(result_meta_rating, R.string.rating_format, rating?.div(1000f))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setMalSync(id: String?): Boolean {
|
private fun setMalSync(id: Int?): Boolean {
|
||||||
syncModel.setMalId(id ?: return false)
|
syncModel.setMalId(id?.toString() ?: return false)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAniListSync(id: String?): Boolean {
|
private fun setAniListSync(id: Int?): Boolean {
|
||||||
syncModel.setAniListId(id ?: return false)
|
syncModel.setAniListId(id?.toString() ?: return false)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,6 +637,7 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
||||||
startAction = arguments?.getInt("startAction") ?: START_ACTION_NORMAL
|
startAction = arguments?.getInt("startAction") ?: START_ACTION_NORMAL
|
||||||
startValue = arguments?.getInt("startValue") ?: START_VALUE_NORMAL
|
startValue = arguments?.getInt("startValue") ?: START_VALUE_NORMAL
|
||||||
|
|
||||||
|
syncModel.addFromUrl(url)
|
||||||
|
|
||||||
val api = getApiFromName(apiName)
|
val api = getApiFromName(apiName)
|
||||||
if (media_route_button != null) {
|
if (media_route_button != null) {
|
||||||
|
@ -1037,7 +1038,6 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> =
|
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> =
|
||||||
EpisodeAdapter(
|
EpisodeAdapter(
|
||||||
ArrayList(),
|
ArrayList(),
|
||||||
|
@ -1523,12 +1523,11 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
||||||
if (SettingsFragment.accountEnabled)
|
if (SettingsFragment.accountEnabled)
|
||||||
if (d is AnimeLoadResponse) {
|
if (d is AnimeLoadResponse) {
|
||||||
if (
|
if (
|
||||||
setMalSync(d.malId?.toString())
|
setMalSync(d.malId)
|
||||||
||
|
||
|
||||||
setAniListSync(d.anilistId?.toString())
|
setAniListSync(d.anilistId)
|
||||||
) {
|
) {
|
||||||
syncModel.updateMetadata()
|
syncModel.updateMetaAndUser()
|
||||||
syncModel.updateUserData()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.aniListApi
|
||||||
import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.malApi
|
import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.malApi
|
||||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||||
|
import com.lagradost.cloudstream3.utils.SyncUtil
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,12 +29,22 @@ class SyncViewModel : ViewModel() {
|
||||||
// prefix, id
|
// prefix, id
|
||||||
private val syncIds = hashMapOf<String, String>()
|
private val syncIds = hashMapOf<String, String>()
|
||||||
|
|
||||||
fun setMalId(id: String) {
|
fun setMalId(id: String?) {
|
||||||
syncIds[malApi.idPrefix] = id
|
syncIds[malApi.idPrefix] = id ?: return
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAniListId(id: String) {
|
fun setAniListId(id: String?) {
|
||||||
syncIds[aniListApi.idPrefix] = id
|
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) {
|
fun setEpisodesDelta(delta: Int) {
|
||||||
|
@ -124,4 +135,9 @@ class SyncViewModel : ViewModel() {
|
||||||
_metaResponse.postValue(lastError)
|
_metaResponse.postValue(lastError)
|
||||||
setEpisodesDelta(0)
|
setEpisodesDelta(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateMetaAndUser() {
|
||||||
|
updateMetadata()
|
||||||
|
updateUserData()
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,9 +8,49 @@ import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
object SyncUtil {
|
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,
|
/** first. Mal, second. Anilist,
|
||||||
* valid sites are: Gogoanime, Twistmoe and 9anime*/
|
* 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 {
|
try {
|
||||||
//Gogoanime, Twistmoe and 9anime
|
//Gogoanime, Twistmoe and 9anime
|
||||||
val url =
|
val url =
|
||||||
|
@ -81,5 +121,4 @@ object SyncUtil {
|
||||||
@JsonProperty("updatedAt") val updatedAt: String?,
|
@JsonProperty("updatedAt") val updatedAt: String?,
|
||||||
@JsonProperty("deletedAt") val deletedAt: String?
|
@JsonProperty("deletedAt") val deletedAt: String?
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue