Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save BillyNate/556d1efda66617d84fa074d742b2aec2 to your computer and use it in GitHub Desktop.

Select an option

Save BillyNate/556d1efda66617d84fa074d742b2aec2 to your computer and use it in GitHub Desktop.
Kodi (OSMC) on Raspberry Pi 2 with Squeezelite, TVHeadend and proper CEC-on-off
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.powerkey" name="Custom powerkey handler">
<extension point="xbmc.python.script" library="script.py" />
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">Simple script for custom handling of the powerkey</summary>
<description lang="en_GB">Custom handling of the powerkey, to effectively use this add-on one needs to set it in the keymap</description>
<disclaimer lang="en"></disclaimer>
<platform>all</platform>
<language></language>
<license></license>
<forum></forum>
<website></website>
<source>https://gist.github.com/BillyNate/556d1efda66617d84fa074d742b2aec2</source>
<email></email>
<news></news>
<assets>
<icon></icon>
<fanart></fanart>
<screenshot></screenshot>
</assets>
</extension>
</addon>
# -*- coding: utf-8 -*-
import xbmc
import xbmcgui
tv_state = xbmcgui.Window(10000).getProperty('cec_status_0')
if tv_state not in [None, '']:
if tv_state == 'on':
xbmcgui.Window(10000).setProperty('cec_redirect', 'standby 5')
xbmc.executebuiltin('XBMC.RunScript(kodi.script.turnofflgtv)')
elif tv_state == 'standby':
xbmc.executebuiltin('ActivateWindow(busydialog)')
xbmcgui.Window(10000).setProperty('cec_redirect', 'on 0')
xbmc.executebuiltin('System.Logoff()')
xbmc.executebuiltin('Dialog.Close(busydialog)')
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.statechange" name="State change handler">
<extension point="xbmc.python.script" library="script.py" />
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">Handles the AVR and TV over HDMI-CEC on media state change</summary>
<description lang="en_GB">Handler for media state changes to control the AVR and TV. This add-on needs to be called by the kodi.callbacks add-on.</description>
<disclaimer lang="en"></disclaimer>
<platform>all</platform>
<language></language>
<license></license>
<forum></forum>
<website></website>
<source>https://gist.github.com/BillyNate/556d1efda66617d84fa074d742b2aec2</source>
<email></email>
<news></news>
<assets>
<icon></icon>
<fanart></fanart>
<screenshot></screenshot>
</assets>
</extension>
</addon>
# -*- coding: utf-8 -*-
import xbmc
import xbmcgui
# Get device states
tv_state = xbmcgui.Window(10000).getProperty('cec_status_0')
audio_state = xbmcgui.Window(10000).getProperty('cec_status_5')
# Split arguments ourselfes if not passed right:
args = sys.argv[1:]
if len(args) == 1:
args = args[0].split()
if args[0] == 'play' or args[0] == 'resume':
# If something starts playing turn AVR on, even if it is already on (just to make sure):
xbmcgui.Window(10000).setProperty('cec_redirect', 'on 5')
# If we're not dealing with music and the TV is off, turn it on:
if args[1] != 'music' and args[1] != 'audio' and tv_state != 'on':
xbmcgui.Window(10000).setProperty('cec_redirect', 'on 0')
# If the media stops or pauses while the TV is off, assume the AVR should be turned off as well:
elif (args[0] == 'pause' or args[0] == 'end') and tv_state == 'standby':
playing = False
# Check for 5 seconds long if the state remains non-playing:
for i in range(1,15):
if xbmc.Player().isPlaying() and not xbmc.getCondVisibility('player.paused'):
playing = True
break
xbmc.sleep(333)
# We can be pretty sure it is not a hickup in a music stream, so turn off the AVR:
if not playing:
xbmcgui.Window(10000).setProperty('cec_redirect', 'standby 5')

This is a description on how I got my Kodi (OSMC to be specific) set up on my Raspberry Pi. Documented here in case anything goes wrong and I got to do it all over again. Obviously this is not a headless installation, so a screen and a way to do some input it assumed 😉

Setup

  1. Get the latest RPi2 disk image from OSMC.tv, write the image to an (Micro)SD-card, put the card in the Pi and boot

  2. After the first boot it will ask to input the language, timezone, optionally a device name, SSH access (best to be turned on), network settings and what skin you like (I prefer to start with Classic). MySQL settings for the master profile can be set already as well

  3. Go to My OSMC -> Updates -> Manual controls, start a scan for updates and install if necessary

  4. Go to My OSMC -> Network to set a static ip if not done at first boot

  5. Go to System (settings) -> Live TV Settings -> Playback and disable Start playback minimised

  6. Go to System (settings) -> Service Settings -> Control to configure the web server (set username and password) and application control. Don't forget to turn on Allow remote control from application on other systems

    Now you should be able to control Kodi by using an app like Yatse

  7. Go to System (settings) -> Interface settings -> Screensaver and set the Screensaver mode to None

  8. Go to System (settings) -> System settings -> Display and set the Resolution to 1080p

  9. Go to System (settings) -> System settings -> Audio and

    1. Set Number of channels to match your hardware
    2. Turn off Send low volume noise (this really fucked up my AVR when on)
    3. Enable Allow Passthrough and flick on any audio stream the AVR understands
  10. Go to System (settings) -> System settings -> Input -> Peripherals -> CEC Adapter and turn Enabled off

Add MySQL connection

  1. Restore from previous Kodi setup:
    1. Open FileZilla and connect to the Pi
    2. Upload or create the /home/osmc/.kodi/userdata/advancedsettings.xml containing the information to connect to the MySQL database
    3. Restart the app (or reboot)
  2. Manually configure:
    1. Go to My OSMC -> Network -> MySQL
    2. Enable the databases you want and enter the configuration details

