How to use two TVHeadEnd backends with Kodi

Most people consider themselves lucky if they can get one PVR backend to work, but sometimes it makes things easier if you can run two different TVHeadEnd backends and let Kodi access both of them.  Unfortunately, Kodi works best with a single PVR backend, although that seems to be less true in Kodi Isengard than in previous versions.

Why would you want to run two different backends?  There are many reasons, but a primary one is proximity to an antenna or satellite dish.  As just one example, say you want to receive terrestrial television signals using a TV tuner card or device, and also satellite signals from your satellite dish, but the two are nowhere near each other.  Maybe your antenna is located right next to your house, but in order to clear a hill or other obstruction, your dish has to be placed several hundred feet away.  You don’t want to run several hundred feet of RG-6 cable if you can help it, because the signal loss would be quite significant.  A better solution would be to place a backend server in some kind of climate controlled (or at least waterproof) enclosure near the dish, and then connect that server to your local network using a fiber optic cable.  But you’d also need a second backend server at your house, to receive signals from your antenna (well, unless you are using networked tuners such as HDHomeRun devices from SiliconDust, but this is just an example).

Note that some people actually have a second TVHeadEnd backend at a completely separate geographical location, maybe in another city, or even another state or country, and connect to it over the Internet.  But, I don’t recommend that unless you’re not subject to ISP usage caps at either end, or you use compression (but that’s beyond the scope of this article).  And anyway, that’s the beauty of receiving signals from the satellites – they can be viewed from a very wide geographic area, as long as there aren’t any obstructions between your dish and the satellite.

Whatever the reason you need two backends, Kodi doesn’t give you a readily apparent way to use both easily.  However, there is a method that works in some Kodi and XBMC installations.  I don’t know why it works great on some systems and not so well others, all I can suggest is that if you find yourself with this need, try this and see what happens.

Note that I am only giving instructions here for Linux and OS X systems.  It should also be possible to do this on other platforms, but since I don’t use those, I don’t know the correct paths.

In Linux, copy /usr/share/kodi/addons/pvr.hts to pvr.hts2 in the same (/usr/share/kodi/addons/) directory.  You will have to be a system administrator to do this (use sudo).  The .hts2 ending is somewhat arbitrary; you could also call it something descriptive like pvr.htsantenna if you like, but if you change it make sure you follow that same naming convention everywhere.  I’ll assume you’ve used pvr.hts2 for the balance of these instructions.  In OS X you do the same thing, except the original file is at /Applications/ and again you make a copy in the same directory.  Note that you are copying an entire directory, not an individual file.  I tend to do things like this in Midnight Commander because I find it easier than trying to remember the correct Linux command line syntax, but if you are a command line devotee you’re welcome to do it from there.

Next, change to the copied directory (pvr.hts2 in this example) and find a file inside named addon.xml.  You want to edit this file, so do something like sudo nano addon.xml (or use your favorite text editor, or highlight the file and press F4 inside Midnight Commander), and change two values, specifically the “id” and “name” strings.  Change the id to match the name of the newly-copied directory (pvr.hts2 in this example), and change the “name” to somehow differentiate the copied addon from the original.  For example, you could add the word (antenna) or (satellite) to the end of the string.

You should do the following steps as a user: In Linux, copy the ~/.kodi/userdata/addon_data/pvr.hts directory to pvr.hts2, or in OS X copy the ~/Library/Application Support/Kodi/userdata/addon_data/pvr.hts to pvr.hts2.  In both cases, the copied directory should be in the same directory as the original, similar to the way you did it in the first step but don’t do it as an administrator, in other words, don’t use sudo.

Now go into the directory you just copied and edit the settings.xml file (same as the way you edited addon.xml but again don’t do it as an administrator).  You will likely need to edit the “host” value to point to your second backend, and you may also need to edit the “pass” and “user” values if the backend requires a username or password for access.  Note you can also change these items from inside Kodi using the second addon’s configuration page, if you prefer, but it’s probably better to at least change the host address before you start it up so you don’t have two addons trying to access the same server.

