Kodi Community Forum

Full Version: [HOW TO] Have rclone autostart on an Android install
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Thought i would document the way I set up rclone to automatically run on my android kodi install.

Prerequisites:
1) Download and unzip rclone-android-arm binary from https://beta.rclone.org/test/testbuilds-latest/
2) A working rclone.conf file (configure with rclone on pc/mac and confirm it's working beforehand)
3) daemon.py from https://www.jejik.com/articles/2007/02/a...in_python/
4) My autoexec.py from https://paste.kodi.tv/raw/aqujicatid

Edit the daemon.py to remove the following two lines

        os.dup2(so.fileno(), sys.stdout.fileno())
        os.dup2(se.fileno(), sys.stderr.fileno())

Edit the autoexec.py file to have the rclone command you want run at kodi start. I highly recommend using the "serve webdav" command, and adding the webdav as a source in Kodi, but any rclone commands will work.

If you use my example, you need to change <your rclone named remote> to your rclone remote.
Then add a webdav source to localhost on port 23457 in kodi.

I have tried using "serve http" but kodi had problems with certain characters in directory names, &,' etc...

Copying all 4 files into your kodi userdata directory will start rclone running when kodi starts, on your android device. I'm sure there's a proper plugin/addon way to do things, but this, with changes to buffering in the advancedsetting.xml file has been flawless for reading directly from cloud storage.


I've created a github fork of fandangos addon.  It will download the rclone binary and start it on kodi start.  The command it runs can be modified, as well as the version of rclone it downloads in the addon settings.

https://github.com/jmez11/rclone-addon

You can create a zip of the script.service.rclone and install manually.  

On start it will download the specified rclone binary to special://temp/rclone.gz and unzip it to special://xbmcbin/../../../cache/lib/rclone-android-16-arm

It will only download a new version if special://xbmcbin/../../../cache/lib/rclone-android-16-arm does not exist.   To update the rclone binary to a newer version, you need to update the url in your config, and delete special://xbmcbin/../../../cache/lib/rclone-android-16-arm in the file manager.  Then restart kodi.  

Hope someone else finds this information useful.
(2020-05-08, 03:09)jkasyan Wrote: [ -> ]Thought i would document the way I set up rclone to automatically run on my android kodi install.

Prerequisites:
1) Download and unzip rclone-android-arm binary from https://beta.rclone.org/test/testbuilds-latest/
2) A working rclone.conf file (configure with rclone on pc/mac and confirm it's working beforehand)
3) daemon.py from https://www.jejik.com/articles/2007/02/a...in_python/
4) My autoexec.py from https://paste.kodi.tv/raw/aqujicatid

Edit the daemon.py to remove the following two lines

        os.dup2(so.fileno(), sys.stdout.fileno())
        os.dup2(se.fileno(), sys.stderr.fileno())

Edit the autoexec.py file to have the rclone command you want run at kodi start. I highly recommend using the "serve webdav" command, and adding the webdav as a source in Kodi, but any rclone commands will work.

If you use my example, you need to change <your rclone named remote> to your rclone remote.
Then add a webdav source to localhost on port 23457 in kodi.

I have tried using "serve http" but kodi had problems with certain characters in directory names, &,' etc...

Copying all 4 files into your kodi userdata directory will start rclone running when kodi starts, on your android device. I'm sure there's a proper plugin/addon way to do things, but this, with changes to buffering in the advancedsetting.xml file has been flawless for reading directly from cloud storage.

Hope someone else finds this information useful.
Hey, I'm trying to achieve exactly what you have described here. Your autoexec.py is no longer linked. Is there any chance you could upload it again please? Thanks
Code:
#!/usr/bin/python3.4
import os, sys, xbmc, time, stat, xbmcvfs
from daemon import Daemon

src = xbmc.translatePath("special://masterprofile/rclone-android-16-arm")
loc = xbmc.translatePath("special://xbmcbin/../../../cache/lib/rclone-android-16-arm")

if not xbmcvfs.exists(loc):
    xbmcvfs.copy(src, loc)
    st = os.stat(loc)
    os.chmod(loc, st.st_mode | stat.S_IEXEC)