TVHeadend

  1. Go to My OSMC -> App store -> TVHeadend server -> Install and hit apply
  2. Open up the TVHeadend web interface (ip:9981) and enable the devices.
    Now either continue configuring in the interface...
    1. Fire up Putty and connect to the Pi
    2. Stop TVHeadend: sudo systemctl stop tvheadend
    3. Open FileZilla and connect to the Pi
    4. Upload the folder channel, input/dbv/networks
    5. Start TVHeadend: sudo systemctl start tvheadend
  3. ...or restore your backup:
    1. In the TVHeadEnd web interface go to Configuration -> DVB Inputs -> Networks, edit the existing network or create a new one with the correct Network ID: (for me that's 43136), Save
    2. Go to DVB Inputs -> Muxes and add a new mux with the correct Frequency and Symbol Rate (for me that's 164000000 and 6900000, set Scan status to PEND and create
    3. Scanning should start now automaticly, whait till it's finished
    4. If any muxes have FAILED as Scan result, select these and set the status to PEND again to force a rescan
    5. Go to DVB Inputs -> Services, all found services should be listed here
    6. Go to Channel / EPG and do a Map app services, you probably don't want to map the encrypted services
    7. Once the services are mappend it's time to set the correct numbers
  4. Go to Add-ons -> My add-ons -> PVR clients -> Tvheadend HTSP Client
    1. Configure it: set the Username and Password
    2. Enable
  5. Use FileZilla to upload the TV channel logo's to /home/osmc/tvlogos

SqueezeLite

  1. Install SqueezeLite using Putty: sudo apt-get install squeezelite
  2. Download the ARM version of SqueezeLite 1.8 from SourceForge
  3. Unpack the downloaded file: tar -xvzf squeezelite-1.8.x.xxx-armv6hf.tar.gz
  4. Optionally back-up the packaged binary: mv /usr/bin/squeezelite ~/squeezelite.backup
  5. Move the downloaded binary to the correct folder: mv -f squeezelite /usr/bin/squeezelite
  6. Edit the configuration: sudo nano /etc/default/squeezelite
    1. Optionally set the hostname
    2. Set the SB_EXTRA_ARGS to -C 10 -a 180
  7. Restart SqueezeLite: sudo systemctl restart squeezelite
  8. Download the repository from Marcel van der Veldt (using Putty): wget https://github.com/marcelveldt/repository.marcelveldt/raw/master/repository.marcelveldt/repository.marcelveldt-1.0.1.zip
  9. Go to Add-ons -> My add-ons -> .. -> Install from zip file -> Home folder and select the downloaded file
  10. Go to Add-ons -> My add-ons -> .. -> Install from repository -> Marcelveldt's -> Music add-ons -> Squeezebox for Kodi -> Install
  11. Once the add-on is installed go to Configure
  12. In Squeezelite turn on Do not auto start squeezelite
  13. In Putty do ifconfig eth0 and enter the HWAddr in Squeezelite -> Mac-address manually
  14. In LMS Server set the IP address of the LMS as the hostname

Proper CEC-Client support

  1. Download all the files in this gist either by using Git or by downloading as zip (wget -O BillyNateOSMCGist.zip https://gist.github.com/BillyNate/556d1efda66617d84fa074d742b2aec2/archive/master.zip) and unpacking it (unzip BillyNateOSMCGist.zip)
  2. If the files are in a subdiretory now, move the files: mv 556d1efda66617d84fa074d742b2aec2-master/* ./
  3. Make the shell script excecutable: sudo chmod +x move.sh
  4. Run the shell script: ./move.sh
  5. Download the LGTV turn off program add-on (because LG did not implement CEC support properly): wget -O kodi.screensaver.turnofflgtv.zip https://github.com/BillyNate/Kodi.Script.TurnOffLGTV/archive/master.zip
  6. Download the HDMI-CEC service add-on: wget -O service.cec.zip https://github.com/BillyNate/service.cec/archive/master.zip
  7. Go to Add-ons -> My add-ons -> .. -> Install from zip file -> Home folder and select the downloaded files
  8. Go to Add-ons -> My add-ons -> Program add-ons and Configure the LG add-on
  9. Go to Add-ons -> My add-ons -> Services and Configure the CEC add-on
  10. Go to Add-ons -> My add-ons -> Program add-ons and enable the Powerkey and State Change add-ons
  11. Go to Add-ons -> My add-ons -> .. -> Install from repository -> Kodi add-on repository -> Services -> Kodi callbacks -> Install
  12. Configure the add-on; add two tasks:
    1. Built-in: RunScript(kodi.script.turnofflgtv)
    2. Python: /home/osmc/.kodi/addons/script.stagechange/default.py
  13. Add the events:
    1. On idle time of 1800 seconds run task 1
    2. On any playback state change run task 2 and add the new state (play, resume, pause, end) as the first parameter and %mt as the second

More add-ons

  1. Install YouTube from Video add-ons
  2. Install Vimeo from Video add-ons
  3. Install Uitzendinggemist from Video add-ons
  4. Install Opensubtitles.org from Subtitles (though the one from their site is said to work better)

Create profiles

  1. Go to System (settings) -> Profile settings and add some profiles. Use the default directory and when asked to copy or start fresh, do a copy from default
  2. Open up the userdata directory of each profile (/home/osmc/.kodi/userdata/profiles/*) and upload the correct advancedsettings.xml, passwords.xml and sources.xml
  3. Log off the master profile, go into each profile and enable the previously installed add-ons
  4. Copy over the addon_data from each installed add-on from the master profile to the other profiles
  5. Copy over the keymap files from the master profile to other profiles

Even more add-ons (user specific)

  1. Install Autosub from Services, configure it to exclude Live TV and HTTP sources
  2. Install Trakt from Program add-ons and connect to your trakt.tv profile

Theme: Aeon MQ7

  1. Download the kodi-brasil repo from their website and install it from zip file
  2. Install the Aeon MQ 7 Krypton add-on from Kodi Brasil Forum Repository -> Look and feel -> Skin
  3. Install the Skin themes - Aeon MQ7 add-on from Kodi Brasil Forum Repository -> Look and feel -> Image collections
  4. Enable the new skin
  5. Go to Skin settings -> Themes and enable Darkness
  6. Copy over /home/osmc/.kodi/addons/resource.images.skinthemes.aeonmq/resources/darkness/programs.jpg to /home/osmc/.kodi/addons/skin.aeonmq7/backgrounds/vnodes.jpg
  7. If you want to be able to change the colors in the theme, you'll have to install the colorpicker add-on
  8. If you ever want to change the background of the profile overview, you'll need to change /home/osmc/.kodi/addons/skin.aeonmq7/backgrounds/vnodes.jpg

Change the boot splash image

  1. Put a splash.png in the home directory
  2. sudo mv /usr/splash.png /usr/splash.old.png
  3. sudo mv splash.png /usr/splash.png

Notes

  • I ended up setting Aeon MQ7 for all profiles, but somehow the skin settings get mixed up when (un)loading the profiles. To fix this I've set the settings.xml (in addon_data/skin.aeonmq7) to read-only (444) and set the CustomMyTheme in settings.xml to special://profile/backgrounds/ with a background directory in each profile
BASE='/home/osmc/.kodi'
for FILENAME in *.{py,xml}
do
MOVETO=$(echo "$FILENAME" | tr '_' '/')
DIR=$(dirname "${MOVETO}")
#echo "$BASE/$DIR -> $BASE/$MOVETO"
mkdir -p "$BASE/$DIR"
mv "$FILENAME" "$BASE/$MOVETO"
done
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file contains the mapping of keyboard keys to actions within Kodi. -->
<!-- -->
<!-- The format is: -->
<!-- <window> -->
<!-- <device> -->
<!-- <button>action</button> -->
<!-- </device> -->
<!-- </window> -->
<!-- -->
<!-- The <global> section is a fall through - they will only be used if the button is -->
<!-- not used in the current window's section. -->
<!-- -->
<!-- Actions can be built-in functions. -->
<!-- eg <B>ActivateWindow(Music)</B> -->
<!-- would automatically go to Music on the press of the B button. -->
<!-- -->
<!-- Long presses -->
<!-- A limitation is that if a single press is mapped in a section, a global "longpress"-->
<!-- will be ignored. The workaround is to duplicate the long mapping in the section. -->
<!-- -->
<!-- An empty action removes the corresponding mapping from default and parent keymaps. -->
<!-- This is different from a "noop" action, which disables a button. -->
<!-- -->
<!-- More documentation on keymaps can be found on http://kodi.wiki/view/keymaps -->
<keymap>
<global>
<keyboard>
<s>RunScript(script.powerkey)</s>
</keyboard>
</global>
<FullscreenVideo>
<keyboard>
<backspace>Stop</backspace>
</keyboard>
</FullscreenVideo>
<Screensaver>
<remote>
<power>Close</power>
</remote>
</Screensaver>
</keymap>
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file contains the mapping of remote keys to actions within Kodi. -->
<!-- -->
<!-- The format is: -->
<!-- <window> -->
<!-- <device> -->
<!-- <button>action</button> -->
<!-- </device> -->
<!-- </window> -->
<!-- -->
<!-- The <global> section is a fall through - they will only be used if the button is -->
<!-- not used in the current window's section. -->
<!-- -->
<!-- Actions can be built-in functions. -->
<!-- eg <B>ActivateWindow(Music)</B> -->
<!-- would automatically go to Music on the press of the B button. -->
<!-- -->
<!-- An empty action removes the corresponding mapping from default and parent keymaps. -->
<!-- This is different from a "noop" action, which disables a button. -->
<!-- -->
<!-- More documentation on keymaps can be found on http://kodi.wiki/view/keymaps -->
<keymap>
<global>
<remote>
<power>RunScript(script.powerkey)</power>
</remote>
</global>
<FullscreenVideo>
<remote>
<back>Stop</back>
</remote>
</FullscreenVideo>
<systeminfo>
<remote>
<power>ActivateWindow(startwindow)</power>
</remote>
</systeminfo>
</keymap>
@BillyNate
Copy link
Author

In order to get the Netflix plugin running in OSMC-KODI18 follow the steps outlined in asciidisco/plugin.video.netflix#665 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment