• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

7. Writing Code > 92. Discovering Your Favorite Writers, Producers, and Directo...

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.

A variation on [Hack #91], let’s give a little credit to the creatives—the writers, producers, and directors—while at the same time learning a little more Tcl.

The Code

#!/tvbin/tivosh

global creatives
               proc addcreative { c type } {
               global creatives
               foreach epcreative $c {
               set slashpos [string first "|" $epcreative]
               set repcreative \
            "[string range $epcreative 0 [expr $slashpos - 1]],"[RETURN]
               
               set repcreative \ 
            "$repcreative [string range $epcreative [expr $slashpos + 1][RETURN]
               
               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 ....# pull out the list of writers, directors, and producers of the
               # shows.  none of these are guaranteed to be here
               set 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 with
               addcreative $epwriters "Writer"
        addcreative $epdirectors "Director"
        addcreative $epproducers "ExecProducer"
    }

    # and grab the next 49 television shows[RETURN]
    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]"
}

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint