Kodi

From ParabolaWiki
Jump to: navigation, search
Note: XBMC rebranded to Kodi starting with the version 14 release.

Kodi is a free software (GPL) multimedia player that originally ran on the first-generation XBox, (not the newer Xbox 360), and now runs on devices running GNU/Linux, Mac OS X, Windows, Android and iOS. Kodi can be used to play/view the most popular video, audio, and picture formats, and many more lesser-known formats, including:

  • Video - DVD-Video, VCD/SVCD, MPEG-1/2/4, DivX, XviD, Matroska
  • Audio - MP3, AAC.
  • Picture - JPG, GIF, PNG.

These can all be played directly from a CD/DVD, or from the hard-drive. Kodi can also play multimedia from a computer over a local network (LAN), or play media streams directly from the Internet. For more information, see the Kodi FAQ.

As of version 12, it can also be used to play and record live TV using a tuner, a backend server and a PVR plugin; more information about this can be found on the Kodi wiki.

1 Installation

Install the kodi package from the official repositories. Be sure to install the optional dependencies listed by pacman that apply to your specific use-case.

2 Configuration

2.1 Autostarting at boot or ondemand

The kodi package supplies a stand-alone wrapper script /usr/bin/kodi-standalone that allows a minimal system to run the application without a full blown DE. There are several methods to enable it described below.

Warning: Select only one of the methods listed below to Users enable this functionality!

2.1.1 Kodi-standalone-service

The kodi-standalone-service package in the pcr repo, will provide kodi.service and will create the needed user to run Kodi in standalone mode. This is a drop-in replacement of the package-legacy systemd service and post install script which Parabola developers have removed from the package when the Xorg package updated to 1.16. Functionally, there is no difference.

Start kodi.service and enable it to run at boot time.

2.1.2 Xsession with LightDM

Note: This assumes that the user has created an kodi user on the system.

To use LightDM with automatic login, see LightDM#Enabling_autologin. Kodi includes kodi.desktop as xsession.

/etc/lightdm/lightdm.conf
[LightDM]
minimum-vt=1
run-directory=/run/lightdm

[SeatDefaults]
session-wrapper=/etc/lightdm/Xsession
pam-service=lightdm-autologin
autologin-user=kodi
autologin-user-timeout=0
user-session=kodi

2.1.3 Socket activation

Socket activation can be used to start Kodi when the user starts a remote control app or on a connection to Kodi's html control port. Start listening with systemctl start kodi@user.socket (replace user with the user running Kodi to be started as). Depending on the setup, the port in kodi@.socket might need to be changed.

/etc/systemd/system/kodi@.service
[Unit]
Description=Launch Kodi on main display

[Service]
Type=oneshot
Environment=DISPLAY=:0.0
Nice=-1
ExecStart=/usr/bin/su %i /usr/bin/kodi
ExecStartPost=/usr/bin/bash -c "sleep 15 && systemctl start kodi@%i.socket"

[Install]
WantedBy=multi-user.target
/etc/systemd/system/kodi@.socket
[Unit]
Conflicts=kodi@%i.service

[Socket]
# listen for WOL packets
#ListenDatagram=9

# change this to Kodi's http control port
ListenStream=8082

[Install]
WantedBy=sockets.target

2.2 Sharing a database across multiple nodes

One can easily configure Kodi to share a single media library (video and music). The advantage of this is that key metadata are stored in one place, and are shared/updated by all nodes on the network. For example, users of this setup can:

  • Stop watching a movie or show in one room then finish watching it in another room automatically.
  • Share watched and unwatched status for media on all nodes.
  • Simplify the setup with only a single library to maintain.

Several key things are needed for this to work:

  • Network exposed media (via protocols that Kodi can read, e.g. NFS or Samba).
  • A MySQL server.
Note: The following guide is only an example of one configuration and is not meant to be limiting but illustrative. Key steps are shown but a detailed discussion is not offered.

