#!/bin/sh
# ---------------------------------------------------------------------
# GetSKY EPG script version 0.7
# Created around Oudeis's xml2epg program
# With a huge thanks to the people at www.bleb.org
# Check here for full info http://www.bleb.org/tv/data/listings?days=0,1&format=XMLTV
# Written by Redneck Eyeball
# replace the hello@world.com with your own e-mail address
# Change the TIMEZONE to whatever you need for your location


EPGLOCATION="/hdd/mv/skyuk"
TIMEZONE="+0"
EMAIL='hello@world.com'

mkdir $EPGLOCATION

# Remove old EPG data
rm $EPGLOCATION/epg.dat
rm $EPGLOCATION/epgui.dat

sleep 1

wget -q --header 'User-Agent: TV::Fetch::XML, $EMAIL' "http://www.bleb.org/tv/data/listings?days=0,1&format=XMLTV&channels=bbc1,bbc2,ch4,five,bbc3,bbc4&file=tgz" -O /tmp/xmltv.tgz
tar xvzf /tmp/xmltv.tgz -C /tmp >/dev/null 2>&1
/var/tuxbox/plugins/xml2epg /tmp/data.xml $EPGLOCATION/epg.dat --offset $TIMEZONE
sleep 3

#Create backup copy of original
cp $EPGLOCATION/epg.dat $EPGLOCATION/orgepg.dat
wget -q --header 'User-Agent: TV::Fetch::XML, $EMAIL' "http://www.bleb.org/tv/data/listings?days=0,1&format=XMLTV&channels=discovery,itv1,itv2,disney&file=tgz" -O /tmp/xmltv.tgz
tar xvzf /tmp/xmltv.tgz -C /tmp >/dev/null 2>&1
/var/tuxbox/plugins/xml2epg /tmp/data.xml $EPGLOCATION/newepg.dat --offset $TIMEZONE
# Join our old and new epg
cat $EPGLOCATION/orgepg.dat $EPGLOCATION/newepg.dat > $EPGLOCATION/epg.dat
sleep 3

#Create backup copy of original
cp $EPGLOCATION/epg.dat $EPGLOCATION/orgepg.dat
wget -q --header 'User-Agent: TV::Fetch::XML, $EMAIL' "http://www.bleb.org/tv/data/listings?days=0,1&format=XMLTV&channels=itv3,itv4,men_and_motors,paramount,paramount2,scifi,sky_cinema1,sky_cinema2&file=tgz" -O /tmp/xmltv.tgz
tar xvzf /tmp/xmltv.tgz -C /tmp >/dev/null 2>&1
/var/tuxbox/plugins/xml2epg /tmp/data.xml $EPGLOCATION/newepg.dat --offset $TIMEZONE
# Join our old and new epg
cat $EPGLOCATION/orgepg.dat $EPGLOCATION/newepg.dat > $EPGLOCATION/epg.dat
sleep 3

#Create backup copy of original
cp $EPGLOCATION/epg.dat $EPGLOCATION/orgepg.dat
wget -q --header 'User-Agent: TV::Fetch::XML, $EMAIL' "http://www.bleb.org/tv/data/listings?days=0,1&format=XMLTV&channels=sky_movies1,sky_movies2,sky_movies3,sky_movies4,sky_movies5,sky_movies6,sky_movies7,sky_movies8,sky_movies9&file=tgz" -O /tmp/xmltv.tgz
tar xvzf /tmp/xmltv.tgz -C /tmp >/dev/null 2>&1
/var/tuxbox/plugins/xml2epg /tmp/data.xml $EPGLOCATION/newepg.dat --offset $TIMEZONE
# Join our old and new epg
cat $EPGLOCATION/orgepg.dat $EPGLOCATION/newepg.dat > $EPGLOCATION/epg.dat
sleep 3

#Create backup copy of original
cp $EPGLOCATION/epg.dat $EPGLOCATION/orgepg.dat
wget -q --header 'User-Agent: TV::Fetch::XML, $EMAIL' "http://www.bleb.org/tv/data/listings?days=0,1&format=XMLTV&channels=sky_movies_cinema,sky_movies_cinema2,sky_one,sky_one_mix&file=tgz" -O /tmp/xmltv.tgz
tar xvzf /tmp/xmltv.tgz -C /tmp >/dev/null 2>&1
/var/tuxbox/plugins/xml2epg /tmp/data.xml $EPGLOCATION/newepg.dat --offset $TIMEZONE
# Join our old and new epg
cat $EPGLOCATION/orgepg.dat $EPGLOCATION/newepg.dat > $EPGLOCATION/epg.dat
sleep 3

#Create backup copy of original
cp $EPGLOCATION/epg.dat $EPGLOCATION/orgepg.dat
wget -q --header 'User-Agent: TV::Fetch::XML, $EMAIL' "http://www.bleb.org/tv/data/listings?days=0,1&format=XMLTV&channels=tcm,uk_bright_ideas,uk_gold,more4,sky_three&file=tgz" -O /tmp/xmltv.tgz
tar xvzf /tmp/xmltv.tgz -C /tmp >/dev/null 2>&1
/var/tuxbox/plugins/xml2epg /tmp/data.xml $EPGLOCATION/newepg.dat --offset $TIMEZONE
# Join our old and new epg
cat $EPGLOCATION/orgepg.dat $EPGLOCATION/newepg.dat > $EPGLOCATION/epg.dat
sleep 3

# Available channels are: bbc1, bbc2, itv1, ch4, five, abc1, bbc1_n_ireland, bbc1_scotland, bbc1_wales, bbc2_n_ireland, bbc2_scotland, bbc2_wales,
# bbc3, bbc4, bbc7, bbc_6music, bbc_news24, bbc_parliament, bbc_radio1, bbc_radio1_xtra, bbc_radio2, bbc_radio3, bbc_radio4, bbc_radio5_live, 
# bbc_radio5_live_sports_extra, bbc_radio_scotland, bbc_world_service, boomerang, bravo, british_eurosport, cartoon_network, cbbc, cbeebies, challenge,
# discovery, discovery_kids, discovery_real_time, disney, e4, film_four, ftn, itv2, itv3, itv4, living_tv, men_and_motors, more4, mtv, nick_junior,
# nickelodeon, oneword, paramount, paramount2, s4c, scifi, sky_cinema1, sky_cinema2, sky_movies1, sky_movies2, sky_movies3, sky_movies4, sky_movies5,
# sky_movies6, sky_movies7, sky_movies8, sky_movies9, sky_movies_cinema, sky_movies_cinema2, sky_one, sky_one_mix, sky_sports1, sky_sports2, sky_sports3,
# sky_sports_news, sky_sports_xtra, sky_three, sky_travel, tcm, uk_bright_ideas, uk_drama, uk_gold, uk_history, uk_style, uktv_documentary,
# uktv_people, vh1


wget 'http://dreambox/cgi-bin/xmessage?timeout=5&caption=SKY+EPG&body=Update+Done'

#Remove our temp files
rm $EPGLOCATION/newepg.dat
rm $EPGLOCATION/orgepg.dat
rm /tmp/data.xml
rm /tmp/raw.xml
rm /tmp/log.tmp
rm /tmp/xmltv.tgz

#create duplicate for MV / EPGUI / DreamVCR compatibility
cp $EPGLOCATION/epg.dat $EPGLOCATION/epgui.dat
sleep 2

exit;

# ---------------------------------------------------------------------