#!/bin/bash
#
# Copyright (C) 2006 Marios Andreopoulos - mrsaccess
# Distributed under the terms of the GNU General Public License v2
#
#
#
# mtv is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY. YOU USE AT YOUR OWN RISK. THE AUTHOR
# WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY
# OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.
# See the GNU General Public License for more details.
#
#
# Version notice:
# There aren't any known bugs in this script.
#
##
system_encoding="utf8"
prog_name="mtv"
prog_version="0.1"
release_name="The truth is out there."
fullprog="${prog_name}-${prog_version}"
DaTe=`date +%Y-%m-%d`
i_am=`whoami`
rawdata=/tmp/$i_am-mtv1
list1=/tmp/$i_am-mtv2
list2=/tmp/$i_am-mtv3
list3=/tmp/$i_am-mtv4
#Setting some color codes
GR=$'\x1b[1;32m'
RED=$'\x1b[31m'
REDB=$'\x1b[31;1m'
TQ=$'\x1b[36;1m'
TQB=$'\x1b[36;1;5m'
YL=$'\x1b[33;1m'
NC=$'\x1b[0m'
version_info()
{
cat <<END
${prog_name}, version ${prog_version}
codename ${TQB}$release_name${NC}
Copyright (C) 2006 Marios Andreopoulos - mrsaccess
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.
in.gr webiste is copyright of Lambrakis Press
END
}
tvguide()
{
echo -e " in.gr.\n\n"
ls $rawdata >/dev/null 2>&1
if ((`echo $?`!=0)); then
echo hi > $rawdata
fi
if [ `head -n1 $rawdata` != "$DaTe" ]; then
echo hi
echo $DaTe > $rawdata
wget -O - "http://www.in.gr/TV/results.asp?dtmDate=$DaTe"|iconv -f iso-8859-7 -t $system_encoding >> $rawdata
fi
clear
grep ChannelID $rawdata|grep -vE "class|size"|sort -u|sed -e 's/.*ChannelID=\(.*\)">\(.*\)<\/a.*/ \2/'|grep -E -n "[0-9A-Za-z--]"
number_of_channels=`grep ChannelID $rawdata|grep -vE "class|size"|sort -u|sed -e 's/.*ChannelID=\(.*\)">\(.*\)<\/a.*/ \2/'|grep -E -n "[0-9A-Za-z--]"|wc -l`
echo -en "\n ENTER: ";read -s -n3 channel_number
channel_number=`echo $channel_number|sed -e 's/^[0]*//'`
if [[ "$channel_number" -lt "1" ]]; then echo -e "\n\n ."; exit; fi
if [[ "$channel_number" -gt "$number_of_channels" ]]; then echo -e "\n\n ."; exit; fi
Channel=`grep ChannelID $rawdata|grep -vE "class|size"|sort -u|sed -e 's/.*ChannelID=\(.*\)">\(.*\)<\/a.*/\1/'|sed -n ${channel_number}p`
clear
echo -e " `grep ChannelID $rawdata|grep -vE "class|size"|sort -u|sed -e 's/.*ChannelID=\(.*\)">\(.*\)<\/a.*/\2/'|sed -n ${channel_number}p` $DaTe:"
grep -v class $rawdata|grep -C3 "ID=$Channel"|sed -e 's/<td>\(.*\)<\/td>/\1/'|sed -e 's/<a \(.*\)">\(.*\)<\/a>/\2/'|sed -n 1~8p|sed 's/[\t]*//' > $list1
grep -v class $rawdata|grep -C3 "ID=$Channel"|sed -e 's/<td>\(.*\)<\/td>/\1/'|sed -e 's/<a \(.*\)">\(.*\)<\/a>/\2/'|sed -n 2~8p|sed 's/[\t]*//' > $list2
grep -v class $rawdata|grep -C3 "ID=$Channel"|sed -e 's/<td>\(.*\)<\/td>/\1/'|sed -e 's/<a \(.*\)">\(.*\)<\/a>/\2/'|sed -n 6~8p|sed 's/[\t]*//' > $list3
for ((i=1; i<=`cat $list1|wc -l`; i++)); do echo -e "`sed -n ${i}p $list1`\t`sed -n ${i}p $list2`\t\t\t\t\t\t\t`sed -n ${i}p $list3`"; done
rm -f $list1 $list2 $list3
}
for ((i=$OPTIND; i<=$#; ++i)); do
case ${!i} in
-v | --version ) version_info; exit;;
-h | --help ) help_info; exit;;
* ) echo -e " Sorry, $prog_name was called with unknown argument(s).\n Try again without any arguments. ;)"; exit;;
esac
done
tvguide