O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



HACK
#92
Discovering Your Favorite Writers, Producers, and Directors
Do you tend to favor the work of a particular director? Do the words of a particular writer keep you riveted to the screen? Chances are that you haven't given your favorite creatives much thought. Thankfully, TiVo keeps track of them for you
The Code
[Discuss (0) | Link to this hack]

The Code

#!/tvbin/tivosh

global creativesproc addcreative { c type } {global creativesforeach epcreative $c {set slashpos [string first "|" $epcreative]set repcreative \
            "[string range $epcreative 0 [expr $slashpos - 1]],"↵set repcreative \ 
            "$repcreative [string range $epcreative [expr $slashpos + 1]↵end]"   
        set repcreative \
            "$repcreative | $type"
         lappend creatives $repcreative 
}}

# open the database
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 creatives { }
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 writers, directors, and producers of the# shows.  none of these are guaranteed to be hereset epwriters [dbobj $episodeobj get Writer]set epdirectors [dbobj $episodeobj get Director]set epproducers [dbobj $episodeobj get ExecProducer]}# add all those creatives to a list to work withaddcreative $epwriters "Writer"
        addcreative $epdirectors "Director"
        addcreative $epproducers "ExecProducer"
    }

    # 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 fcreatives that is the frequency count
# of the creatives on the shows we have watched
set fcreatives { }
foreach l $creatives {
    if ![ info exists a($l) ] { 
        set a($l) 0 
    }
    incr a($l) 
}
foreach i [ array names a ] {
    lappend fcreatives [list $i $a($i)]
}

# and let's quickly alphabetically sort then print the list
set fcreatives [lsort -index 0 $fcreatives]
foreach fcreative $fcreatives {
    puts "[lindex $fcreative 0] | [lindex $fcreative 1]"
}

Save the code as creatives.tcl in TiVo's /var/hack/bin directory and make it executable:

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


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.