Tuesday, March 31, 2015

Cutting the cord

I cut the cord -- we cancelled DirectTV and don't have cable. We looked at what we were actually watching, and it's just a few network shows and a lot of Netflix and a little Amazon. We'd cancelled the NFL package a few years ago since it turned out that most of the games we wanted to watch were either on the network or at the local sports bar, which is a lot of fun.

We have a Roku that shows Netflix and Amazon, so we just need to be able to get the local TV stations and record them so we can do ad skipping and time shifting.

I bought one of these last year to run XBMC to play our huge music library:

http://www.amazon.com/Matricom-Sigma-E350-Ubuntu-Output/dp/B00G2C3386/ref=cm_cr_pr_product_top?ie=UTF8

These are out of date already, but there are a number of small form-factor computers that are similar and cheap.

I installed OpenELEC instead, which is a small Linux OS tuned for Kodi. Installation is easy.

Directions are here:  OpenELEC. http://wiki.openelec.tv/index.php/HOW-TO:Installing_OpenELEC

Download the generic build from here, get the disk image version.

http://openelec.tv/get-openelec

Write it to a 256MB+USB stick:

http://wiki.openelec.tv/index.php/HOW-TO:Installing_OpenELEC/Writing_The_Disk_Image

Plug the USB stick into the HTPC and boot.
Enter the BIOS to set to boot from the USB stick, save the changes and reboot.

OpenELEC installer starts with this screen:



Read the message, then go with option 1. OpenELEC installer shows this screen:



I only have one drive, so that's the one I selected. Select okay, then OpenELEC installer shows this screen:



Your choice on whether yes or no. I went with yes since this means I can do some remote admin later.

Next step:



Select yes since this is the thing to do.

Last chance!



Do it!

Installation happens, and the installer goes back to the first dialog. Remove the USB stick and choose Reboot.

OpenELEC boots and shows the initial OpenELEC configuration screens. Select the language, keyboard, hostname, networking, whether to turn on SSH (if you installed it) and Samba. Select both of these if you have media on other devices that you want to see in Kodi. Make a note that the default ssh user is 'root' and the password is 'openelec'. Finally there is a thank you screen and clicking next shows Kodi.

For some reason, my local network didn't show up in the initial configuration. It turned out that my wifi router needed rebooted. I did that, rebooted the HTPC, and the network connected automatically.

Now configure Kodi. There are a lot of steps, but they are all easy steps.

1. The picture doesn't fit my TV. Go to System - Settings - System - Video output - Video Calibration. There are grab bars at the top left and bottom right of the screen. You might not be able to see them, just mouse there, click and drag, then you'll see the bars to align with the corners. ESC key goes back when you're done.

2. Time is wrong. Go to System - Settings - Appearance - International. Set your timezone country and timezone here. Kodi should now show the correct time.

3. Connect the network storage for music, just go to music and add it as an smb source.

4. I have a USB TV card connected to an antenna on my roof, so I need to install tvheadend to be able to see TV through Kodi and have PVR support. tvheadend has a client and a server. The server does the actual connection with the TV card and pulls in all the TV stations and makes them available for the client. The client gets the data from the server and displays it in Kodi. Both can be installed on the same box, which is what I wanted to do.

The client is a simple install, go to System - Settings - Addons - PVR Clients and install tvheadend client.

Install tvheadend backend server: This turned out to be a pain in the ass. tvheadend is an open source project that is running out of steam. What is there is very good quality software, but it is cryptic and hard to configure.

First, the not-obvious part is to install the unsupported repository. Then install tvheadend. I have no idea why the client would be in the supported repository and the server is in the unsupported.

