cloudstream icon indicating copy to clipboard operation
cloudstream copied to clipboard

GitHub account

Open antonydp opened this issue 3 years ago • 16 comments

antonydp avatar Sep 30 '22 19:09 antonydp

Looks good, @LagradOst ?

Is there anything missing or incomplete? I can help if there's anything :pray:

Blatzar avatar Sep 30 '22 19:09 Blatzar

The main functions (backupGithub & restorePromptGithub) are working for me, we now need to decide if it's best to add a dedicated "backup data on cloud" button or to make it do that automatically or both. Also before merging I think someone else should compile it and try all the features to see if it's actually working fine.

antonydp avatar Sep 30 '22 20:09 antonydp

Can you explain how it works in layman terms?

venkat2305 avatar Oct 01 '22 05:10 venkat2305

Basically the current backup feature already coded in cloudstream works thanks to two main functions: Backup () writes and stores in the phone memory a txt file with the user data RestorePrompt() use the txt file the user selects and convert back the txt into cloudstream data

This cloud solutions mimics this procedure BackupGithub() creates a gist in your gist.github account and uploads there the txt file made by backup(). In order to do that you need to provide a GitHub token for authentication RestorePromptGithub() simply downloads the gist and uses the current RestorePrompt()

antonydp avatar Oct 01 '22 09:10 antonydp

After logging in , every time we open CS3 , it downloads and uploads the text(back up data) right?

venkat2305 avatar Oct 01 '22 10:10 venkat2305

I only coded backupGithub & restorePromptGithub, the logic regarding how to automate the process is not there yet. I was in fact asking if it's best to add a dedicated "backup data on cloud" button or to make it do that automatically or both.

antonydp avatar Oct 01 '22 10:10 antonydp

I think it should be automatic. We use multiple devices(me personally tv, laptop, phone). We can just continue from another device without doing anything. Or maybe options for automatic and and dedicated button???

venkat2305 avatar Oct 01 '22 11:10 venkat2305

Okay for automatic restoration I'm thinking something like

ioSafe {
    initAll()
    // No duplicates (which can happen by registerMainAPI)
    apis = allProviders.distinctBy { it }

    if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)){
        this.restorePromptGithub()
    }
}

at https://github.com/recloudstream/cloudstream/blob/master/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt#L584 and something like

override fun onDestroy() {
    val broadcastIntent = Intent()
    broadcastIntent.action = "restart_service"
    broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java)

    if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)) {
        this.backupGithub()
    }

    this.sendBroadcast(broadcastIntent)
    afterPluginsLoadedEvent -= ::onAllPluginsLoaded
    super.onDestroy()
}

At https://github.com/recloudstream/cloudstream/blob/master/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt#L400 I am not 100% this will cause a race condition since its threaded, but if you ever see that it does not backup the data to github try moving it to the onStop or lastly onPause

Blatzar avatar Oct 01 '22 11:10 Blatzar

This would assume you had a switch in settings with the key R.string.automatic_cloud_backups :+1: Why have a button, when you can just toggle the automatic functionality :shrug:

Blatzar avatar Oct 01 '22 11:10 Blatzar

There's something to fix in the restoreprompt: it looks like it's restoring cached data before it gets the backup from cloud. does it make sense?

antonydp avatar Oct 01 '22 12:10 antonydp

I am not quite sure what you mean :confused:

Blatzar avatar Oct 01 '22 13:10 Blatzar

I wasn't sure what I meant either 🤣 anyway we made some changes, it still needs testing, if someone else can compile it and test it, that would be nice

antonydp avatar Oct 01 '22 19:10 antonydp

Can it backup and restore app settings?

venkat2305 avatar Oct 18 '22 07:10 venkat2305

hm. it still doesnt seem to properly push the settings to the gist

C10udburst avatar Oct 27 '22 21:10 C10udburst

To make the home page refresh you can do the following: In the HomeFragment companion object:

val reloadStoredDataEvent = Event<Unit>()

in the onstop and onresume in homefragment.kt inlude the new method like the following

    override fun onResume() {
        super.onResume()
        reloadStored()
        afterPluginsLoadedEvent += ::firstLoadHomePage
        mainPluginsLoadedEvent += ::firstLoadHomePage
        reloadStoredDataEvent += ::reloadStoredEvent
    }

    override fun onStop() {
        afterPluginsLoadedEvent -= ::firstLoadHomePage
        mainPluginsLoadedEvent -= ::firstLoadHomePage
        reloadStoredDataEvent -= ::reloadStoredEvent
        super.onStop()
    }

    private fun reloadStoredEvent(input: Unit) {
        reloadStored()
    }

Now you can call HomeFragment.reloadStoredDataEvent.invoke(Unit) from wherever you want and it'll reload all the local data @antonydp

Blatzar avatar Nov 04 '22 22:11 Blatzar

I tested this now on a fresh dummy account on a fresh cs3 install and got some things to say.

  1. the toast when exiting the app saying "saved data" is super annoying, it is better to have a toast if it fails
  2. It did not work for me and instead created many gist with the same name????? image
  3. The account got fucked because it looked sus af to have an 20min old acc creating many gists. please add a note that that might happend if ppl create new accounts image

I can take a look at the code too, but these are kinda important impo

LagradOst avatar Dec 03 '22 22:12 LagradOst

closed but why?

venkat2305 avatar Mar 22 '23 12:03 venkat2305

What did this PR do?

RokeJulianLockhart avatar Aug 11 '23 16:08 RokeJulianLockhart

https://github.com/recloudstream/cloudstream/pull/128#issuecomment-1675069301

https://codeberg.org/cloudstream/cloudstream/issues/426#issuecomment-849020

RokeJulianLockhart avatar Aug 31 '23 16:08 RokeJulianLockhart