#!/bin/sh
# ---------------------------------------------------------------------
# GetSKY EPG script version 1.0 Beta 1
# 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 
# Thanks to Rick Hunter for his help
# replace the hello@world.com with your own e-mail address
# Change the TIMEZONE to whatever you need for your location


#Create Symlink for 7020
ln /usr/lib/libxmltree.so.0 /usr/lib/libtuxbox-xmltree.so.0.0.0

if [ -d /mnt/usb/mv ] ; then
EPGLOCATION="/mnt/usb/mv/skyuk"
elif [ -d /hdd/mv ] ; then
EPGLOCATION="/hdd/mv/skyuk"
else
exit 0
fi

TIMEZONE="+0"
EMAIL='hello@world.com'

if [ ! -d $EPGLOCATION ] ; then
mkdir $EPGLOCATION
fi


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


wget -O /tmp/getsky.tmp -q 'http://root:dreambox@127.0.0.1/cgi-bin/rc?352'
wget -O /tmp/getsky.tmp -q 'http://root:dreambox@127.0.0.1/cgi-bin/xmessage?timeout=5&caption=SKY+EPG&body=Updating+SKYEPG++Please+wait'

sleep 1

# bbc1,bbc2,ch4,five,bbc3,bbc4
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

# discovery,itv1,itv2,disney
#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

# itv3,itv4,men_and_motors,paramount,paramount2,scifi,sky_cinema1,sky_cinema2
#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

# sky_movies1,sky_movies2,sky_movies3,sky_movies4,sky_movies5,sky_movies6,sky_movies7,sky_movies8,sky_movies9
#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

# sky_movies_cinema,sky_movies_cinema2,sky_one,sky_one_mix
#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

# tcm,uk_bright_ideas,uk_gold,more4,sky_three
#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

# Nieuw toegevoegd: sky_sports1, sky_sports2, sky_sports3,sky_sports_news, sky_sports_xtra,sky_travel
#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_sports1,sky_sports2,sky_sports3,sky_sports_news,sky_sports_xtra,sky_travel&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

# Nieuw toegevoegd: abc1,boomerang, bravo,british_eurosport, cartoon_network,challenge
#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=abc1,boomerang,bravo,british_eurosport,cartoon_network,challenge&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

# Nieuw toegevoegd: bbc1_n_ireland, bbc1_scotland, bbc1_wales, bbc2_n_ireland, bbc2_scotland, bbc2_wales,bbc_news24, cbbc, cbeebies
#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=bbc1_n_ireland,bbc1_scotland,bbc1_wales,bbc2_n_ireland,bbc2_scotland,bbc2_wales,bbc_news24,cbbc,cbeebies&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

# Nieuw toegevoegd: discovery_kids, discovery_real_time, disney, e4, film_four, ftn,living_tv
#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_kids,discovery_real_time,disney,e4,film_four,ftn,living_tv&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

# Nieuw toegevoegd: mtv, nick_junior, nickelodeon, uk_drama, uk_history, uk_style, uktv_documentary,uktv_people
#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=mtv,nick_junior,nickelodeon,uk_drama,uk_history,uk_style,uktv_documentary,uktv_people&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

# Nieuw toegevoegd: sky_two,uk_history
#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_two,uk_history&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 -O /tmp/getsky.tmp -q 'http://root:dreambox@127.0.0.1/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
rm /tmp/getsky.tmp

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

exit;

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