View Full Version : ty-collector.php -episode collection utility script

02-25-2006, 04:08 PM
What is is: a PHP script (runs standalone, outside of Apache).

What it does: uses mfs_ftp to check for episodes of shows you're collecting; if it finds one you don't have already, it downloads it, and then attempts to retrieve the season # / episode # from TV.com, and names the downloaded file accordingly. So, for example, my extracts folder looks like this:

Family Guy
03-12 - To Live and Die in Dixie.ty
04-09 - Breaking Out Is Hard to Do.ty
01-03 - I, Roommate.ty
02-12 - Raging Bender.ty

When I have time, I edit out commercials and convert to .mpg files using TyTool, move the final files to my video\shows folder (with the same subfolder structure for each show), and delete the downloaded .ty files. The script checks for episodes in both folders, so if I already have the processed file, it won't download the .ty file again.

Why? I tried eTivo, but it wasn't quite what I was looking for - it does a whole lot more than what I wanted. I just wanted a way to simplify / automate the collection process, but leave the commercial editing / post-processing to me. This does just the collecting part.

Let me know what you think.

02-25-2006, 04:19 PM
There's also TyExtract (http://www.dealdatabase.com/forum/showthread.php?t=34932).

02-25-2006, 10:35 PM
Do I need a specific version of php? Not having any luck with php5. it is erroring out.

Fatal error: Call to undefined function curl_init() in I:\Tivo\ty-collector-0.1\
extended-episode-info.php on line 7


02-25-2006, 10:53 PM
You'll need to enable curl support - if you're on Windows, its compiled in, just go into the php.ini file and remove the ; comment character before the curl module:


If you're on unix and you built your own distribution, you'll need to compile it with the appropriate flag to include curl - check php.net for more info, just search for "curl" on their site under documentation.

02-25-2006, 11:26 PM
Thanks, that fixed that, now if I can just figure out what is wrong with mfs_ftp.


02-27-2006, 06:53 PM
There's also TyExtract (http://www.dealdatabase.com/forum/showthread.php?t=34932).

Thanks, I hadn't run across that one - I haven't used it before, but after reading through the thread, in case anyone is interested, here is a rundown of the differences and similarities:

- used to collect episodes of a show that you have on your TiVo (season pass, or wish list, or whatever)
- use mfs_ftp to retrieve Now Showing list and do extraction

- Windows executable
- extracts shows based on specified keywords
- options are specified as command line parameters
- can limit scan to a specific date range
- output file names based on mfs_ftp settings + -n parameter
- optionally can delete show off TiVo after downloading
- collecting multiple shows is done by running the utility multiple times, one per show, or by passing in a list of shows in a text file
- can shutdown mfs_ftp when done, if desired
- will not download the same show twice, if a matching .ty (etc.) file is found; but if output file name includes the channel, the same show on multiple channels may be downloaded
- downloads into a "flat" directory structure
- optionally can invoke post-processing commands

- PHP script: can be run on Windows, *nix, Mac, etc., and can be modified by anyone who knows PHP
- extracts episodes of whatever shows you specify by creating a folder with the show name
- options are specified in the ty-collector.ini file
- looks at the entire Now Showing list on your tivo to find any shows that you haven't collected yet
- output file names are the episode name, plus optional <season #>-<episode #> prefix; stored in folders matching the show name
- does not delete show off TiVo after downloading
- always collects whatever shows you have configured (by creating a folder matching the show name) in one pass
- cannot shut down mfs_ftp when done
- will not download the same episode twice, based on looking for a matching episode title (or OriginalAirDate, if show has no episode titles) - this includes non-ty files (like shows already processed to .mpg or .avi)
- downloads episodes into folders for each show
- does not (yet) invoke any post-processing commands
- optionally prepends season-episode #s to filename, if available, from tv.com episode info
- optionally downloads associated XML file from mfs_ftp, using the same name prefix as the ty file

If I've misrepresented anything on the TyExtract side, please let me know and I'll correct it.

Another obvious difference is that TyExtract has had several people bang on it over time already, while my ty-collector script has been tested only by me (that I know of) on my S1 DTivo for the last couple weeks.

Anyway, if you like collecting show episodes, and don't have a solution of your own in place, take a look at one or the other :-)

03-02-2006, 08:24 PM
Nice script! Thanks for sharing...


03-03-2006, 01:50 PM
Nice script! Thanks for sharing...


Thanks Moat, glad you found it useful :-)

02-02-2007, 10:59 PM
I can't believe I never saw this script before now. It's a great utility!
I had to make a couple tweaks to get it working in my environment.

The first problem I ran into is that PHP 4 does not have a scandir() function which is used in this script (I know, I know...still using PHP4). I overcame that by putting the following code in ty-collector.php:

function scandir($folder){
$dh = opendir($folder);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
return $files;

I also kept getting a max_execution error, so I added the following:

ini_set('max_execution_time', 0);

And finally, I don't know if this is a bug in general, or just something weird with my setup, but the date calculation routine was consistently getting the date wrong. It always calculated one day early. So I changed this line:

$days_since_1970 = $days_since_1970 * 24 * 60 * 60;
to this:

$days_since_1970 = ($days_since_1970 + 1) * 24 * 60 * 60;

Thanks for creating this script. I LOVE that it was written in PHP so I can easily make changes!