loc2 = xbmc.translatePath("special://masterprofile/rclone.conf")
pidfile  = xbmc.translatePath("special://temp/librclone.pid")
logfile  = xbmc.translatePath("special://temp/librclone.log")
cachepath  = xbmc.translatePath("special://temp")
if os.path.isfile(pidfile):
    os.remove(pidfile)

class MyDaemon(Daemon):
    def run(self):
        os.popen(loc + " serve webdav <your rclone named remote>: --addr :23457 --config " + loc2 + " --log-file=" + logfile + " --dir-cache-time 2400h --poll-interval 10m &")

if __name__ == "__main__":
    monitor = xbmc.Monitor()
    rclonedaemon = MyDaemon(pidfile)
    rclonedaemon.start()
    while not monitor.abortRequested():
        if monitor.waitForAbort(10):
            rclonedaemon.stop()
            break

I use --dir-cache-time 2400h --poll-interval 10m above.  Replace with values you like, or add any others.  Just leave the & at the end.
Oh, be sure you're not running 19.x versions. Matrix is disabling autoexec, and I haven't figured out how to do it properly yet.
If that isn't awesome, I don't know what is. 

Thank you for the tutorial and scripts, it works really well.
(2020-12-24, 08:11)jkasyan Wrote: [ -> ]Oh, be sure you're not running 19.x versions. Matrix is disabling autoexec, and I haven't figured out how to do it properly yet.

https://kodi.wiki/view/Autoexec_Service

I know nothing of python but I believe we need a service addon to make it work.
@jkasyan 

Ported the daemon to python 3.
created the addon files needed. 
fixed the file paths.

But there's something I can't figure out:
Quote:RuntimeError: fork not supported for subinterpreters

Here's the git for it:

https://github.com/fandangos/rclone-addon

Do you have any idea how to do this?
Got it working with Kodi Matrix v19 and Python 3.8.5.

There are several restrictions to create a subprocess with newer python and Kodi Matrix removed AutoExec.. 

But there you go:

https://github.com/fandangos/rclone-addon/
  1. Install addon from zip file
  2. Edit file addon/service.autoexec/autoexec.py and change to the name of your remote for the one in rclone config file.
  3. Place rclone.conf in your master profile folder (the user data folder)
  4. Enable the addon in your addon settings (it is called Auto Exec)
  5. Add a webdav source with localhost and port 23457
Enjoy

Download link for the zip file:
https://github.com/fandangos/rclone-addo...toexec.zip

Please, test it, I'm a complete noob with Python and I have removed the daemon because I have no idea how to do use it with the newer restrictions from python 3.8+.
(2021-01-02, 23:13)fandangos Wrote: [ -> ]Got it working with Kodi Matrix v19 and Python 3.8.5.

There are several restrictions to create a subprocess with newer python and Kodi Matrix removed AutoExec.. 

But there you go:

https://github.com/fandangos/rclone-addon/
  1. Install addon from zip file
  2. Edit file addon/service.autoexec/autoexec.py and change to the name of your remote for the one in rclone config file.
  3. Place rclone.conf in your master profile folder (the user data folder)
  4. Enable the addon in your addon settings (it is called Auto Exec)
  5. Add a webdav source with localhost and port 23457
Enjoy

Download link for the zip file:
https://github.com/fandangos/rclone-addo...toexec.zip

Please, test it, I'm a complete noob with Python and I have removed the daemon because I have no idea how to do use it with the newer restrictions from python 3.8+.

I appreciate it, but i don't plan on testing matrix until there's an official non beta non rc release.  I am curious if the kodi quit function works. The reason i use the demonizer is to allow kodi to gracefully stop rclone on quit.  Without it, it just hangs.
(2021-02-10, 08:23)jkasyan Wrote: [ -> ]
(2021-01-02, 23:13)fandangos Wrote: [ -> ]Got it working with Kodi Matrix v19 and Python 3.8.5.

There are several restrictions to create a subprocess with newer python and Kodi Matrix removed AutoExec.. 

But there you go:

