MythTV UPnP Conflicts with XBMC UPnP
Running the MythTV backend and XBMC/Kodi is a fairly standard home entertainment system configuration for cord-cutters like myself who favor the Mac OS X platform over Windows. (One of these days, perhaps I’ll write a post explaining how easy this is to set up). However, the two conflict when it comes to their respective UPnP servers. MythTV UPnP doesn’t play nicely with XBMC.
What are MythTV and XBMC?
If you’ve found this post, you probably already know what these are, but for the few of you that don’t, here’s a quick intro to these two fantastic open source projects.
XBMC (known as “Kodi” from version 14 on) is arguably the best home theater software in the market today (it certainly beats anything that the cable companies force on their customers). It provides an easy to navigate interface for you to browse and watch all of your movies, TV shows, and streaming services. It’s also immensely extensible — and there’s a vibrant community of developers doing so. It also supports presenting and interacting with a live television and PVR source… through packages like MythTV, Tvheadend, NextPVR, and DVBLink.
MythTV is the only one that presently supports the Mac OS X architecture. But even with it being the only option, it is a powerful one. MythTV consists of two components. The “Frontend” — its own user interface for watching and recording TV, and the “Backend” — the business end of the software. The MythTV Backend handles scheduling, database maintenance, commercial detection, and all the other technical things that let you take a live video source (broadcast or unlocked cable) and transform them into something you can watch and manage within XBMC.
Both XBMC UPnP and MythTV UPnP are services that make content available via streaming over the network on demand.
Here’s the problem: both the MythTV UPnP server and the XBMC UPnP server try to run and allow you to watch media on other devices (e.g., I can lay in bed and watch my shows on my iPad using VLC). These two tend to get in each other’s way… and since the MythTV UPnP server generally loads first when your Mac boots, it usually wins. However, I prefer to use the XBMC uPNP media server, as it gives me access to all of my media; not just my TV recordings.
If the MythTV backend was set up with an internal IP address (127.0.0.1 or localhost), the problem doesn’t occur. However, if you’re using an external address like I am, they conflict. It seems that the easy solution would be to switch to an internal address, right? Unfortunately, I’m doing some development work with MythTV, which requires external access to the MythTV API.
So, you’re left with a few options:
Option 1: Disable MythTV UPnP
This is easily (if not non-intuitively) done from the Terminal (I actually prefer iTerm2). Here’s how to do it, step-by-step:
- Open Terminal (or iTerm2).
- Change to the /Library/LaunchDaemons directory.
- Stop and unload the MythTV daemon. Note the code below — “stop” requires just the label, while “unload” requires the filename (with the .plist extension).
- Edit the org.mythtv.mythbackend.plist file with vi (or your preferred text editor) – be sure to do this in sudo mode. You need to add a new string value to the launch command: “–noupnp”.
- Load and restart the MythTV daemon.
$ sudo launchctl stop org.mythtv.mythbackend $ sudo launchctl unload org.mythtv.mythbackend.plist $ sudo vi /Library/LaunchDaemons/org.mythtv.mythbackend.plist
Now, add the “–noupnp” string, save the document (by pressing escape and then typing “:wq” — without the quotes — to write the file and quit):
<!--?xml version="1.0" encoding="UTF-8"?> EnvironmentVariables HOME /opt/local/var/mythtvuser PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin PYTHONPATH /opt/local/lib/python2.7/site-packages:$PYTHONPATH KeepAlive Label org.mythtv.mythbackend ProgramArguments /opt/local/bin/mythbackend --logpath /opt/local/var/log/mythtv.27 --pidfile /opt/local/var/run/mythtv.27/mythtv --loglevel info --quiet --noupnp RunAtLoad ThrottleInterval 300
If all went well, you should now be ready to load and start up the MythTV backend.
$ sudo launchctl load org.mythtv.backend.plist $ sudo launchctl start org.mythtv.backend
Note that if you’re not comfortable with the command line, or simply want to stay within the GUI, the LaunchControl app can do a similar function. Simply fire it up, choose org.mythtv.mythbackend from the Global Daemons list and append “–noupnp” to the command.
Option 2: Disable XBMC UPnP instead of MythTV UPnP
Your second option is to disable the built-in XBMC UPnP server and use the MythTV UPnP server instead.
This is the simpler option – it doesn’t require you to drop into a terminal window or doing anything too complex. From the XBMC home screen (Gotham 13.2, at the time of this writing), go to System > Services > UPnP and uncheck the “Share Video and Music Libraries through UPnP” option. As I mentioned earlier, this is the less preferred option for me. Your needs may vary – but this is the easier way to resolve the conflict.
Which UPnP Server is Right for You? MythTV UPnP or XBMC UPnP?
The MythTV UPnP server option may be the right configuration for you. It is possible to make your XBMC media library available through the MythTV UPnP configuration, but for me, it wasn’t the right choice. I have too many media sources set up in XBMC to make using the MythTV UPnP server work.
One issue that this brings up is… how do I access my TV recordings via XBMC instead of through MythTV UPnP? This is actually quite easy to solve. Create a folder within your media collection (non-indexed), and set up a process using launchctl to run the MythLink script. This Perl script handles creating symlinks from MythTV to another folder with a fully-configurable naming structure (so you can see titles, episode numbers, etc. from within the XBMC UPnP service). For XBMC, I just use the Live TV functionality.
The Missing XBMC & MythTV UPnP Metadata Feature
One of the biggest gripes I have is that neither XBMC nor MythTV UPnP server are able to supply the program metadata. It is an often asked-for, but lower-priority item on the backlog. Being a good “open source citizen” I wish I could contribute to making this work, alas, the codebase is beyond my abilities.
My HTPC Configuration
I’m running XBMC Gotham 13.2 and MythTV 0.27/fixes under Mac OS X Mavericks (10.9.5) at the moment. MythTV and all the supporting libraries and software have been installed and managed by MacPorts. MythTV UPnP is turned off so that XBMC can take that role. If your configuration is different, your mileage may vary.