Hackviking He killed Chuck Norris, he ruled dancing so he took up a new hobby…

20Mar/170

Kodi central db backup

Using a central database for all your Kodi media players is convenient. Only one of them need to scan for new content or you can even update the database straight away. It holds state across all the devices like paused movies, watched episodes etc. If you have a large library it takes time to scan it all again so you should keep it backed up. I didn't but now I do!

Continue reading...

14Jun/160

Control Kodi with your TV-remote without CEC

HDMI-CEC is a wonderful thing when you have it! It enables your TV to relay control signals over the HDMI cable which gives you the ability to control your Kodi mediaplayer, or similar device, with your TV remote. Unfortunately not all TV's support this and that leaves you with a few options with disadvantages.

The smart phone apps available for controlling Kodi are good, no question about it. But every time I put on my TV I need to find my smartphone or tablet and make sure I'm on the correct wifi. Call me old fashioned but I like the TV as a semi stand alone device if you know what I mean.

Secondary remotes come in a number of different types. There are the regular IR based once that require additional hardware, if you don't have IR reception on your device. Since all my Kodi boxes are Raspberry Pi based I need additional hardware. There is also stand alone remotes connected to wifi ro Bluetooth which are pretty good but expensive. As soon as your dog, child or other semi destructive member of your household get their hands on it will be broken or gone.

As I mentioned before you need additional hardware on the Raspberry Pi to support a remote control unless it's communicating over the HDMI port. I also want a cheap solution that I can easily replace if damaged or lost. And if possible I don't want a second remote control for my TV setup. Here comes Flirc and saves the day!

Flirc is a programmable USB IR-receiver that can be used with any remote control! It even has a profile for Kodi in it's setup application. It's usually recommended for Kodi users in combination with a standard Apple TV remote. Even if I like the Apple TV remote it's still a second remote. There are a number of unused buttons on any TV remote that can be programmed into the Flirc. In my case I realized that the up, down, right and left keys on my TV remote, that are crucial for Kodi operations, where unused while not in the menu system of my TV. If I tried to use them without the menu open there where no response from the TV at all.

The setup of the Flirc is really easy! Just connect it to your computer and download the software, select the profile and then program the buttons you want. Then just unplug it and connect it to your Kodi box. It is also very sensitive for IR-signals, all my Raspberry Pi's are strapped to the back of my TV furniture but thanks to my white walls the IR-signal bounces in there and are picked up without any problem.

It's currently priced under $23 on Amazon and really worth it. It can be used with any remote and you can replace your TV set and just reprogram it if needed.

 

3Jun/160

HifiBerry Dac on Raspberry Pi OpenElec Kodi

Have been experiencing static noise from the analog output on my Raspberry Pi for some time. Tested several different power sources and it came to a point where I wasn't sure if the noise has always been present or not. In the end I got a HifiBerry Dac+ and some decent cables and the issue went away. The installation was really easy and well documented in the HifiBerry Knowledge base. In the video above you can see the difference, I very much recommend this!

16Feb/160

Raspberry PI: Central kodi database

When you run more then one Kodi device with a shared media repository you should also run a shared library. With a shared library you only need to update the library on one of the Kodi devices when new media is added. There are a few other great benefits of running a shared library like the ability to stop media on one device and continue watching on another. It will also show what has been watched regardless of which device you actually watched it on. I run OpenELEC on Raspberry Pi's for all my media stations so this guide is focused on a Raspberry Pi implementation but the principal is the same for all devices capable of running Kodi and MySQL.

Preparations

Download the latest raspian image from https://www.raspberrypi.org/downloads/raspbian/ and put it on an sd-card with Win32DiskImager. Then put the sd-card in the Raspberry Pi and power it on. You can connect a monitor, mouse and keyboard for the initial setup. I usually just wait for it to boot up and check my routers DHCP list for it to show up and connect to it over SSH. This article is based on SSH terminal access but you can do the same on the Pi with a connected monitor.

Basic setup of the Raspberry Pi

First we need to configure the Raspberry Pi. Connect over SSH and login as pi with password raspberry. We want to:

sudo raspi-config
  • Expand Filesystem - Expand the pi file system to use the entire SD-card.
  • Change User Password - Change the default raspberry password for the pi user.
  • Boot Options - Select B1 Console - Text console, requiring user to login
  • Advanced - Some additional settings
    • Hostname - Select a hostname for your pi. I user PISRV
    • Memory Split - Set to 16 since we will not use a monitor or run any other graphics on this machine.
  • Finish - Exit the raspi-config and reboot.

When the pi has booted up again we can login with our new password we configured. When in the console run:

