How do I schedule a regular download for xmltv data?

Hi,

I’m installing a new DVR system for my in-laws.
It consists of a DS218+, an hdhomerun dvb tuner, a tablet and several Chromecasts.

It all works perfectly.

However, I’ve only manually downloaded a copy of the guide data from silicon dust and I need to automate it.

I was hoping I could just shove a wget line into the cron file but wget fails with a 400 error. I can, of course, just right click save from Chrome.

Also, it appears you have to grab the key for the XML data every day, off of discover. JSON or the API on the hdhomerun.

So, I have those two problems to fix but I assume this is actually well trodden ground.

Any ideas?

UPDATE1:
I have Plex Premium, DVR is working perfectly.
My location (UK) is unsupported, so I must provide my own XMLTV.XML file.
This manual process works perfectly but I have to manually update the XMLTV.XML file.
I know it’s not supposed to be automatic, are there existing solutions to this problem?

Ta,

J1M.

dvr on plex requires plex pass.

plex dvr also provides it’s own guide (included with plexpass), or you can continue to use your own xmltv source.

in no case will plex download xmltv for you, it must be done outside of plex.

https://support.plex.tv/articles/225877347-live-tv-dvr/

https://support.plex.tv/articles/226463767-frequently-asked-questions-dvr-live-tv/

Hi,

Sorry, should have made it clearer.

I have Plex Pass (Monthly so that if this doesn’t work I can kick it off the server)

I have fully functioning DVR on Plex.

Currently I can manually download a copy of xmltv.xml from Silicon Dust (HDHomeRun manufacturer) but only off of a browser (wget fails with HTTP 400)
XMLTV URL is: https://api.hdhomerun.com/api/xmltv?DeviceAuth=xxx
DeviceAuth can be manually extracted from: http://my.hdhomerun.com/discover.json
Instructions are here: https://forum.silicondust.com/forum/viewtopic.php?f=125&t=72813

I know the functionality isn’t build in (although it should be, and it certainly should be built into download the XMLTV file from Silicon Dust)

So, I need a solution.
Assuming I’m going to write a python or shell script to be added to the Synology’s cron file.
There’s a programming guide for HDHomeRun here: https://www.silicondust.com/hdhomerun/hdhomerun_development.pdf

  1. Execute some python to grab today’s DeviceAuth:
    Python wrapper for HDHomeRun Discover API
  2. Execute the URL to grab the latest XMLTV.XML
  3. Replace existing XMLTV with the new file.
  4. Add this file as an executable, run at 3am using cron

I do a custom xmltv.xml on my end and automated the process with a combination of a shell script and a python script. In my shell script I call zap2xml.pl to download two different xml files and combine them into one and the from there push it into plex.

first you have to get your plex token, dvr id and plex url. I got mine my using google chrome developer tools (f12) and manually updating the epg using their internal source and teased out the details from the console.

I don’t recall where I found this py script, but it works to update the epg

#!/usr/bin/env python

import requests

plexToken = "[your token]"
DVRID = "[your id]"
plexURL = "[your url]"

refreshEPG = plexURL + "/livetv/dvrs/"+DVRID+"/reloadGuide?X-Plex-Token=" +plexToken
res = requests.post(refreshEPG)
if res.status_code == 200:
        print("Refreshing EPG")
else:
        print("Error Returned : "+str(res.status_code))

as long as there is a file xmltv.xml in the same directory as the py script, it will pick it up and push into plex.

1 Like

Interesting, I wonder if this zap2xml script can download the xmltv file off of the hdhomerun?

Combining is interesting, as a 2nd act I was going to look into updating the xmltv file using the DVB-T’s OTA EPG data, get the latest changes for the next 7 days.

And that direct injection script looks great, at the moment Plex periodically imports the xmltv file in the Plex user’s home folder, I was going to just update that file. I’d need to figure out how to disable that periodic file scan to prevent unnecessary load on the NAS.

I’ll poke some of these scripts when I’m up there tomorrow, thanks.

J1M.

Have you tried using curl instead of wget? Reading through the SiliconDust thread you linked, someone over there developed a short script to query the current DeviceAuth (it changes) and download the XMLTV data. Here’s a link to that post:

https://forum.silicondust.com/forum/viewtopic.php?f=125&t=72813&start=45#p356922

I’m not able to test it as I don’t subscribe to their DVR service.

zap2xml probably won’t do the hdhomerun, but you might be able to pull it down with wget or curl. it can for sure help with the OTA EPG, that is what I use it for on my setup.

Hi,

I’m logged in using my in-laws account right now but this is RoboJ1M.

So, I’m ssh’d into the Synology NAS and I’ve started making progress.

Using curl and jq I can grab the daily auth code with:

curl -s http://192.168.55.116/discover.json | jq ‘.DeviceAuth’

So now I need to insert that into:

curl https://api.hdhomerun.com/api/xmltv?DeviceAuth=xxx

And write the output to /homes/Plex/xmltv.xml

Might have to strip the quotes off of the output from jq as well.
Then I’ll need to schedule it but that’s for later, need to get it working first.

Can anybody help? I’d like to just get it running in a shell script.

Thanks,

J1M.

Try this. It’s a modified version of the one I linked above (I did not write the original). It’s been changed to accept two arguments: The IP address of the HDHomeRun (mandatory) and the path/filename to save to (optional, default goes to your home directory) and to suppress progress output from curl:

#!/bin/bash

ip_address=$1
guide_path=$2

if [ -z "$guide_path" ]; then
        guide_path=~/xmltv.xml
        echo 'No file path provided; using default:' $guide_path
fi

if [ -n "$ip_address" ]; then
        echo 'Getting Current Key from HDHomeRun at:' $ip_address
        KEY=$(curl -s http://$ip_address/discover.json | jq -r .DeviceAuth)
        echo 'Current Key is' $KEY #optional
        echo 'Downloading TV Guide Data...'
        curl -s --compressed api.hdhomerun.com/api/xmltv?DeviceAuth=$KEY > $guide_path
        echo 'Done!'
else
        echo 'Usage:' $0 'hdhomerun_ip_address [file_path]'
fi

Example: ./scriptname.sh 192.168.1.100 /home/username/xmltv.xml

1 Like

Hi,

Thanks, I’ve mostly got that working.
Your bit works, I tried adding in some code from this thread that triggers an update.
Doesn’t work though, so I’ll just run it daily and let Plex do it’s daily import that it already does.

#!/bin/bash

ip_address=a.b.c.d
plex_path=/volume1/homes/plex
guide_path=$plex_path/xmltv.xml
curl_output_path=$plex_path
plex_token=xyz
DVRID=2
plexURL=http://a.b.c.d:32400/web/index.html#

if [ -z "$guide_path" ]; then
        guide_path=~/xmltv.xml
        echo 'No file path provided; using default:' $guide_path
fi

if [ -n "$ip_address" ]; then
        echo 'Getting Current Key from HDHomeRun at:' $ip_address
        KEY=$(curl -s http://$ip_address/discover.json | jq -r .DeviceAuth)
        echo 'Current Key is' $KEY #optional
        echo 'Downloading TV Guide Data...'
        curl -s --compressed api.hdhomerun.com/api/xmltv?DeviceAuth=$KEY > $guide_path
        echo 'Done!'
        refreshEPG=$plexURL/livetv/dvrs/$DVRID/reloadGuide?X-Plex-Token=$plex_token
        echo 'Trigger EPG Update using:'
        echo $refreshEPG
        curl -s $refreshEPG > $curl_output_path/EPGUpdateOutput.html
        echo 'Done!'
else
        echo 'Usage:' $0 'hdhomerun_ip_address [file_path]'
fi

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.