In many cases, this is all you need to do, other than go into Kodi’s PVR addons and make sure that both are enabled and have the correct configuration settings.  You will see your channel list populated with channel numbers from both backends, and you will see recordings from both backends, etc.  But on some Linux-based systems, there is one additional directory that must be copied, as an administrator.  This directory is at /usr/lib/kodi/addons/pvr.hts and you’d again copy the entire pvr.hts directory to pvr.hts2 in the same (/usr/lib/kodi/addons) directory.  I have no idea why this additional step is necessary with some systems but not others.  And this doesn’t seem to apply to OS X – if there’s an equivalent directory there, I haven’t been able to find it.

As I noted, this same technique should work with Kodi on other platforms if you can find the correct equivalent directories.  Note that you will need to repeat these steps any time you upgrade Kodi to a newer version, unless you are using Linux.  Under Linux, you will need to repeat these steps only when the TVHeadEnd PVR addon is updated.  And in either case you will likely only need to repeat the steps that require administrator access; the settings in the userdata directory shouldn’t be affected by a software update.

It goes without saying that I do not guarantee this will work.  I’m not a programmer, so if it doesn’t work for you, all I can suggest is you go into the Kodi PVR forum and add your support to this thread, which actually provided some of the information in this article.


How to view ATSC closed captions (where available) in Kodi using a MCE-compatible remote

Because most of the free-to-air satellite feeds in North America aren’t intended for direct home viewing, not all of them will have closed captions enabled.  But, many feeds do include closed captions, and since most PVR backend software (including TVHeadEnd) save these as part of the transport stream (.ts) recordings, Kodi version 15 (“Isengard”) is capable of displaying them, when they’re available.  The support isn’t perfect yet (it’s especially irritating that words with apostrophes are often displayed with double quotes in place of the apostrophe) but it’s present in the newest Kodi versions (at least in the Linux version of the Kodi software).  You can toggle the closed captions on and off from the On-Screen Display, but if you have a Windows MCE compatible remote, you may find it a bit frustrating that pressing the “Closed Caption” or “Teletext” button only brings up a message saying “Teletext not available.”

A recent post on the Kodi forum provides a solution to this:

Go to your Kodi userdata/keymaps directory (~/.kodi/userdata/keymaps in Linux, ~/Library/Application\ Support/Kodi/userdata/keymaps in OS X, I don’t know where it is on other platforms) and see if there’s file called remote.xml there. If so, you will want to add the following lines to it (except for the first line if it’s already there); if not, create a new file with that name and edit it to contain all of this:

<?xml version="1.0" encoding="UTF-8"?>

Save the edited file. Now you should be able to toggle ATSC closed captions using the Teletext button on your remote, without needing to go into the OSD.

I tested this and it seems to work, but not on every satellite feed.  I have no idea why it works on some feeds, but not others, other than that some feeds either don’t include the closed captions, or they include them in a non-standard manner (one that their decoders at their local affiliates know how to deal with).

If you try this on your system and it doesn’t work, it may be that ATSC closed caption support isn’t properly implemented yet in your version of Kodi, particularly if you are not running under Linux or Windows. Or, it may be that the “Closed Captions” or “Teletext” button on your remote is sending something other than “Teletext”.  In Linux, if you run the irw program from the Linux command prompt, and then press the button on the remote, it should show you what that button is sending.  On my system it looks like this:

~$ irw
000000037ff07ba5 00 Teletext mceusb
000000037ff07ba5 01 Teletext mceusb

(Press Control-C to exit irw.) Don’t worry if more than one line appears for a single button press, but if the button shows anything other than Teletext, substitute that in place of “teletext” in the line <teletext>ShowSubtitles</teletext>. If pressing the button gives no response at all, then this technique won’t work until you can figure out how to get your system to recognize that button, which is beyond the scope of this article.