Central KODI Media Database

Once you start using KODI as your home theater system, you’re going to realize how cool it is and you’re going to set up more Raspberry Pis for each TV in the house! For sake of consistency, you’re going to ask yourself,

How can I share my media library with all the Raspberrys?!?!

There’s a trick. If you have a MySQL server on your network you can program KODI to store your media library metadata on it! Set up a new user account on the MySQL server for Kodi to log in and create a database. If you installed kodi with “apt install kodi” on an existing Raspberry Pi OS, do a “ps -ef | grep kodi” and see what user is running Kodi. In my case, it was root. SO, I’ll go to /root/.kodi/userdata and create a file called advancedsettings.xml. Watch out! If you installed with the LibreElec .img file the relevant files are in /storage/.kodi/userdata/ Also, to ssh into a LibreElec server the default username and password is root/libreelec You’re welcome.)

advancedsettings.xml

<advancedsettings>
  <onaccesswakeup>
   <netinittimeout>60</netinittimeout>
   <netsettletime>500</netsettletime>
   <wakeup>
       <host>182.168.1.9</host>
       <mac>00:e0:4c:4b:30:9f</mac>
       <pingport>3306</pingport>
       <pingmode>1</pingmode>
       <timeout>600</timeout>
       <waitonline>38</waitonline>
       <waitonline2>40</waitonline2>
       <waitservices>0</waitservices>
   </wakeup>
</onaccesswakeup>
<videodatabase>
    <type>mysql</type>
    <host>192.168.1.9</host>
    <port>3306</port>
    <name>MyVideos</name>
    <user>kodi</user>
    <pass>kodi</pass>
  </videodatabase>
  <musicdatabase>
    <type>mysql</type>
    <host>192.168.1.9</host>
    <port>3306</port>
    <name>MyMusic</name>
    <user>kodi</user>
    <pass>kodi</pass>
  </musicdatabase>
  <videolibrary>
    <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
  </videolibrary>
  <loglevel>0</loglevel>
</advancedsettings>

Reindex Your Media Collection

Edit this file as necessary. You’ll have to set the IP address of the MySQL server and the name and password that KODI will use to access the database. Unfortunately, KODI chooses the name of the database, so you’re going to have to give the Kodi user pretty open access to your server. I’ve NEVER had a problem with it doing ANYTHING that it shouldn’t.

Now, back in your distro’s userdata directory, delete the file that contains the media sources, “sources.xml” and reboot.

Go through the “Add media sources…” again and THIS time, it will save the indexed metadata on your server. Every KODI in the house that has these two files in place will use the local database! When you scan for new media, every Raspberry will get updated!

Final note

You may have issues getting this to work. Make sure your “kodi” user has the rights to create new databases. If all else fails, turn on debugging in kodi and reboot and the log will have the connection transaction detail that you can use to noodle out what the issue is.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.