3/20/13

Workflow Processing Multiple Files - TiVo Edition



It seems that there are a lot of people that have been struggling with their TiVo. Like me they want to watch shows when the want, where they want and on the device they want. The problem is getting the recorded show off the TiVo, decrypted, edited then transcoded into a file type that their personal device can play. 

I originally wrote about an application called iTiVo that made this process a lot easier.

TiVo & the Mac - Downloading TiVo files

Then an OS update broke iTiVo so I wrote up a work around. You can read about it here:

TiVo to Mac - Mountain Lion Edition

After a few months, when iTiVo finally became usable again, I wrote up a quick way to update the beta version to get full functionality back. 

Continuing Adventures with iTiVo

I don't know when iTiVo will be updated to work without major surgery but hopefully it will be soon. So while we wait I want to answer a question that has been asked a lot during this whole process; How do I create a Apple Workflow that will process multiple files? This question doesn't just apply to processing TiVo files of course but I'll use that as my example.

Apple provides a great tool for speeding up and automating your work tasks. It's called Automator. It's an easy tool to get to know but getting it to do just what you want, in the way you want can be a trial. 

Let's assume for a minute that iTiVo is broken again and you want to watch the entire season of Supernatural that currently sits on your TiVo. Downloading the files is easy. You can use the web version I wrote up here, or if you have Roxio's Toast you can use the included "TiVo Transfer" application to download your files. Either way you end up with a file on your Mac that is encrypted. So let's decrypt them. 

Assuming you have followed all my directions you should have a copy of tivodecode loaded on your Mac. Now all you need is an Automator Workflow to convert all the files. Not one at a time, but in a batch so you can set it running before you go to bed. 

Open up the Automator application and create a new Workflow


In the column at the left you will need to select "Files & Folders" icon on the left then drag the "Ask for Finder Items" into the window pane on the right.  In the "Prompt" section just type in "Choose a Tivo file(s)" and fill the folder location you normally use when you download your Tivo files.  To handle multiple files make sure that the Type is set to "Files" and "Allow Multiple Selection" box is checked. 




In order to deal with multiple files we need to assign them as variables. Select "Utilities" from the Library and drag "Set Value of Variable" to the right window pane. In the Variable box create a new variable. I called mine "Tivo_File". 




Just as an explanation, the variable "Tivo_File" will be set to the file or files you select manually when you run the action. The value of the variable will be the full name of the file including path.

example:

.../TiVo Files/Supernatural_Hunteri_Heroici_111 KSTWDT_1363233538.TiVo

This is a very important point that we will have to deal with later in the shell script. The tivodecode application needs both the path to the file and the file name.  Now that the variable is set we need to use it.

Again select "Utilities" from the Library and drag "Get Value of Variable" to your script. It seems odd, and you would think the computer should remember the variable because you just set it, but that's the way scripting works. Especially when dealing with multiple files. Make sure that the Variable is set to "Tivo_File" or whatever name you choose in the set variable value step.



Another important point is to make sure the "Ignore this action's input" check-box is checked in the options tab since our input is the variable itself. 

Now that we have our variable we need to run a shell script to decode it. Grab the "Run Shell Script" action from utilities and move it to the Window pane on the right.  Make sure the "Shell" is set to "/bin/bash". 

The first thing we do is start a loop to process each of the files you selected. I have titled my loop counter as the letter "i".  

      for i in "$@"
       do

After we start our loop we need to decode our variable and just grab the file name without the full path information in front of it. To do that I choose to use the UNIX awk command. There are a lot of ways to do this but this one works. The assumption here is that your file name extension has .TiVo at the end. Or to be more exact, it has a dot "." and an extension at the end of the file name.  I've set the file name to a script variable called "fname". 

fname=`echo $i | awk -F"/" '{print $NF}'| awk -F"." '{print $1}'`

After we have the file name we need to run tivodecode. 

tivodecode -m 1234567890 -o "/MacHD/Users/Username/Movies/$fname.mpg" "$i"

Remember to insert your real MAK address into the command where I have put "1234567890". Also insert the real path to your output file. The output file will be the same as your downloaded TiVo file name but with an ".mpg" extension.  The "$i" at the end of of the statement is the full path & filename. Make sure to inlude the quotes as I have shown above.

Since that's all the processing we need to close the loop by adding "done" at the end of the script.   This is how your script should look.



Since that's the last step here's a copy of the entire automator action


You can check your script at this point by hitting the run button at the top. If it all works as planned you are ready to save your Automator Workflow as an executable app. Make sure it's saved as an application in the "File Format" drop down menu.

Happy converting and I hope this answers the question of how to process multiple input files in a single script. 



3/4/13

What do Geeks do on their day off?

This past weekend Seattle hosted the Emerald City Comicon. According to their web site it's "the largest comic book and pop culture convention in the pacific northwest!" After attending this geekfest I tend to agree. It was jammed with artwork, comics, TV stars, & people dressed as their favorite characters. It was a a great break from the more technical side of my brain and my family and I had a blast. 



I thought you might enjoy some photos just to help get you through your Monday. Enjoy! If you see a friend, someone you know or yourself leave a comment and I'll send you a copy of the photo.  



These escalators are empty at this point. Usually they were packed. 



Notice the eyes? Where do you get yellow contacts? Oh, right they sell them in one of the booths. 


Makes my neck hurt just looking at her


You wonder how much makeup you go through to get yourself this pink all over?


Just how many cows died to make this!?


Couples often coordinated their costumes


Artists were working during the show


A Seattle icon with a twist


The depth and breadth of the artistic skill was impressive


This artist actually worked for WB and was one of the animators for Pinky and the Brain as well as Animaniacs


Great booths with lots to see


Say it with me, "Drinking blood is bad"



Who knew under all that armor Boba Fett had tats and needed more.


Here's a Brave little girl.


It's all about comics. 


My legs hurt just looking at these costumes. Let alone walking around in them for 3 days.


The floor space was HUGE. 


"No ghosts here... I think..."


Girl power


Everyone took pictures. 


Nice toys were also available


Misha Collins - The reason my wife and daughter wanted to go to the con.


Red Sonja


Queen of Hearts


Riddle me this 


Steam Punk and some nice gaming furniture


Comic/CosPlay fans come in all ages


Spidey sense isn't always enough and sometimes you just have to text


I found this guy outside the men's room. Looks like even Waldo needs to go sometimes.


Venom


The requisite Storm Trooper


Here's a motley crew



Even heros have to rest for a while.



What a family. 


There are so many characters and I soon realized that those that grew up on DC comics or Marvel are in the minority. With the web, TV and all the independent comic companies it's hard to know what series this is from. 


Ready for action!


Had a fun time talking to this very nice person. She wasn't sure anyone would want to take her picture. But I think the costume is great.


A princess for sure


I'm not quite sure what this is but all I can say is Wow!


A Cylon from my youth


Avitar


The Joker


Zombie Rogers - So wrong, yet so right


Antonia Stark


Jack Frost


Baby-Fett