sudo apt-get update

Update the package lists from all the repositories.

sudo apt-get dist-upgrade

Upgrade all installed packages.

Install MySQL

Install MySQL server. It will ask you to select a root password.

sudo apt-get install mysql-server

We need to be able to access the MySQL server from other locations then localhost. Open up the MySQL config file.

sudo nano /etc/mysql/my.cnf

And change:

bind-address = 127.0.0.1

To:

bind-address = 0.0.0.0

Then restart the MySQL server.

sudo /etc/init.d/mysql restart

Setup the databases

Now we need to setup the databases for our video and music library. Login to MySQL, you will be prompted for your password.

mysql -uroot -p

What ever you do don't create any databases. Kodi will use the name that we supply later but just as a prefix, it will add an additional identifier. We need to create a user for the kodi machines. You can use whatever username and password you like but once again make a note of it.

 CREATE USER 'kodi' IDENTIFIED BY 'password';

The first time Kodi connects it needs to be able to create it's databases, we need to grant the account full access. We will lock that down later to secure our MySQL if we want to use it for other things then Kodi as well.

GRANT ALL ON *.* TO 'kodi';

Test to connect to the database from another machine. Either via MySQL command line tool, the same we used on the Pi, or download MySQL Workbench and test the connection. If all is working just type quit and press enter to return to the main shell.

Setup kodi

Then we need to make a backup of our current media library. I'm using OpenELEC but most Kodi versions should be the same. In the Kodi UI goto System/Settings -> Video -> Library and select Export library. If you don't see the last options make sure that Settings Oprions is set to Advanced in the lower left corner of the screen. Select Multiple files, this will create .nfo files along side all the media files. I already use this setup since I scan all my libraries With local information only. This is by far the safest way to migrate your library otherwise you have to scrape all the media again. So if you use local information only on your scrapes your good to go. Otherwise do the export!

Now we need to setup Kodi to use the MySQL server. Connect to the Kodi with SSH, username and password depends on the distribution you used to install your Kodi. The location of the userdata folder also varies from different distributions. I have one XBMC installed on a Raspberry Pi where the path is /home/pi/.kodi/userdata. On the OpenELEC installs I'm doing this for the userdata folder is located in /storage/.kodi/userdata/.

When you have found the folder you need to create a file named advancedsettings.xml. You can also do this via smb share if that is enabled on your Kodi machine. I prefer to do it over SSH to prevent any encoding issues. If you want to you can try it out by going \\{ip of kodi}\userdata.

sudo advancedsettings.xml

In this file we will put the configuration for accessing our MySQL server.

<advancedsettings>
  <videodatabase>
    <type>mysql</type>
    <host>{IP address or FQDN of your MySQL server}</host>
    <port>3306</port>
    <name>{prefix of your db name, I used kodi_video}</name>
    <user>kodi</user>
    <pass>{password you selected}</pass>
  </videodatabase> 
  <musicdatabase>
    <type>mysql</type>
    <host>{IP address or FQDN of your MySQL server}</host>
    <port>3306</port>
    <name>{prefix of your db name, I used kodi_music}</name>
    <user>kodi>/user>
    <pass>{password you selected}</pass>
  </musicdatabase>
  <videolibrary>
    <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
  </videolibrary>
</advancedsettings>

Save the file and reboot your Kodi machine. Depending on distribution you may need to do sudo reboot. Once it recycles you can scan your locations again, it will use the local .nfo files you already had or the once created during your export.

Securing MySQL again

We don't want the kodi MySQL user to have full access going forward. If your not using your MySQL for anything else then you can leave it be, but I want to secure mine. So back to the SSH console on the MySQL server.

mysql -uroot -p

You will once again be prompted for your MySQL root password and then dropped into the MySQL console. So now we check the name of the databases.

mysql&amp;amp;amp;gt; show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| kodi_music52 |
| kodi_video93 |
| mysql |
| performance_schema |
+--------------------+
5 rows in set (0.00 sec)

So we have the kodi_ databases named after the <name> parameter in our advancedsettings.xml. Now we revoke all the access we gave the kodi account.

REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'kodi';

And then only grant it full access to the two kodi_ databases.

GRANT ALL ON `kodi%`.* TO 'kodi';
flush privileges;

Setting up the other Kodi

Once all this is up and running setting up the second one is really easy. If you enabled SMB shares on OpenELEC like I did you just connect to the first kodi like \\kodi\UserData copy the advancedsettings.xml and sources.xml to the other kodies UserData share. If you don't have SMB enabled you have to edit the files via SSH.