Tuesday, April 16, 2019

Setting up Kodi to share media library on Libreelec

I was looking for a way to keep all of my various Kodi devices in sync, so that I can tell from my bedroom which shows I have seen even if I watched them in the living room. Kodi has a few ways to to this, one using UPnP, another using MySQL. Both have difficulties, in my case, getting UPnP to work across both my ethernet network and my wifi network is a pain to set up and doesn't always work. The MySQL approach, as show on the Kodi wiki website is difficult to set up. There are several guides on the internet about how to do it with Docker containers, which again is a little difficult to do and is way overkill if your main Kodi instance is Libreelec. Libreelec has a standard addon for MySQL (actually MariaDB, which is the open source equivalent of MySQL).

As far as I know, this only works on Libreelec. I didn't include all the "click here" paths for each step, I'm assuming Kodi is easy enough to use to not need them.

Prerequisites:

1. Ensure all Kodi instances are running the same major version of Kodi, as in all are running Krypton or all are running Leia, or whatever the latest and greatest is named.

2. Ensure your media files are accessible from all Kodi instances. All of my media files are on a Western Digital "My Cloud" device, which is basically a NAS with a nice web interface. It is accessible via SMB or NFS.

3. Choose which Kodi instance is the "master". This one needs to be running Libreelec. This is the instance that will be maintaining the video and music sources for the library and hosting the shared library database. In my case, I have a mini-PC with 8 GB RAM and 300 GB of hard drive space connected to my main home theater system, so that's the obvious choice. I have 5 Firesticks, a laptop, and 2 phones with Kodi installed. The laptop would also be a decent choice, except it sometimes leaves the house.

On the "master":

4. Install the MariaDB/MySQL addon from the Libreelec repository.
 
5. Configure the MariaDB addon, change the root and user passwords to "kodi". There is no need to do any other db stuff, the addon takes care of setting up the db users and media database. I'm assuming this is all running on a private network, so the weak passwords are okay.
 
6. Export your current library if you want. I chose not to as it seems like an unnecessary step to me.

7. Create or update ~/.kodi/userdata/advancedsettings.xml with this:

<advancedsettings>
  <videodatabase>
    <type>mysql</type>
    <host>***.***.***.***</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </videodatabase>
  <musicdatabase>
    <type>mysql</type>
    <host>***.***.***.***</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </musicdatabase>
  <videolibrary>
    <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
  </videolibrary>
</advancedsettings>

Change both of the ***.***.***.*** to the IP address of the master Kodi instance. This tells Kodi to use MariaDB instead of the built-in SQLlite database. Notice the password are in plain text here, if you changed them in the addon settings, change them here too.

8. Restart the master.

9. Import your exported library if necessary.

10. Copy the advancedsettings.xml file to a location accessible to the other Kodi instances.

On each of the remaining Kodi instances:

11. Remove all media sources for videos and music.

12. Open the file manager.

13. In the left pane, navigate to the "profile" folder. You should see a file named "guisettings.xml" if you are in the right place.

14. In the right pane, create a new source with the location where you put the copy of advancedsettings.xml

15. In the right pane, navigate to the advancedsettings.xml file, use the context menu (right click or Ctrl-C) to copy to the left pane.

16. Restart the Kodi instance.

Should be done, all media info should automatically be available in each instance. Now shows you watch on one instance will be marked as watched on all other instances, you can pause a movie in one room and pick it up where you left off in another room. Nice!

No comments: