Real EPG for Synology’s Video Station


For those of us who always have to try and implement the solution before reading the instructions, you’re looking for this zip file. Yep. That’s the one.


I’ve had a Synology NAS for several years, and recently upgraded from a DS112 to a DS918+. The new NAS is a lightning fast piece of kit, and most of Synology’s standard utilities work smoothly … with the notable exception of Video Station.

Video Station’s Digital Television Recorder (DTR) is all but unusable because it has a thoroughly broken Electronic Programme Guide (EPG), and provides no way to import guides from other sources. The Video Station retrieves programme information from the transmission stream, but doesn’t know what to do with unicode. The result is that some channels have only the current and next programme because that’s all that’s streamed over the air; others have a full week of programmes presented in perfectly formatted gibberish. Because of this obvious fail, I bought a DVBLink license for my previous NAS. Now I find that on the DS918+ the USB DVB-T dongles I have don’t work with DVBLink, or with Plex Server, or indeed with TVHeadEnd. They do, however, work with Video Station. I’ve been happy with DVBLink, and toyed with replacing the hardware; but it seems a bit hit and miss matching the receivers that work with Synology on an Intel processor with the receivers that are compatible with your media platform of choice. The only certainties appear to be the most expensive options, which shouldn’t surprise me.

Never one to walk away from a challenge, I pried into the inner workings of Video Station. The EPGs are stored in /var/packages/VideoStation/etc/EPGs/0EPG. There’s one JSON file for each channel, with the naming convention based on frequency band and other channel-specific parameters. They look like this.

Determining which of the files relates to which channel is as straightforward as manually refreshing the EPG for that channel and watching the directory to see which file is created or updated. And the file contents? Here’s a truncated example.

I thought about this and decided it wouldn’t be too difficult to retrieve a comprehensive EPG and transform it from the standard XMLTV format to Synology’s JSON. I was thinking about Java, and grimacing as I did so, and then I remembered the new NAS has an Intel processor. Would a native Linux executable run? Would that executable be able to save into the EPG directory? Could Synology’s Task Scheduler be persuaded to run it? A quick prototype gave me a Yes! to these questions, so I got to work.

Although I mostly work in web technologies these days, I still call on Object Pascal when I need a desktop utility; I use Lazarus on Linux, and it cross-compiles nicely for MacOS and Windows on the rare occasions I need that. I put this to work, and in a couple of hours I had a small console app that downloads the latest New Zealand EPG file, courtesy of Matt Huisman, and then converts that to multiple JSON files and saves them to the appropriate directory.

So if you have

  • A Synology NAS with an Intel processor
  • Confidence to SSH into your box and change file permissions
  • A willingness to figure out channel to EPG filename mappings (if you’re in New Zealand these are already done)

then you too could have a Synology Video Station with an accurate, comprehensive electronic programme guide.

The steps

  1. Download a copy of an XMLTV programme guide for your region. The first section of this file lists the channels, and you’ll need the channel id attributes in the next step.
  2. Edit your .ini file. Copy the synoepg.ini file in the attached zip. In the copy, change the URL to your region’s XMLTV guide source; remove the entries in the Mapping section; replace the network_id value with the one from your existing Video Station EPG files (it’s in the final section of each file). I don’t know what isdst means unless it’s “is Daylight Saving Time”, so set it to the whatever value it has in the existing EPG files.
  3. Map your channels. You’ll need to have scanned the channels on your TV receiver first. SSH into your NAS and go to the /var/packages/VideoStation/etc/EPGs/0EPG directory. Open the Video Station and, one at a time, open each channel and refresh the EPG using the circular arrow button above the programme listings. Watch which of the EPG files changes (the timestamp’s a giveaway, so ls -l), and create an entry in the Mappings section of the .ini file that maps the XMLTV channel id to the Video Station filename.
  4. Change file permissions. The utility needs to be able to overwrite the existing Synology EPG files in /var/packages/VideoStation/etc/EPGs/0EPG, so this is a job for sudo chmod 0777 epg*.
  5. Turn off auto updating. In the Video Station’s Settings dialog, set Update frequency to Never. If the Video Station does update the EPG files, either automatically or by clicking the refresh button in error, the file permissions will revert and have to be changed again. I’ve not yet thought of a cunning plan to prevent this.
  6. Upload the files. Create a suitable directory on your NAS, then change the pushd path in the synoepg.sh script to that directory. When thats done, upload synoepg and your edited copies of synoepg.ini and synoepg.sh. Ensure synoepg and synoepg.sh are executable (chmod +x [FILENAME]).

Now you’re ready to test this. First, from your SSH session in the upload directory, run ./synoepg -h. This lists the available command-line options, which are only intended for initial setup and debugging if necessary. You should see the output on the left.

Now run it again, but with different options: ./synoepg -d -c -i -l will show you whether the utility is able to download your XMLTV file and whether it’s able to process it successfully. It should result in JSON files saved to a new subdirectory called output in your upload directory. Assuming they’re there, open one and check that it looks similar to an original Video Station EPG file from /var/packages/VideoStation/etc/EPGs/0EPG. It does? Brilliant.

Finally, run ./synoepg -d, then check your Video Station EPG directory: the files should be updated. And now when you open a channel in the Video Station’s channel list, you should have a week’s worth of accurate programme guides.

Making it automatic

You may have wondered why the script file (synoepg.sh) is in the upload folder. It’s there so we can automate the updating of your EPG. From your Synology Control Panel, open the Task Scheduler and create a new task. Give it a name and set it to run under your user account (if we’ve got this far, we know that works). It seems the Task Scheduler isn’t keen to launch an executable file, but it’s very happy to kick off a script that does so at one remove, so we’ll work with what we’ve got.

On the Task settings tab enter the full path to synoepg.sh. How you choose to configure the Schedule tab really depends on how often you expect the source XMLTV file to be updated: the one I use for New Zealand is updated just after midnight each day.

When you’ve saved the new task you can highlight it in the list and click the Run button. Check the Video Station’s EPG directory again to be sure the files have been updated. If there’s a problem at this point you can temporarily push the output from the task into a log file by changing the entry on the Task settings tab to something like /volume1/web/epg/app/synoepg.sh >>/volume1/web/epg/app/debug.log 2>&1 and then checking the contents of the log file. You can also set up notification emails if you want, and they’ll contain the output too. I recommend configuring emails initially and turning them off after a day or two when you’re confident everything’s running smoothly.

What’s next?

Being observant, you’ll have noticed that I have my own utility installed in the web directory and that, although my source XMLTV file is updated once a day, I’m running this utility twice that often. There’s a reason for this madness.

Another point of fail for the Synology Video Station is its inability to handle recurrent recordings. I could instruct DVBLink to record every episode of “Game of Thrones”, but with the Video Station I need to tell it to record each episode individually. I think this is something that can also be improved, and I’ll prototype a solution as soon as I have the time.

In conclusion

If for any reason the executable synoepg doesn’t play nicely with your local XMLTV files or with your Intel Synology box, the source code is included in the zip file. Lazarus is free and easily installed, and Object Pascal is a straightforward enough language to pick up. Alternatively you might be interested in porting the code to Java so it’ll run on all the various processors Synology supports. That should also be easy enough: the code’s dead simple.

What I’d really like to happen is for Synology to look at this and say “Gosh that’s simple; let’s include functionality like this in the next iteration of the Video Station”. That would be a major win for all Synology Video Station users.