ImporTiVo Scripts/Binaries
By Jeremy Laurenson
www.map-pin.com

Why I created these scripts/apps:
	Most existing TiVo to mac converters are serial in nature. They download a file, then 
	decode it, then comskip it, then encode it, then add to iTunes...
	While a file is encoding, why not download the next one? What a time saver!
	These scripts run concurrently to try do as much as possible in as little time as
	possible, and also give you settings on a per-show basis for commercial skipping, artwork
	as well as encoding options.

	Example of the time savings/concurrency:
	
	ls | grep inprogress
	ComskipList.inprogress
	DownloadList.inprogress
	EncodeList.inprogress
	TagList.inprogress

	Machine is Downloading a file from TiVo (<5% CPU)
	Machine is determining commercial skipping (40% CPU)
	Machine is Tagging MP4 files (10% CPU)
	Machine is encoding at the same timeÉ (Rest of 200% CPU)

	Much more efficient.
	



Important/Issues:
	I use a bunch of binaries from other folks, and have not included any acknowledgments yet.
		mencoder	http://www.mplayerhq.hu
		comskip		http://www.kaashoek.com/comskip/
		tivodecode	http://tivodecode.sourceforge.net/
		atomicparsley	http://atomicparsley.sourceforge.net/
		growlnotify	http://growl.info/
	Everything is case sensitive. Heroes <> heroes, for example.





Basic Setup:
	Move the ImporTiVo directory somewhere that you want it. TV Shows in process will live inside
	this directory.. so make sure its big enough.

	Edit ImporTiVo_Settings.sh and move it into your home directory (~) This points all other things
	to the right place...

	Now, check out the config directory... it has some files you will want to rename and then edit:
	(remove the .example from the filename and edit:)

		settings.txt		Fill in your: (Each on a separate line, with a blank line at the end)
					TiVo IP
					MAK
					full path to theImporTiVo directory, with a trailing /
					full path to iTunes Watch Folder, with a trailing /
		recordlist.txt 		Edit this file to include case sensitive show names of shows to get.
					ImporTiVo scripts will only download shows listed in this file.
		encoder.txt		This is the default set of encoder parameters. The encoder used is
					mencode since it allows for commercial splicing, while maintaining
					sync with video and audio properly. Other encoders did not work
		comskip.txt		This is the default file for comskip settings.
	
	Finally, after you have done all your customizing (read this whole doc), set up Cron Jobs
	for each of the 7 scripts:
	
	1_GetPrograms.sh	Just after the hour - say 8 mins after.
	2_DownloadList.sh	Every 10 mins
	3_DecodeList.sh		Every 10 mins
	4_ComskipList.sh	Every 10 mins
	5_EncodeList.sh		Every 10 mins
	6_TagList.sh		Every 10 mins
	7_iTunesList		Every 10 mins

My crontab looks like this: (Edit yours by typing crontab -e)

@reboot bash /Volumes/Drobo/ImporTiVo/rebooted.sh >/dev/null 2>&1
8 * * * * sh /Volumes/Drobo/ImporTiVo/1_GetPrograms.sh >/dev/null 2>&1
*/10 * * * * sh /Volumes/Drobo/ImporTiVo/2_DownloadList.sh >/dev/null 2>&1
*/10 * * * * sh /Volumes/Drobo/ImporTiVo/3_DecodeList.sh >/dev/null 2>&1
*/10 * * * * sh /Volumes/Drobo/ImporTiVo/4_ComskipList.sh >/dev/null 2>&1
*/10 * * * * sh /Volumes/Drobo/ImporTiVo/5_EncodeList.sh >/dev/null 2>&1
*/10 * * * * sh /Volumes/Drobo/ImporTiVo/6_TagList.sh >/dev/null 2>&1
*/10 * * * * sh /Applications/Utilities/Laurenson/checktunnelserver.sh  >/dev/null 2>&1
*/10 * * * * sh /Volumes/Drobo/ImporTiVo/7_iTunesList.sh >/dev/null 2>&1


Note the reboot script, which cleans out anything that may have been aborted half way through.

Notifications:
	This set of scripts uses growl to pop notifications on the screen... also You can
	tail -f importivo.log to see whats happening from the shell.. or
	tail -f importivoerrors.log to see whats breakingÉ



Advanced setup:
	There are a few folders used to set up unique settings per show. Create files
	in these directories to override the default settings used by the scripts...
	
	encodersettings		place <show name>.txt files in here to change the encoder settings for
						that show. You can copy the encoder.txt from the config directory as a
						starting point.
						
	artwork				place <show name>.jpg files in here to use the image as the show
						thumbnail. 500x500 is best...
						
	comskipsettings		place <show name>.ini files here to have comskip use those settings
						to detect commercials for the show. If the file simply has ***off***
						int he first line, commercials will not be skipped.
						
						
						
						
****************************************************************************************************						
						

There are 6 separate "Activities" that run as part of these scripts:


1... GetPrograms	Download of the current list of programs in the "Now Playing"
					list on your TiVo.
					This script calls GetNowPlaying binary, which calls
					getNowPlaying.pl, a perl script that downloads and formats
					the list.
					
					Schedule this to run each hour, a few minutes after the hour
					so that you get a current list of programs.

				
					
2... DownloadList	Downloads TiVo media files that are not already downloaded,
					and are not in progress on TiVo (still recording).
					This process only downloads the shows that are listed in the
					text file  recordlist.txt  inside the config folder. The list
					in this file is case sensitive.
					
					a... BuildDownloadScripts	parses all the shows, checks to see
												if theyre completed already or
												downloaded, and if not it downloads
												metadata and then also creates
												a script that will download the
												media.
					b... BuildQueue				Builds a queue of these download
												scripts.
					c... The queue to download is run.
					
					Schedule this to run ever 10 minutes or so.

					Programs successfully downloaded will have a file created
					for them called <Episodeid>.downloaded, in addition to the
					.tivo file in the show directory. (in data/<showid>)
				
				
					
3... DecodeList		Decodes all the existing .tivo files that are not already
					decoded. Uses the unix "find" command to build a list of
					<EpisodeID>.downloaded files, excludes ones with a corrosponding
					<EpisodeID>.decoded.
					
					a... BuildDecodeScripts	Builds the scripts to decode the .tivo
											files
					b... BildQueue			Builds a queue of those scripts.
					c...	The queue to decode is run.
					Schedule this to run ever 10 minutes or so.

					Programs successfully decoded will have a file created
					for them called <Episodeid>.decoded, in addition to the
					.mpg file in the show directory. (in data/<showid>)


4... ComSkipList	Generates a commercial skip file (edl,txt) for the mpg video.
					Uses the unix "find" command to build a list of
					<EpisodeID>.decoded files, excludes ones with a corresponding
					<EpisodeID>.comskipped file.
					
5... EncodeList		Generates encode scripts for all shows that have been comskipped.

6... TagList		Generates scripts to use atomicparsley to add tags to the mp4 files.

7... iTunesList		Generates scripts to add shows into iTunes, and then delete all the
					interim files, scripts etc. Only <episodeid>.complete remains to avoid
					future downloading of the same show again

