Saturday 21 February 2009

Revised Applescript for downloading EPG for use with EyeTV

Last year I wrote an Applescript to download an xmltv file and load into EyeTV (see this post). This relied on downloading a single xmltv file from Free*EPG. Unfortunately in Septembver 2008 they discontinued providing this file for direct download and instead required their software which only worked on a Windows PC. 

The handy part with the Free*EPG file was they handled all the location set-up and provided a single file for download (EyeTV only accepts a single xmltv file). The other choice for downloading xmltv files was OzTiVo , but this required updating the Applescript to do all the file handling and aggregating. This turned out to be a bit of work and some of the bugs I had to fix took a week to appear which slowed things down a bit.

Version 2.0 of my xmltv Applescript can be downloaded here (168 K). I also included instructions on its set-up. Apart from choosing which channels (e.g. ABC-NSW) to download on first run, it is basically the same as for version 1.0.

UPDATE 12 Oct 2009: All the Australian free to air networks now publish up to date EPG data for about 7 days over DVB (thanks to the Anonymous comment on my original post). I highly recommend using this data instead of my Applescript (which will now no longer be updated). To change to DVB go to each channel and change EPG to DVB, then right click on the Program Guide item and select "Clear EPG Database", then right click again on Programs and select "Update DVB Program Guide".

30 comments:

Anonymous said...

Hey Ben,
It's Eli from work. My iceTV account expired and I stumbled across your script looking for a free alternative. Pretty freaky coincidence! Anyway, thanks for sharing it, it works perfectly and saved me a $100/year subscription on iceTV.

Anonymous said...

Absolutely love it!!. Very cool and comprehensive script.

Just one tiny thing that I did to make it more useful was add a line to quit EyeTV before it updates. It wasn't updating with the new xmltv file if EyeTV was open when the script ran.

Also if any users have trouble with EyeTV requiring admin permission to quit, you need to allow the user to write to the /Library/Preferences directory.

Thanks for such a useful script.

benb :)) said...

G'Day Anonymous!

Glad you like the script. I have not had the problem with EyeTV not updating when open so I never needed to add quitting.

Anonymous said...

great script. any chance you could amend it for NZ?
I have an older applescript but it doesn't work anymore for 3.1.
The NZ data is here: http://epg.pvr.geek.nz/epg/listings-freeview.xml.gz

any help greatly appreciated. Oh, and here's the old script if it helps any...


on run
--based on a script from http://flolog.de/osx/?p=39

--or you can replace this with your local xmltv provider, remember to keep in the quotes \"
set theURL to "\"http://epg.pvr.geek.nz/epg/listings-freeview.xml.gz\""

tell application "Finder" to get folder of (path to me) as Unicode text
set theDir to "\"" & POSIX path of result & "\""
set theCmd to "curl "
set theDownload to theCmd & theURL & " > " & theDir & "listings-freeview.xml.gz"
set LogMsg to "xmltv file downloaded ok"

try
do shell script theDownload
try
-- do shell script "unzip -o" & theDir & "listings-freeview.xml.gz"
do shell script "gunzip -d " & theDir & "listings-freeview.xml.gz" --& " -d " & theDir
try
do shell script "open -a EyeTV.app " & theDir & "listings-freeview.xml"
on error errTxt
set LogMsg to "Error in opening xmltv file: " & errTxt
end try
on error errTxt
set LogMsg to "Error in Unziping file: " & theDir & "listings-freeview.xml.gz" & errTxt
end try
on error errTxt
set LogMsg to "Error downloading file: " & errTxt
end try

--disable this if you do not want a logfile written
write_to_file(((the current date) as string) & ": " & LogMsg & (ASCII character 13), (path to "logs" as string) & "EyeTV xmltv Download.log", true)
end run

on write_to_file(this_data, target_file, append_data)
--from http://www.apple.com/applescript/sbrt/sbrt-09.html
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file

benb :)) said...

I tried your posted Applescript and it worked ok with 3.1. What error are you getting with this?

Andrew said...

Thanks for coming up with this script. Do you know if it would work for me in the United States?
Cheers!

benb :)) said...

This script should work anywhere, provided that the xmltv site provides:
- separate files for each channel and day
- a separate channel file
- a file with the list of dates on each of the files

You should be able to modify the properties in the Applescipt to link to the correct named files. Let me know if you have any hassles with this.

Chip and Moo said...

Thanks so much for writing this script, it's brilliant.
There's a couple of issues I have with it at the moment:
1) it seems to take a very, very long time to run. I can live with this, but...
2) it opens script editor in the foreground (on top of EyeTV). Is there any way to make this a silent process? I'm not that great with Applescript, but I thought compiled scripts could run silently in the background.
3) Are you having any issues with the xmltv content only filling some channels for a week, but others only for that day?

benb :)) said...

When I set this up with iCal on MacOS X 10.5 the script runs without launching Script Editor.

I have found that the EPG can be lacking for some HD channels, but the regular channels are ok.

