Update: The information below is about TV Forecast version 2.3.5. Since I wrote the post below, Matt Comi released an official fix, namely version 2.4, which now use TVRage.com as its data source. You should use TV Forecast official releases (1st link below), instead of trying to hack an old widget’s code like I did below.

TV Forecast is a nice widget that Matt Comi created. You tell it what TV shows you watch, and it will keep track of the upcoming episodes for those shows.

tv_forecast_fixed

The only down side to that widget is that it data-scrape TV.com to get its data.
Not only is this illegal, but it also tends to break the widget every time TV.com change their layout in any way.

Getting tired of that, I decided to open the widget’s code, and change the data source to something more stable: TheTVDB.com
They provide a quite stable API to query their database, which is user-maintained.
TVRage.com has something similar, but my eyes hurt each time I go on their site, so I picked TheTVDB for now!

Update: Another good reason to pick TheTVDB over TVRage at this time: TVRage XML feeds are currently unavailable.

tv_rage_doww

TheTVDB offer a search service, so changing the search function of the widget was easy enough.

Fetching the next episode information was trickier.
The API doesn’t offer an easy way to do that. They only provide XML data of all the episodes of a show; this is quite a lot to download for a small widget, just to know what’s the next episode…
So I created a middle-man.
This data proxy queries the API for an answer, and will then cache the result for 24 hours (48 hours for not running series; 1 week for ended series), before it will refresh its information again.
That way, each client running the widget can query the data proxy, which can use cached informations to return answers very fast, and in a very efficient way.

Note that the files packaged below are still Matt Comi’s property. I do not pretend to now own them in any way. I redistribute them here to allow end users to continue using his nice widget until he has time to fix his widget himself.

So… want to fix your own TV Forecast widget? Here’s how:

  • Right click ~/Library/Widgets/TV Forecast.wdgt and select Show Package Contents.

This in how this should look before you touch anything:

tv_forecast_fix_1

  • Copy the files found in this archive one by one into the TV Forecast.wdgt directory. Do not attempt to copy the TV folder itself found in my archive, or you’ll remove necessary files from the widget.
    i.e. You need to copy the files inside it, but not the folder itself.

There’s one new file (TvShowParser2.js) that goes in the TV folder, the rest are files I modified, so you need to overwrite the existing files with mine.

Here’s how it should look after copying the new files:

tv_forecast_fix_2

  • Reload (Cmd-R) the widget, or remove then re-add it to your Dashboard.

  • Remove and re-add all TV shows in the widget’s configuration.

For the curious ones, here’s the diff of all my changes, plus the code for the data proxy script used by the widget. Feel free to use that script on your own server, and edit TV/Functions.js to point to your version of the script. It requires PHP 5 and MySQL, among other things…