Building a TV Server on a Synology NAS (Updated)

Work Environment

NAS:  Synology DS216+II with DSM 6.1.7-15284

Before you begin:

Enable SSH.

If you have a battery backup unit then enable UPS.

You will need to donate $20 to http://mc2xml.awardspace.info to get a version of the software that will run on your Synology if it uses an ARM processor and won’t run the standard x86 version that you can download from the site. The DS216+II in this tutorial has an Intel x86 / x64 processor so the standard x86 version will work just fine.

You will also need a subscription to Schedules Direct.

Add SynoCommunity to your package sources. Install the latest version of Tvheadend. You might need to enable beta versions to get the latest version of the software.

Create a Windows Share folder on your Synology called “public” and make sure the “sc-media” user has read/write access to it.

SSH into your Synology and create the following scripts.

$ cd /volume1/public
$ wget https://raw.githubusercontent.com/nurtext/tv_grab_file_synology/master/src/local/tv_grab_file

Then make sure that the line beginning with ‘cat’ is pointing to /volume1/public/xmltv.xml. Here’s a sample:

/volume1/public/tv_grab_file

#!/bin/sh
# tv_grab_file for local XMLTV file
dflag=
vflag=
cflag=
if [ $# = 0 ]
then
    cat /volume1/public/xmltv.xml
    exit 0
fi

for arg
do
    delim=""
    case "$arg" in
    #translate --gnu-long-options to -g (short options)
       --description) args="${args}-d ";;
       --version) args="${args}-v ";;
       --capabilities) args="${args}-c ";;
       #pass through anything else
       *) [[ "${arg:0:1}" == "-" ]] || delim="\""
           args="${args}${delim}${arg}${delim} ";;
    esac
done

eval set -- $args

while getopts "dvc" option
do
    case $option in
        d)  dflag=1;;
        v)  vflag=1;;
        c)  cflag=1;;
        \?) printf "unknown option: -%s\n" $OPTARG
            printf "Usage: %s: [--description] [--version] [--capabilities] \n" $(basename $0)
            exit 2
            ;;
    esac >&2
done

if [ "$dflag" ]
then
   printf "Local"
fi
if [ "$vflag" ]
then
   printf "1.0\n"
fi
if [ "$cflag" ]
then
   printf "baseline\n"
fi
exit 0

Create a symlink to /var/packages/tvheadend/target/bin:
$ sudo ln -s /volume1/public/tv_grab_file /var/packages/tvheadend/target/bin/tv_grab_file

Create a symlink to /usr/bin:
$ sudo ln -s /var/packages/tvheadend/target/bin/tv_grab_file /usr/bin/tv_grab_file

Change permissions and make the files executable:
$ sudo chown -R sc-tvheadend:tvheadend /var/packages/tvheadend/target/bin
$ sudo chmod +x /var/packages/tvheadend/target/bin/tv_grab_file
$ sudo chmod +x /usr/bin/tv_grab_file

Create the grab_listings script:

/volume1/public/grab_listings

/volume1/public/mc2xml -T [username]:[password] -D /volume1/public/xmltv.dat -o /volume1/public/xmltv.xml

Make the file executable:
$ sudo chmod +x /volume1/public/grab_listings
$ sudo chmod 777 /volume1/public/grab_listings

Copy mc2xml to /volume1/public folder and make executable.
$ sudo chmod +x /volume1/public/mc2xml

The following will update your TV listings once a night:

/etc/crontab

0       23       *       *       *       root    /volume1/public/grab_listings

Restart Cron:
sudo synoservice --restart crond

Now restart TVheadend and log into the TVheadend GUI, you should see a module called “Internal: XMLTV: Local” under Configuration > Channel/EPG > EPG Grabber Modules. Enable the one that shows a path to /usr/bin/tv_grab_file. Then click on “Re-run Internal EPG Grabbers”. If all goes well, then TVheadend should now contain EPG Grabber Channels.