https://github.com/fandangos/rclone-addon/
  1. Install addon from zip file
  2. Edit file addon/service.autoexec/autoexec.py and change to the name of your remote for the one in rclone config file.
  3. Place rclone.conf in your master profile folder (the user data folder)
  4. Enable the addon in your addon settings (it is called Auto Exec)
  5. Add a webdav source with localhost and port 23457
Enjoy

Download link for the zip file:
https://github.com/fandangos/rclone-addo...toexec.zip

Please, test it, I'm a complete noob with Python and I have removed the daemon because I have no idea how to do use it with the newer restrictions from python 3.8+.

I appreciate it, but i don't plan on testing matrix until there's an official non beta non rc release.  I am curious if the kodi quit function works. The reason i use the demonizer is to allow kodi to gracefully stop rclone on quit.  Without it, it just hangs.

Yes but daemonization isn't possible for sub process on python 3.8.

The release of kodi matrix is just around the corner.
If you can, please, take a look, my python knowledge is minimal.
(2021-02-10, 13:13)fandangos Wrote: [ -> ]
(2021-02-10, 08:23)jkasyan Wrote: [ -> ]
(2021-01-02, 23:13)fandangos Wrote: [ -> ]Got it working with Kodi Matrix v19 and Python 3.8.5.

There are several restrictions to create a subprocess with newer python and Kodi Matrix removed AutoExec.. 

But there you go:

https://github.com/fandangos/rclone-addon/
  1. Install addon from zip file
  2. Edit file addon/service.autoexec/autoexec.py and change to the name of your remote for the one in rclone config file.
  3. Place rclone.conf in your master profile folder (the user data folder)
  4. Enable the addon in your addon settings (it is called Auto Exec)
  5. Add a webdav source with localhost and port 23457
Enjoy

Download link for the zip file:
https://github.com/fandangos/rclone-addo...toexec.zip

Please, test it, I'm a complete noob with Python and I have removed the daemon because I have no idea how to do use it with the newer restrictions from python 3.8+.

I appreciate it, but i don't plan on testing matrix until there's an official non beta non rc release.  I am curious if the kodi quit function works. The reason i use the demonizer is to allow kodi to gracefully stop rclone on quit.  Without it, it just hangs.

Yes but daemonization isn't possible for sub process on python 3.8.

The release of kodi matrix is just around the corner.
If you can, please, take a look, my python knowledge is minimal.
Hi @fandangos, your add-on is awesome. Working quite well!!!!

The only problem I'm getting is that it is filling the memory of my box only after 10 minutes of viewing (44GB file).
Is there any way to restrict the memory use?

Thanks in advance!!
(2021-04-09, 04:28)jorges4lu2 Wrote: [ -> ]
(2021-02-10, 13:13)fandangos Wrote: [ -> ]
(2021-02-10, 08:23)jkasyan Wrote: [ -> ]I appreciate it, but i don't plan on testing matrix until there's an official non beta non rc release.  I am curious if the kodi quit function works. The reason i use the demonizer is to allow kodi to gracefully stop rclone on quit.  Without it, it just hangs.

Yes but daemonization isn't possible for sub process on python 3.8.

The release of kodi matrix is just around the corner.
If you can, please, take a look, my python knowledge is minimal.
Hi @fandangos, your add-on is awesome. Working quite well!!!!

The only problem I'm getting is that it is filling the memory of my box only after 10 minutes of viewing (44GB file).
Is there any way to restrict the memory use?

Thanks in advance!!
What does "filling the memory" mean?   Do you get an error?  What is the error?  What rclone command are you using?  Have you set a cache mode in kodi using advancedsettings.xml?  If so, which?
Hi @fandangos, is the rclone addon working with Kodi 19.1?
I have put the rclone.conf in ANDROID\DATA\ORG.XBMC.KODI\FILES\.KODI\USERDATA and modified main.py with my remote name.
But after I added a video source with paths "http://localhost:23457/" and click OK, Kodi said "Unable to connect".

If the rclone works, is it due to the settings I did wrong?

Thank you.

Sincerely.
This seems correct.

I haven't tested kodi 19.1.
(2021-07-05, 12:03)fandangos Wrote: [ -> ]This seems correct.

I haven't tested kodi 19.1.

It does not work with Matrix 19.1, please see if someone can help
Pages: 1 2 3 4