Tvheadend / DVBLink Integration

@jkaberg / @iPhonedation ~ I’m not sure I understand how we’re using the wrong channel numbers in the URLs. If you look at the channel mapping for my device:

If we used 002 or 356 (the Gracenote channel number) the recording wouldn’t work, but everything works fine over here. We specifically use the device channel number.

(Also, BTW, the reason we don’t use the URLs passed back from HDHR directly is that they are always with respect to the LAN, and we support accessing HDHR devices remotely.)

@elan said:
@jkaberg / @iPhonedation ~ I’m not sure I understand how we’re using the wrong channel numbers in the URLs. If you look at the channel mapping for my device:

If we used 002 or 356 (the Gracenote channel number) the recording wouldn’t work, but everything works fine over here. We specifically use the device channel number.

I’ll take a look when I get home from work (I based my conclusions on what @iPhonedation said). But if that’s true then my standpoint is still where it was, you should respect the URL key in lineup.json anyhow (even if it normally never changes).

I am running a new test here, with new ID for the HDHR that the proxy emulates and then I will see. Thanks @elan … I will post an update later/tomorrow.

2 Questions - can we access the mappings somehow?

@elan - I tested it:

This is the 705 Gracenote Channel ID for Sky Cinema Hits HD. It is in fact channel 602 in my TVH instance. But the log file shows this:

See:

Is it the number of digits maybe? Just guessing … if you like you can access my setup, happy to give you an temp ssh user.

I can just say for a 2 digit channel, (12 in my setup) with a Gracenote ID of 417 it works … strange

@jkaberg said:
So here is the solution, GitHub - jkaberg/tvhProxy: An small flask app to help Plex DVR connect with Tvheadend (yes recording is working)

One small note: the current Plex implementation is hardcoded to use port 5004 when recording from HDHR (it will append 5004 to any url), so an current workaround is to create an virtual web host, proxy it to tvhProxy (on port 80). Add the virtualhost to your host’s file, then setup Plex DVR to use the virtual host.

I hope the Plex engineers see’s this post and alters the behaviour.

Awesome!

So far the proxy seems to be working well and it’s fantastic to get this kind of use out of a USB tuner that was otherwise gathering dust (Hauppauge HVR-950).

A few notes:

  • If tvheadend is configured with a webroot for reverse proxy, adding the webroot to the end of the URL in the proxy config works fine
  • [Resolved] ATSC has channel numbers as x.y and the proxy would crash when it tried to evaluate the channel as int(). I’m no developer so there’s probably a different/better way to do this but evaluating as float was enough to get it going - there’s a PR open for this.
  • [Resolved] The README could use an update to indicate that a web server and virtual host config are currently necessary to make this work (also removing the portion about setting the Plex URL to URL:5004 since we need the virtual host) - if you’d like a PR for the doc update let me know.
  • [Resolved] Plex’s minimum number of 2 detected tuners will likely cause issues if you have a single tuner and schedule overlapping recordings. So far this is the only user-facing functionality gap I’m seeing.
  • [Resolved] The tvheadend user’s number of connections should be limited to the number of tuners available to prevent other apps from interfering with Plex recordings - found this out when a recording in progress by Plex was ended when I launched Kodi and it stole the tuner (recording via Kodi or tvheadend directly seems to keep a lock on the recording and not allow interruptions regardless of the number of connections).

In case it’s useful, here’s a sample nginx config after setting “127.0.0.1 tvhproxy” in /etc/hosts:

$ cat /etc/nginx/conf.d/tvhproxy.conf 
server {
    listen       80;
    server_name  tvhproxy;
    location / {
        proxy_pass http://127.0.0.1:5004;
    }
}

Thanks for giving tvheadend folks like me a chance to dig into Plex DVR!

Edit: Noted resolved issues

@Taligent said:

@jkaberg said:
So here is the solution, GitHub - jkaberg/tvhProxy: An small flask app to help Plex DVR connect with Tvheadend (yes recording is working)

One small note: the current Plex implementation is hardcoded to use port 5004 when recording from HDHR (it will append 5004 to any url), so an current workaround is to create an virtual web host, proxy it to tvhProxy (on port 80). Add the virtualhost to your host’s file, then setup Plex DVR to use the virtual host.

I hope the Plex engineers see’s this post and alters the behaviour.

Awesome!

So far the proxy seems to be working well and it’s fantastic to get this kind of use out of a USB tuner that was otherwise gathering dust (Hauppauge HVR-950).

A few notes:

  • ATSC has channel numbers as x.y and the proxy would crash when it tried to evaluate the channel as int(). I’m no developer so there’s probably a different/better way to do this but evaluating as float was enough to get it going - there’s a PR open for this.
  • The README could use an update to indicate that a web server and virtual host config are currently necessary to make this work (also removing the portion about setting the Plex URL to URL:5004 since we need the virtual host) - if you’d like a PR for the doc update let me know.
  • Plex’s minimum number of 2 detected tuners will likely cause issues if you have a single tuner and schedule overlapping recordings. So far this is the only user-facing functionality gap I’m seeing.
  • If tvheadend is configured with a webroot for reverse proxy, adding the webroot to the end of the URL in the proxy config works fine
  • The tvheadend user’s number of connections should be limited to the number of tuners available to prevent other apps from interfering with Plex recordings - found this out when a recording in progress by Plex was ended when I launched Kodi and it stole the tuner (recording via Kodi or tvheadend directly seems to keep a lock on the recording and not allow interruptions regardless of the number of connections).

