The life and times of the younger, lesser spotted chicken.

Thursday, August 25, 2005

XMLTV && PuddleTV continued...

After a full afternoon of fiddling with the XMLTV scripts, as well as port forwarding to update Gorilla's portage, I think I have created a solution for showing whats coming up on SABC[1,2,3] and ETV, live, on PuddleTV.

The first problem I had to tackle was an irregularity in the tv_grab_za and tv_grep script. The tv_grep script does exactly what you'd expect it to do, from the name, it just 'grep's for certain arguments or parameters, and gives you the filtered result. The tv_grep script comes with a command to show the part of the schedule that hasn't already aired, ie. only from the current time, until the end of the cached schedule. The problem with this extension is that when asking it to show all shows that are coming up, it seems to start with shows that aired two hours previously. The obvious cause of this would be a badly interpreted current time/date. The fact that it is two hours difference made me immediately suspect SAST vs UTC. South Africa is +2 hours on GMT, and because of this, I suspected that the script wasn't taking this into account.

After a bit of fiddling, I found that it was trying to take this time zone difference into consideration, but for some reason wasn't being very successful with the adjustment. It would take the read out from a `date` command and then parse it, and based on whether there was a time zone mentioned, it default to just UTC or GMT time. For some reason, it wasn't interpretting SAST and so would take the current time as UTC and then make the adjustment for my time zone, and end up two hours early. The solution, after some bashing, came about quite randomly. I thought that because it isn't reading the SAST right, it might only be able to interpret certain symbols or time zones. I added an extra UTC to the end of a customized `date` command and voila, it worked. All of a sudden the script was doing as it was supposed to, and it was interpretting the correct time zone. After wording through my train of thought and attempts to fix it, in this blog, I have realised that it doesn't really make that much sense, but bygons, it works :-)

The second problem this afternoon was the issue of an out of date portage on gorilla.scw. He can't see campus, and as a result, his rsync in Gentoo doesn't work. An out of date portage isn't the worst thing in the world, because I can just make my PC fetch the files and then scp them across to gorilla. That works in most cases, but not when XMLTV has a dependency list of over 50 tiny perl packages. I tried making a snapshot of my portage and untar'ing it over gorilla's current portage with no luck. The easiest work around, I found, was to just:

$ ssh -L 80:ftp.rucus.ru.ac.za:80 flipflop@flipflop.scw.ru.ac.za

And then run the emerge -f xmltv command to fetch all the files through my PC. I will look into fixing rsync soon. It apparently uses SSH, so a simple ssh forward to my box should do the trick. I'm too excited to try figure it out now... I finally have the scripts for the schedule display on PuddleTV and I want to see it in action ASAP!

The scripts weren't too difficult to come up with, and with a bit of fancy footwork, I have emerged with two bash scripts. The one script ssh's to flipflop.scw and instructs it to fetch the TV schedules for the next 7 days from DSTV. Again, this is needed because gorilla himself can't see DSTV.co.za. flipflop.scw fetches the new schedule every three days (instructed to by the crontab) and then scp's it back to gorilla and effectively updates it. The use of sshkeys makes this possible, so I don't have to be there to type in the password to scp and ssh to and from the two boxes. The fetch script is below:

#/bin/bash
TVDIR="/home/flipflop/PuddleTV"
export http_proxy="http://username:password@cache.ru.ac.za:3128"
tv_grab_za --days 7 > $TVDIR/sabc_schedule.raw
scp $TVDIR/sabc_schedule.raw gorilla:~/PuddleTV/
rm $TVDIR/sabc_schedule.raw


It is frustrating because of gorilla's inability to see campus, but this kindof work around has become second nature to me, through the development of PuddleTV. The next script is the script which filters the schedule and then outputs the necessary, and needed, information to a local file. The file is then cat'd (with some more fancy footwork) and given to 'convert' which, through the use of the 'text' function, writes the programme information to a blankly (but PuddleTV prepared) jpeg image. This image is then replicated twenty times and then, using mencoder, made into a movie running at 2 frames per second. The result is a 10 second long video showing the next 15 shows that are to come onto the 'free' SA TV channels, in order of screening. The script is as follows:

#/bin/bash
TVDIR="/home/flipflop/PuddleTV"
tv_sort $TVDIR/sabc_schedule.raw | tv_grep --on-after "`date +%x' '%X' 'UTC`" --on-before tomorrow | tv_to_text | head -n 15 | grep "\-\-" > $TVDIR/temp/sabc_list
convert -font helvetica -pointsize 30 -fill blue -draw "text 10,110 '`cat $TVDIR/temp/sabc_list | sed 's/\t/ /g'`'" $TVDIR/schedule_pics/sabcschedule.jpg $TVDIR/temp/schedule_sabc.jpg
for i in `seq 1 20`
do
cp $TVDIR/temp/schedule_sabc.jpg $TVDIR/temp/schedule_sabc-$i.jpg
done
mencoder "mf://$TVDIR/temp/schedule_sabc-*.jpg" -mf fps=2 -o $TVDIR/videoclips/sabc_schedule.avi -ovc lavc -lavcopts vcodec=mpeg4
rm $TVDIR/temp/*


This script is run every five minutes on gorilla. I may change this so that it happens less often, like every ten minutes maybe, because the schedule doesn't change that often, and every ten minutes should be more than sufficient (and accurate). The only thing I want to add to this script is the addition of a timestamp in the top corner. This isn't too difficult, as it is already implemented into my original PuddleTV schedule generator.

I am in the process of emerging XMLTV onto gorilla, and the minute it is finished, I will fire up the scripts on the PuddleTV, realtime, and see how they perform. I plan on making the advert show, just about as often as the PuddleTV schedule. Once again, PuddleTV is developing, and every time I release another one of these scripts, it makes me think about how awesome it would be to actually package PuddleTV and release it as an actual ebuild for Gentoo. Oh well, some day :-)

1 Comments:

Anonymous Anonymous said...

http://pastexpiry.blogspot.com/2009/03/cartoon-chicken-soup-for-soul.html cartoon for your blog!

12:43 am

 

Post a Comment

<< Home