Unknown said...

Hi, thank you so much for this script!! One issue that I am having though, I can download the scheduling fine on my laptop but it errors out on my mini for some reason. What do you think could be the problem?

benb :)) said...

Aubrey, I have no idea why it would not work on your Mac Mini. I run mine on a Mac Mini and it runs fine. You can you tell me what the error message is?

Unknown said...

Hi Benb,
I know, it's the weirdest thing. There has to be some sort of difference for this to happen right? The error is exactly this.
"Applescript Error - Can't make some data into the expected type."

thanks for your help.

benb :)) said...

Aubrey, if the script works ok on your laptop, can you copy the entire folder (including the Applescript and all the xml files) onto the Mac Mini and see if that runs ok? Also are they running different MacOS versions?

Unknown said...

Hi benb, I have done that a couple times before to the same results. I have 10.5.7 on both machines as well. What I have to do now is run the script on the laptop, throw the files on the mini then launch eyetv with the xml every time I want to update, not that big of a deal but it would be nice to have automated I dont have to worry about it. Puzzling

pundi said...

Thanks Ben, very much appreciate you making this available. Have had horrific experiences in the past with win mce and icetv - so was keen to avoid them with the new mac mini.

Unknown said...

I also have the same issue on the Mac Mini (OSX 10.4 Tiger, EyeTv 3.01 Diversity.)


Script runs; downloads the channels manifest, allows me to select channels to write the channels_for_epg.xml file but then fails with

system events got an error:Can't make every XMl element of XML element 1 of contents of XML file "Macintosh.Applications.Applescript:datalist.xml whose name = channel" and ID = SevenHD" into type reference

any ideas?

benb :)) said...

@robot: I tried setting up new channels this morning including Seven HD (on 10.5.7) and it worked ok for me. Does this error occur if you don't select Seven HD?

Probably best to email me your channels_for_epg.xml file (email address in the Read Me.rtfd file) and I will see if I can work out what is wrong.

Anonymous said...

Thanks for posting this script
I have:
EyeTv 3.2, Mac OS X 10.6.1, EyeTV Hybrid

The error I get is "System events got an error: some data was the wrong type.

benb :)) said...

@Creative Tips: I have been unable to reproduce this error message in the past. If you are in Australia I highly recommend you use the DVB guide which is now more accurate.

Anonymous said...

Hi Ben,

Just set up my mini with EyeTV+IceTV and was disappointed to see no EPG for Win WA. Your script solved the problem.. brilliant. Thanks for making the effort and providing it to all!

Unknown said...

Hey there, I posted quite a while ago how I had to do the download on another machine then open up the xml on the min well after a year having to do that I finally redid the machine from scratch and now it all works as it is supposed to now I dont have to manually do it, the mini does it all automatically. I true pvr now!!! yay, thanks fro the great script!!

Unknown said...

Ok its doing it again, but now I think I know what has created the "applescript error - Finder got an error: Can’t make file "Macintosh HD:Users:aubreysmith:Downloads:Download xmltv for EyeTV:Daily Channel Files:ABC3_2010-04-06.xml" into type ". It was working fine right before I installed Xcode, which I need to install Macports. You have any idea why?

benb :)) said...

@Aubrey, I do not know why the script is failing. I no longer use it on my Mac Mini as I just use the DVB guides (which I have found to be more accurate). I recommend you change to the DVB guide.

Unknown said...

I do use them for the ABC channels but, being in regional WA, I have GWN and WIN that are not digital yet and for some reason the sbs channels are not working with dvb. I guess I will just have to go back to using my other computer to run the script.

Unknown said...

Hi, I've found a bit of a solution and seems to work very well. If anyone else is having issues with this script theres a java alternative here: http://paulshipley.id.au/index.php/tools/xmltv-for-eyetv
You cannot do an automated running of this yet, but Mr. Shipley has informed me that he is in the process of getting this accomplished.

jamtoast said...

Hey Ben
Do you know a way of automating the DVB update in EyeTV?

benb :)) said...

Graham, there is no Applescript command to update the DVB guide. You could try UI scripting to do this, but that will be difficult.

Daniel said...

I have an idea. When you tune into channel XYZ, using the dvb Eyetv automatically updates the dvb for the channels on that frequenc. We need a script that takes advantage of this.

At some specified convenient time eg 5am,
open a viewing window
Mute the soundl
Wait long enough to update epg (eg 5 sec)
Channel down
cycles through x channels where x is the total number of set channels
Close window
Sleep

Anyone skilled enough to program this?

benb :)) said...

Daniel - I find that EyeTV updates all channel info even if you are not tuned to that channel. Eventually...

bsk said...

I'm trying to write something similar to download Radio Times data (for the UK) and put it in eyeTv because I hate the tvtv peg we have to use. I'm only moderately skilled in Applescript and know nothing of xml so reading your code is giving me loads of ideas. Thanks for posting it as there does not seem to be anything else out there in a similar vein.