In case it’s useful, here’s a sample nginx config after setting “127.0.0.1 tvhproxy” in /etc/hosts:

$ cat /etc/nginx/conf.d/tvhproxy.conf 
server {
    listen       80;
    server_name  tvhproxy;
    location / {
        proxy_pass http://127.0.0.1:5004;
    }
}

Thanks for giving tvheadend folks like me a chance to dig into Plex DVR!

In its current state, the proxy is just a proof of concept. However I agreed about the documentation and other stuff you said. Send me an PR on the documentation part, if you’d be so kind :slight_smile:

@jkaberg said:

In its current state, the proxy is just a proof of concept.
The great part is that it is quite functional even though further improvements require PMS fixes.

However I agreed about the documentation and other stuff you said. Send me an PR on the documentation part, if you’d be so kind :slight_smile:

Done!

When we will see tvheadend add to the offical beta ?
@elan
Do you guys plan to add Tvheadend support in the beta version or will it be HDHR device only ?

+1 for adding TVHeadend support as commented above

So this thread has a lot of talk about TVHeadend and not so much about DVBLink anymore. It’s unclear to me what the best way of testing the integration for DVBLink would be and what functionality is currently available. Any pointers?

Does this work if the proxy runs on another machine than plex? I have TVH and the proxy on Ubuntu, and Plex on macOS. I don’t know how to access the tvhproxy virtual host from macOS.

Sure it should work. I have mine running on my Ubuntu based QNAP with TVH.

@lauridsd said:
Does this work if the proxy runs on another machine than plex? I have TVH and the proxy on Ubuntu, and Plex on macOS. I don’t know how to access the tvhproxy virtual host from macOS.

just make sure you set the host file on your macOS, I’ve just corrected this in the readme @ github

So i have nginx running on my Ubuntu machine (where TVHeadend runs), started the proxy there too.
I pointed tvhproxy to my ubuntu ip on my Mac’s (where PMS runs) /etc/hosts

Now when i add tvhproxy in Plex’s DVR settings i get a spinning loading icon while adding, but after ~5 sec i get this:

There was a problem adding the device: tvhproxy

It seems like it finds something but there’s another problem, because when i add a random IP in my LAN i don’t even get the 5 sec loading time, instead it directly shows the error.

@lauridsd said:
So i have nginx running on my Ubuntu machine (where TVHeadend runs), started the proxy there too.
I pointed tvhproxy to my ubuntu ip on my Mac’s (where PMS runs) /etc/hosts

Now when i add tvhproxy in Plex’s DVR settings i get a spinning loading icon while adding, but after ~5 sec i get this:

There was a problem adding the device: tvhproxy

It seems like it finds something but there’s another problem, because when i add a random IP in my LAN i don’t even get the 5 sec loading time, instead it directly shows the error.

Did you set up the virtual host with nginx and reloaded the config?

Yes, i added the host to my /sites-available/default and ran:

laurids@ubuntu:~$ sudo /etc/init.d/nginx reload [ ok ] Reloading nginx configuration (via systemctl): nginx.service.

The proxy is running:

laurids@ubuntu:~/tvhProxy$ ps -ef | grep tvh hts 845 1 0 Sep29 ? 00:06:50 /usr/bin/tvheadend -f -u hts -g video root 4030 1 10 03:12 ? 00:00:00 /home/laurids/tvhProxy/venv/bin/python /home/laurids/tvhProxy/tvhProxy.py laurids 4036 3262 0 03:12 pts/3 00:00:00 grep --color=auto tvh

nginx is running too:

laurids@ubuntu:~/tvhProxy$ ps -ef | grep nginx root 3095 1 0 00:36 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; www-data 3996 3095 0 03:05 ? 00:00:00 nginx: worker process laurids 4038 3262 0 03:12 pts/3 00:00:00 grep --color=auto nginx

Important part of /etc/hosts on the mac:

191.168.7.186 tvhproxy
(That’s the IP of the Ubuntu machine)

@lauridsd said:
Yes, i added the host to my /sites-available/default and ran:

laurids@ubuntu:~$ sudo /etc/init.d/nginx reload [ ok ] Reloading nginx configuration (via systemctl): nginx.service.

The proxy is running:

laurids@ubuntu:~/tvhProxy$ ps -ef | grep tvh hts 845 1 0 Sep29 ? 00:06:50 /usr/bin/tvheadend -f -u hts -g video root 4030 1 10 03:12 ? 00:00:00 /home/laurids/tvhProxy/venv/bin/python /home/laurids/tvhProxy/tvhProxy.py laurids 4036 3262 0 03:12 pts/3 00:00:00 grep --color=auto tvh

nginx is running too:

laurids@ubuntu:~/tvhProxy$ ps -ef | grep nginx root 3095 1 0 00:36 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; www-data 3996 3095 0 03:05 ? 00:00:00 nginx: worker process laurids 4038 3262 0 03:12 pts/3 00:00:00 grep --color=auto nginx

Important part of /etc/hosts on the mac:

191.168.7.186 tvhproxy
(That’s the IP of the Ubuntu machine)

Firewall? Did you add an exception for port 80 and 5004? If you browse 191.168.7.186:5004/lineup.json what do you get?

I get the translated tvh channel list from your script. That probably means my nginx proxy isn’t working, right?

I realised that it works when i just enter 192.168.7.186:5004 in Plex DVR. Adding the tuner works flawlessly, but i can’t record anything because every recording fails.