These assumptions are used for the guide, substitute to reflect your setup:

  • The media is located under following mount points: /mnt/tv-shows /mnt/movies /mnt/music.
  • The network addresses of all nodes are within the 192.168.0.* subnet range.
  • The user wishes to use NFSv4 exports.
  • The IP address of the machine running both the NFS exports and the MySQL database is 192.168.0.105.
  • Each Kodi box is referred to as a node.
  • The GNU/Linux user running Kodi is 'kodi' on all nodes.

For additional info, refer to the official Kodi wiki.

2.2.1 Setup an NFS server

This section provides an example using NFS exports (NFSv4), but as mentioned above, any protocol that Kodi can read is acceptable.

Note: Users only need one box on the LAN to serve the content, therefore, do not repeat this for each node. The following example assumes the user is running Parabola, but any NFS server will work, be it GNU/Linux or BSD, etc.

The NFS server is provided by nfs-utils and this only needs to be installed on the box serving up the content.

Setup the shares:

# mkdir -p /srv/nfs/{tv-shows,movies,music}
# mount --bind /mnt/tv-shows /srv/nfs/tv-shows
# mount --bind /mnt/movies /srv/nfs/movies
# mount --bind /mnt/music /srv/nfs/music

Add the corresponding entries for these bind mounts to /etc/fstab:

...

/mnt/tv-shows /srv/nfs/tv-shows none bind 0 0
/mnt/movies /srv/nfs/movies none bind 0 0
/mnt/music /srv/nfs/music none bind 0 0

Share the content in /etc/exports:

/srv/nfs 192.168.0.0/24(ro,fsid=0,no_subtree_check)
/srv/nfs/tv-shows 192.168.0.0/24(ro,no_subtree_check,insecure)
/srv/nfs/movies 192.168.0.0/24(ro,no_subtree_check,insecure)
/srv/nfs/music 192.168.0.0/24(ro,no_subtree_check,insecure)
Tip: This example sets-up read-only exports. See man exports for additional options and configurations.

Whenever changes are made to /etc/exports, always refresh the exports:

# exportfs -rav

Start nfs-common.service and enable it to run at boot time.

Optionally check with:

# showmount -e localhost
Export list for localhost:
/srv/nfs/tv-shows 192.168.0.0/24
/srv/nfs/movies 192.168.0.0/24
/srv/nfs/music 192.168.0.0/24
Note: If the box is using a firewall, ensure that it is not blocking connections. This is beyond the scope of this article.

2.2.2 Install and setup the MySQL server

The box running the library needs to be available 24/7 and is commonly the same box that holds the media.

Note: The following example assumes the user is running Parabola, but any MySQL server will work, be it GNU/Linux or BSD, etc.

The MySQL server is provided by mariadb and this only needs to be installed on one box that all nodes can access.

Start mysqld.service and enable it to run at boot time.

First time setup:

# mysql_secure_installation
   <<follow the in-script prompts and answer "Y" to all the questions>>
$ mysql -u root -p
   <<enter the mysqld root password assigned in the first step>>
MariaDB [(none)]> CREATE USER 'kodi' IDENTIFIED BY 'kodi';
MariaDB [(none)]> GRANT ALL ON *.* TO 'kodi';
MariaDB [(none)]> \q

No other setup to the MySQL server should be needed.

Note: If the box is using a firewall, ensure that it is not blocking connections. This is beyond the scope of this article.

2.2.3 Setup Kodi to use the MySQL library and the NFS exports

Since this example makes use of NFS shares, an optional dependency of Kodi is now required to access them. Ensure that each of the Kodi nodes has libnfs installed.

2.2.3.1 Setup Kodi to use the common MySQL database

To tell Kodi to use the common database, insure that Kodi is not running, then create the following file:

~/.kodi/userdata/advancedsettings.xml
<advancedsettings>
  <videodatabase>
    <type>mysql</type>
    <host>192.168.0.105</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </videodatabase>

  <musicdatabase>
    <type>mysql</type>
    <host>192.168.0.105</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </musicdatabase>

  <videolibrary>
    <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
  </videolibrary>