Now to configure... I googled a crapload of pages to figure this all out so it works.
  • Open a web browser on another computer, go to your Kodi box at port 9981. 
  • click the Configuration tab. At the bottom right of the window is a little up arrow, click that to see the output of what tvheadend is doing. It can be very informative.
  • click the tv adapters tab. Make sure your adapter appears in the list.
  • click the Networks tab. Click Add, then atsc type, then give it a name (I'm lazy, I used "atsc"), check Network Discovery and uncheck Skip initial channel scan. In Pre-defined Muxes, choose United States: us-ATSC-Center-frequencies-8... Do this even if there is a mux for your area. This one has all the stations, the local ones don't necessarily. The Boise one is missing channels 2 and 7, the ATSC center one had them all. Click Create. Click Force Scan.
  • click the Muxes tab. There should be a lot of muxes listed. It might take a while for the list to fill in, be patient. A lot will fail, that's okay.
  • click the Services tab. Click Map All. Wait a while. Check the log to make sure all your channels got mapped. 
At this point, channels should be showing up in Kodi. Go to TV and Channels and see what you have. The easy part is done. Next is to configure the program guide. I spent 3 days figuring this out. You can't get a guide over the air, you have to get it from the internet. You need a script to pull in the guide data, then another script to feed that data to tvheadend, and this is a tedious and painful process. Fortunately, there aren't that many channels here.

So -- 
  • ssh to your Kodi box and create a /storage/scripts folder. Add it to the path by creating a /storage/.profile file and adding this line:

    export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/storage/.kodi/addons/service.multimedia.tvheadend/bin:/storage/scripts
  • get mc2xml from mc2xml.hosterbox.net. Create a /storage/scripts folder. Copy mc2xml there and make it executable. This is the script that will pull in the actual TV guide data.
  • get tv_grab_file from http://code.google.com/p/tv-grab-file/downloads/list. This is the script that will hand off the output of mc2xml to tvheadend. This file needs edited so it will work on openelec: on line 5, change (( and )) to [ and ] respectively, so when you're done you should have

    if [ $# = 0 ]

    and change line 7 to look like this:

    cat /storage/.xmltv/tv_grab_file.xmltv

    Make this script executable also.
  • Create a cron entry with

    crontab -e

    Add this line:

    0 2 * * * /storage/scripts/mc2xml -c us -g 83607 -o /storage/.xmltv/tv_grab_file.xmltv

    This will fetch a new TV guide every day at 2 am. The -c parameter is the country code, the -g parameter is the zip/postal code, change as appropriate. The -o parameter is where to put the output.
  • Run that command from the command line once:

    /storage/scripts/mc2xml -c us -g 83607 -o /storage/.xmltv/tv_grab_file.xmltv

    The first time it runs, it asks what sort of guide to pull in. I picked 4 for the digital over the air stations. This will create the initial TV guide data.
  • In Kodi, go to System - Settings - Addons - Enabled Addons - Services - tvheadend, then configure tvheadend to use the tv_grab_file script. This should be straightforward, just pick it with the file chooser.
  • Back to the tvheadend configuration pages -- Configuration - Channel/EPG EPG Grabber. Check the first 3 boxes, then in Internal Grabber, click down on Module and you should see XMLTV. You won't see this until you do the previous step. Select that and Save Configuration.
  • Now go to the Channels tab. Click Map Services. Most of what you'll get is crap. ssh to your Kodi box and look through /storage/xmltv/tv_grab_file.xmltv. The trick now is to go through each channel in the Channels tab in the web interface, use the Edit button, and select the appropriate EPG source for that channel. I made a spreadsheet to keep this all straight. Go ahead and delete any channels you don't want. I deleted a couple of home shopping channels and a few of the Spanish language channels.
  • Super pain-in-the-ass part -- the NAME in the Edit Channel dialog MUST be the same name as listed in the tv_grab_file.xmltv file. MUST!!! So maybe the channel mapper gave it a nice name of ABC, and now you must change it to KBOIDT or KBOIDT2. Also be sure to check the Auto EPG Channel box.
  • Do this for every channel, then wait 2 hours to cool off from such diddly tediousness. 2 hours because that is the default time in Kodi to refresh the program guide. You can set it to 15 minutes in the Live TV - EPG settings to do it sooner, then set it to 1440 minutes to update it twice a day.  
I may have missed something, but this should be really close to right. Note that recording is built in to Kodi. Once the guide is there, you can set a "timer" to record an individual program or the entire series. 

That's pretty much it. Kodi has a lot of add-ons, a lot! There are quite a few that are on the shady side, but will let you watch live streaming sports, TV, and movies, and past episodes of TV shows. Might be legal, might not, depends on where you live, I guess.

A good starting place to continue to configure Kodi is this page:

http://www.tvaddons.ag/config-wizard-kodi/












No comments: