Hack 91. Discovering Your Favorite Actors

   

Hack 91 Discovering Your Favorite Actors

figs/moderate.gif figs/hack91.gif

Ever think about who your favorite stars of the small screen are? I don't mean those you can think of off the top of your head. I mean based on actual television viewing habits .

We already have a framework to key off and siphon data from the television shows in the Now Playing List [Hack #90]. Now, let's gather some slightly different data. We'll make an account of all the actors and actresses in the television shows we watch, perhaps spotting trends in those we tend to gravitate toward.

Programmatically, this isn't any more than grabbing the Actor rather than the Title and EpisodeTitle attributes from the Program object. The Actor object lists all the stars of a particular show, which we'll parse to draw out the individual names and tally up the number of times they show up in your Now Playing List .

The Code

 #!/tvbin/tivosh # open the database, and for each television show, # extract the date it aired, the title of the show, # and the episode title set db [dbopen] # pull out the first 50 recorded shows from the database  set recdir "/Recording/NowShowingByTitle  " RetryTransaction {     set files [mfs scan $recdir -count 50] }  set actors { }  while { [llength $files] > 0 } {     # iterate through the shows we extracted     foreach rec $files {         # grab the FSID of the program from the list         set fsid [lindex $rec 0]         RetryTransaction {             # get the object that represents this recording and the             # object that represents this episode.  wrap it in a              # catch just in case it doesn't work             set recordingobj [db $db openid $fsid]             set episodeobj [dbobj [dbobj $recordingobj get Showing] get  Program]  # pull out the list of actors in this show   set epactors [dbobj $episodeobj get Actor]   }   # transform the actors names into strings and append them to   # our list of all the actors on our TiVo   foreach epactor $epactors {   set slashpos [string first "" $epactor]   set repactor \  "  [string range $epactor 0 [expr $slashpos - 1]]  ,"  set repactor \  "  $repactor [string range $epactor [expr $slashpos + 1] end]  "  lappend actors $repactor   }  }     # and grab the next 49 television shows     set lastName [lindex [lindex $files end] 1]     RetryTransaction {         set files [mfs scan $recdir -start $lastName -count 50]     }     if { $lastName == [lindex [lindex $files 0] 1] } {        set files [lrange $files 1 end]     }      }  # create a new list called factors that is the frequency count of the   # actors on the shows we have watched   set factors { }   foreach l $actors {   if ![ info exists a($l) ] {   set a($l) 0   }   incr a($l)   }   foreach i [ array names a ] {   lappend factors [list $i $a($i)]   }   # and let's quickly alphabetically sort then print the list  [RETURN]    set factors [lsort -index 0 $factors]   foreach factor $factors {   puts "[lindex $factor 0]  [lindex $factor 1]  "  }  

Save the code to a file called actors.tcl in TiVo's /var/hack/bin directory and make it executable:

 bash-2.02#  chmod 755 /var/hack/bin/actors.tcl  

Running the Hack

Run the script from TiVo's command line Section 3.3:

 bash-2.02#  /var/hack/bin/actors.tcl  Ackles, Jensen  4 Agena, Keiko  2 Berkeley, Xander  1 Bernard, Carlos  1 Bishop, Kelly  2 Bledel, Alexis  2 Brook, Jayne  1 Burton, LeVar  1 Carradine, Ever  1 Channing, Stockard  4 Corbett, John  1 Cuthbert, Elisha  1 Dorn, Michael  1 Esposito, Giancarlo  1 Forsythe, William  1 Frakes, Jonathan  1 Gardell, Billy  1 Glover, John  4 Graham, Lauren  2 Gunn, Sean  2 Haysbert, Dennis  1 Herrmann, Edward  2 Hill, Dule  4 Holmes, Katie  15 Hudson, Oliver  5 Humes, Mary-Margaret  1 Jackson, Joshua  15 Janney, Allison  4 Jerald, Penny Johnson  1 Jones III, Sam  4 Jones, John Marshall  1 Kajlich, Bianca  5 Kreuk, Kristin  4 Lowe, Rob  4 Mack, Allison  4 Malina, Josh  1 McCarthy, Melissa  2 McFadden, Gates  1 Moloney, Janel  4 ... 

To capture your list of favorite actors as a pipe-delimited text file, use the > redirect symbol and supply the name of a file to which to write. For example, sending output to a file called actors.out in the /var/out directory would look like this:

 bash-2.02#  /var/hack/bin/actors.tcl > /var/out/actors.out  

   
Top


Tivo Hacks. 100 Industrial-strength Tips Tools 2003
Tivo Hacks. 100 Industrial-strength Tips Tools 2003
ISBN: 1597490318
EAN: N/A
Year: 2004
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net