What do you get when you add a TV DVB HAT (should be called crust's instead of HAT's - cred's to Tom L) to a Raspberry Pi and then pipe it into Plex?

TV streaming goodness.

Yet again whilst hazily stumbling through the www, I come across a post around Plex and live TV streaming via a Raspberry Pi TV DVB Hat. Within 2 minutes an order was placed with PiHut

The second part to this is Plex. Luckily I already have a Plex media server at home (HP N54L Microserver - 16GB RAM - 7TB) so setup should be easy!

Note: I highly recommend Plex as a media server over some others such as Serviio or Universal Media Server. I've had it up and running for around a year now and it has been running sweeeeet!


Things you'll need:

Recommended setup/tools:


Setting up your Raspberry Pi

  1. Open Etcher, select the Raspbian Lite .zip file, choose the designated SD card and finally click Flash! (The drive may be 'ejected' at the end of the flash, reinsert it and ensure you can see 'boot' as a drive for the next step)

  2. To enable SSH for headless control, create a blank file called 'ssh' and place it in the root folder of the SD card (boot)

  3. If your planning to use Ethernet for network then skip this step...
    Create a file called 'wpa_supplicant.conf' and insert the following code, ensuring you enter your deets for 'country', 'ssid', 'psk' and 'key_mgmt':

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="yourrealwifissid"
    scan_ssid=1
    psk="yourrealpassword"
    key_mgmt=WPA-PSK
}
  1. Safely eject the SD card and insert it into your RasPi. Before we power up the Pi, ensure the TV HAT is fitted correctly on the GPIO pins.

  2. As this is a headless install, we will need to identify the IP address assigned to the Pi to SSH in. There are a few ways to figure this out:

    • Head to your routers GUI/backend and find it there
    • Use a mobile app like Fing (AOS/iOS)
    • Use Nmap
  3. Open PuTTY and using the IP address of the Pi, enter pi@myipaddress for the hostname and click Open

  4. Press Yes on the initial security message, and enter the password: raspberry

  5. Once logged in, you'll need to run:
    sudo apt-get update
    sudo apt-get dist-upgrade
    sudo rpi-update
    sudo reboot

  6. Hops back onto the Pi once it has rebooted and run the following: sudo raspi-config

Currently your Pi is running with default settings, lets change that:

  • Change the default password for the pi user (use a strong password)
  • Set the hostname (something simple, short and easy to remember)
  • Boot Options > Desktop / CLI > Console
  • Boot Options > Wait for Network at Boot > Yes
  • Advanced Options > Expand Filesystem
  • Advanced Options > Memory Split > 256
  • Press right arrow twice then Finish
  1. One final reboot after that and we are ready in setup the TV HAT

Now we have setup our Raspberry Pi, we can begin installing and configuring the TV HAT and Plex!

Handy Tip:

At this point after a setup, I usually setup SSH keys using PuTTY to save the hassle of logging into the Pi at a later date.
Another handy tip ... Get a password manager to store your logins.
And the ulimate last tip? ... Don't forget your password for your password manager as you may need to repeat this guide


Setting up tvheadend

To save yourself the time, data, space etc, I would suggest following this guide from the chaps at PiHut on how to setup TVheadend ... I would of ended up copying this any who as its pretty bang on ...

Once you've got to and completed the 'Mapping Services' bit, come back here to get the Plex magic working!

tvhProxy

If you've googled 'TVheadend + Plex' already, you'll notice that most guides show to how to install a plugin called 'plex plugic' in order to pipe the TVheadend streaminto Plex. This is all good, however you will have to go into 'Plugins' then some horrible menu/GUI to access your shows. Shag that. What we'll use is tvhProxy.

tvhProxy is a 'proxy' server that will allow us to utilise the navite DVB/TV streaming element in Plex without the use of a plugin.

Steps:

  1. Install PIP
    sudo apt install python-pip

  2. Create another user for tvhProxy
    sudo useradd -m tvh -s /bin/bash

  3. Become one with the user "tvh"
    sudo su - tvh

  4. Pull the tvhProxy file and setup the environment

git clone https://github.com/jkaberg/tvhProxy.git
cd tvhProxy
virtualenv venv
. venv/bin/activate
pip install setuptools --upgrade
pip install wheel
pip install -r requirements.txt' 

It took around 10mins to run '-r requirements.txt' on a RasPi 2B+, may look like its hanging ... Stick with it

  1. Once we've done the needful, exit out of tvh user and navigate to the home directory
exit
cd /home
cd tvh
cd tvhProxy
  1. Nearly there, finally we need to edit the script before running
    sudo nano tvhProxy.py

  2. Change and replace the following lines

'tvhURL': os.environ.get('TVH_URL') or 'http://username:password@RasPiIPAddress:9981',
'tvhProxyURL': os.environ.get('TVH_PROXY_URL') or 'http://RasPiIPAddress',
  1. Fucking A. Last bit ... Run the following to create a service on starup
sudo cp tvhProxy.service /etc/systemd/system/tvhProxy.service
sudo systemctl daemon-reload
sudo systemctl enable tvhProxy.service
sudo systemctl start tvhProxy.service

End Game ... Plex

Note: I will upload screenshots soon, HP/Plex server being moved at time of writing

  1. This last leg to to setup Plex

  2. Log into your Plex and navigate to Settings and Live TV & DVR

  3. Click on Setup Plex DVR

  4. The next window you will see a 'Device Address' box, pop in the RasPi IP address with the port '5004' and click Connect

  5. Once it has connected, the next window will confirm the TV channels scanned from TVheadend. Press continue and finally 'View Program Guide'

Boom. Wasn't to hard eh? Now you've got Live TV streaming in Plex and the ability to record as well! Have a dabble around and enjoy!