</advancedsettings>
Tip: If using kodi-standalone-service, the default for the profile is /var/lib/kodi/.kodi and be sure to chown the newly created file to the kodi user and group, i.e. # chown -R kodi:kodi /var/lib/kodi
2.2.3.2 Setup network shares
Warning: This only needs to be done once, on only one of the nodes. Once completed, configuration of subsequent nodes is a drop-in operation of ~/.kodi/userdata/advancedsettings.xml; no other configuration is needed!
Note: Even if Kodi is running on the same box that is also running the NFS exports and MySQL server, one MUST setup the media using the nfs shares only!

Load Kodi and define the network shares that correspond to the exports by browsing to the following within the interface:

Video>Files>Add Videos>Browse>Network Filesystem(NFS)

After a few seconds, the IP address corresponding to the NFS server should appear.

Select "/srv/nfs/tv-shows" from the list of share and then "OK" from the menu on the right. Assign this share the category of "TV Shows" to setup the appropriate scraper and to populate the MySQL database with the correct metadata.

Repeat this browsing process for the "movies" and "music" and then exit Kodi once properly configured. At this point, the MySQL tables should have been created.

2.2.4 Cloning the configuration to other nodes on the network

Setting up another Kodi node on the network to use this library is trivial. Simply copy ~/.kodi/userdata/advancedsettings.xml to that box and restart Kodi.

Note: There is NO need to do any other setup steps to define the sources since the nfs exports, the metadata for the programming, any stop/start times, view status, etc. are all stored in the MySQL tables. If problems are encountered after this file is added to the profile directory and after Kodi is restarted, it is recommended to simply re-create the Kodi profile on that node, and again copy over the advancedsettings.xml file. This way, only a trivial amount of configuration to the GUI itself is required which is often easier than troubleshooting conflicting local databases, sources, and the like.

2.3 Using a remote control

As Kodi is geared toward being a remote-controlled media center; any PC with a supported IR receiver/remote, can use remote using LIRC or using the native kernel supported modules. To work properly with Kodi, a file will be required that maps the lirc events to Kodi keypresses. Create an XML file at ~/.kodi/userdata/Lircmap.xml (note the capital 'L').

Note: Users running Kodi from the included service file will find the kodi home (~) under /var/lib/kodi and should substitute this in for the shortcut above. Also make sure that if creating this file as the root user, it gets proper ownership as kodi:kodi when finished.

Lircmap.xml format is as follows:

<lircmap>
  <remote device="devicename">
      <XBMC_button>LIRC_button</XBMC_button>
      ...
  </remote>
</lircmap>
  • Device Name is whatever LIRC calls the remote. This is set using the Name directive in lircd.conf and can be viewed by running $ irw and pressing a few buttons on the remote. IRW will report the name of the button pressed and the name of the remote will appear on the end of the line.
  • XBMC_button is the name of the button as defined in keymap.xml.
  • LIRC_button is the name as defined in lircd.conf. If lircd.conf was autogenerated using # irrecord, these are the names selected for the buttons. Refer back to LIRC for more information.
  • A very thorough Lircmap.xml page over at the Kodi Wiki should be consulted for more help and information on this subject as this is out of scope of this article.

2.3.1 MCE remote with Lirc and Systemd

Install lirc-utils and link the mce config:

# ln -s /usr/share/lirc/mceusb/lircd.conf.mceusb /etc/lirc/lircd.conf

Then, make sure the remote is using the lirc protocol:

$ cat /sys/class/rc/rc0/protocols

If not, issue:

# echo lirc > /sys/class/rc/rc0/protocols

A udev rule can be added to make lirc the default. A write rule does not seem to work, so a simple RUN command can be executed instead.

/etc/udev/rules.d/99-lirc.rules
KERNEL=="rc*", SUBSYSTEM=="rc", ATTR{protocols}=="*lirc*", RUN+="/bin/sh -c 'echo lirc > $sys$devpath/protocols'"

Finally, enable and start the lirc service. As of lirc 0.9.1 the appropriate service is lircd.socket, not lircd.service:

# systemctl enable lircd.socket
# systemctl start lircd.socket

This should give a fully working mce remote.

2.3.2 HDMI-CEC with Pulse Eight USB-CEC

An elegant way of getting remote functions in Kodi is using CEC, a protocol that is part of the HDMI specification. Most modern TVs support CEC, although some manufacturers advertise the feature under other names. Apart from a CEC-enabled TV some hardware that takes the CEC signals coming from the TV and present them in a way that Kodi can understand is also needed. One such device is the USB-CEC adapter from Pulse Eight. Hooking up the USB-CEC is pretty simple, but in order for it to work in Parabola we have to do a few things.

Install libcec.

When connected, the USB-CEC's /dev entry (usually /dev/ttyACM*) will default to being owned by the uucp group, so in order to use the device the user running Kodi needs to belong to that group. The user also needs to belong to the lock group, otherwise Kodi will be unable to connect to the device. To add a user to both groups, run

# usermod -aG uucp,lock [username]

If more than one user uses Kodi, repeat the command for all those users. If, for example, one is using kodi-standalone, the relevant command is

# usermod -aG uucp,lock kodi

Remember that modifying the groups of any logged in users means those users need to log out and login again in order for the changes to take effect.

Note: Trying to use the USB-CEC without belonging to above groups may lead to problems, including Kodi crashes, so make sure the correct user belongs to both groups.

3 Tips and Tricks

3.1 Fixing the Wunderground Weather Add-on

The wunderground now requires users to have an API key in order to receive weather data. An API key is available free of charge for kodi users. To obtain a key, and to configure the add-on follow these steps:

  1. Sign up for an API key at wunderground's automated system.
  2. Format the key for kodi's wunderground.py script (it expects the key to be reversed and base64 encoded, see below).
  3. Enter the formatted key into WAIK variable in ~/.kodi/addons/weather.wunderground/resources/lib/wunderground.py

To reverse and base64 encode the API key, run this two-liner using your own API key in the "key" variable.

$ key=9cc49125b91eb85a
$ echo $key|rev|base64
YTU4YmUxOWI1MjE5NGNjOQo=

For this example key, the first few lines of ~/.kodi/addons/weather.wunderground/resources/lib/wunderground.py would look like this:

# -*- coding: utf-8 -*-

import urllib2, gzip, base64
from StringIO import StringIO

WAIK             = 'YTU4YmUxOWI1MjE5NGNjOQo='

3.2 Fullscreen mode stretches Kodi across multiple displays

For a multi-monitor setup, Kodi may default to stretching across all screens. One can restrict the fullscreen mode to one display by setting the environment variable SDL_VIDEO_FULLSCREEN_HEAD to the number of the desired target display. For example, having Kodi show up on display 0, add the following line to the Kodi user's Bashrc:

SDL_VIDEO_FULLSCREEN_HEAD=0
Note: Mouse cursor will be held inside screen with Kodi.

3.3 Video tearing on Intel HD Graphics

Users observing tearing when watching a movie try this: https://bbs.archlinux.org/viewtopic.php?id=176651

3.4 Slowing down CD/DVD drive speed

The eject program from the util-linux package does a nice job for this, but its setting is cleared as soon as the media is changed.

This udev-rule reduces the speed permanently:

/etc/udev/rules.d/dvd-speed.rules
KERNEL=="sr0", ACTION=="change", ENV{DISK_MEDIA_CHANGE}=="1", RUN+="/usr/bin/eject -x 2 /dev/sr0"

Replace sr0 with the device name of the optical drive. Replace -x 2 with -x 4 if the preference is 4x-speed instead of 2x-speed.

After creating the file, reload the udev rules with

# udevadm control --reload

3.5 Use port 80 for webserver

Kodi has a webservice that allows interaction through a web-interface. By default, it uses port 8080 as 80 requires root privileges. Use the following to permit it to use low port numbers:

 # setcap 'cap_net_bind_service=+ep' /usr/lib/kodi/kodi.bin

Restart kodi.service and set port 80 in the configuration menu (Services->Webserver->Port).

3.6 Using ALSA

If PulseAudio does not work properly, try using ALSA directly by starting Kodi with the AE_SINK=ALSA environment variable.

3.7 Soft subtitles not displaying

The ffmpeg package is used to extract the subtitles.

4 See also

  • Kodi Wiki - Excellent resource with much information about Parabola specifically

5 Acknowledgement

This wiki article is based on ArchWiki. We may have removed non-FSDG bits from it.