# # $Id: ltk_seasonpass.itcl,v 1.4 2002/08/06 05:41:21 karlsson Exp $ # # ltk_seasonpass.itcl - dump the contents of the season pass directory # # # get output # proc ltk_output {chan priority title channum channame callsign recordquality keepatmost keepuntil showtype starttime endtime} { # # Open the table # #puts $chan [html_table_start "" "" "" ] # # Output the header row # #puts $chan [tr "" [th "Priority"][th "Title"][th "Channel"][th "Name"][th "Quality"][th "Keep At Most"][th "Keep Until"][th "Type"][th "Start Time"][th "End Time"]] # # Output the data. # # Modify the row variable to fit your output needs. # #set row [tr "" [td "$priority"][td "$title"][td "$channum"][td "$callsign"][td " $recordquality "][td " $keepatmost episodes "][td " $keepuntil "][td " $showtype "][td " $starttime "][td " $endtime "]] set row "$priority|$title|$channum|$channame|$callsign|$recordquality|$keepatmost|$keepuntil|$showtype|$starttime|$endtime" # # Write the output # puts $chan "$row" # # Close the table # #puts $chan [html_table_end] } # # get priority # proc ltk_getpriority {sp} { set priority [strim [dbobj $sp get Priority]] incr priority return $priority } # # get keep until # proc ltk_getkeepuntil {sp} { set keepuntil [defaultval 1 [dbobj $sp get KeepTime]] if {$keepuntil == 0} { set keepuntil "Until I delete" } elseif {$keepuntil == 1} { set keepuntil "Space needed" } else { set keepuntil "UNKNOWN" } return $keepuntil } # # get keep at most # proc ltk_getkeepatmost {sp} { set keepatmost [defaultval 0 [dbobj $sp get MaxRecordings]] if {$keepatmost == 0} { set keepatmost "All" } return $keepatmost } # # get recordquality # proc ltk_getrecordquality {sp} { set recordquality [defaultval 100 [dbobj $sp get RecordQuality]] if {$recordquality == 100} { set recordquality "Best" } elseif {$recordquality == 75} { set recordquality "High" } elseif {$recordquality == 40} { set recordquality "Medium" } elseif {$recordquality == 0} { set recordquality "Basic" } else { set recordquality "UNKNOWN" } return $recordquality } # # get showtype # proc ltk_getshowtype {sp} { set showtype [defaultval 0 [dbobj $sp get ShowStatus]] if {$showtype == 0} { set showtype "Repeats & first run" } elseif {$showtype == 1} { set showtype "First run only" } elseif {$showtype == 2} { set showtype "All (with duplicates)" } else { set showtype "UNKNOWN" } return $showtype } # # get series title # proc ltk_getseriestitle {sp} { set series [dbobj $sp get Series] set title [strim [dbobj $series get Title]] return $title } # # get channel callsign # proc ltk_getcallsign {sp} { set station [dbobj $sp get Station] set callsign [dbobj $station get CallSign] return $callsign } # # get channel number # proc ltk_getchannum {sp} { global channeltablestation set station [dbobj $sp get Station] set stationfsid [dbobj $station fsid] set data $channeltablestation($stationfsid) set channum [lindex $data 0] return $channum } # # get channel name # proc ltk_getchanname {sp} { set station [dbobj $sp get Station] set channame [strim [dbobj $station get Name]] return $channame } proc get_nextmanualrectime {dowlocal starttime} { global tzoffset set nowsecs [clock seconds] if { $starttime > 86400 } { set dow [expr $dowlocal + 1] } elseif { $starttime < 0 } { set dow [expr $dowlocal - 1] } else { set dow $dowlocal } set nowtime [expr ($nowsecs / 86400) * 86400 + $starttime] set downow [clock format $nowtime -format "%w"] if { $downow > $dow } { # day is earlier than now set rectime [expr $nowtime + ($dow - $downow + 7) * 86400] } elseif { $dow > $downow } { # day is later than now set rectime [expr $nowtime + ($dow - $downow) * 86400] } else { # day is today if { $starttime > [expr $nowsecs % 86400] } { # if record is later today set rectime $nowtime } else { # recording time has passed, get next week... set rectime [expr $nowtime + (86400 * 7)] } } return $rectime } # # Main function # proc action_tvd_spass {chan path env} { # # Set global variable # global db global tzoffset global seasonpassdir # # For each file in the mfs season pass directory, do the following # ForeachMfsFileTrans fsid name type $seasonpassdir "" 20 { # # Set the season pass database object to "sp" # set sp [db $db openid $fsid] # # Set variables that apply to all season pass types # set priority [ltk_getpriority $sp] set recordquality [ltk_getrecordquality $sp] set keepatmost [ltk_getkeepatmost $sp] set keepuntil [ltk_getkeepuntil $sp] # # Set the season pass type (1=regular, 2=manual, 3=wishlist) # set type [defaultval 1 [dbobj $sp get Type]] # # Regular Season Passes # if { $type == 1 } { set showtype [ltk_getshowtype $sp] set title [ltk_getseriestitle $sp] set callsign [ltk_getcallsign $sp] set channum [ltk_getchannum $sp] set channame [ltk_getchanname $sp] # # Set start time and end time # set starttime [defaultval 0 [dbobj $sp get StartTimePadding]] if {$starttime == 0} { set starttime "On-time" } set endtime [defaultval 0 [dbobj $sp get EndTimePadding]] if {$endtime == 0} { set endtime "On-time" } ltk_output $chan $priority $title $channum $channame $callsign $recordquality $keepatmost $keepuntil $showtype $starttime $endtime # # Manual Recording Season Passes # } elseif { $type == 2 } { set station [dbobj $sp get Station] set stationfsid [dbobj $station fsid] set callsign [ltk_getcallsign $sp] set channum [ltk_getchannum $sp] set channame [ltk_getchanname $sp] # # Get GMT start time # set starttimelocal [dbobj $sp get StartTimeLocal] set starttime [expr $starttimelocal - $tzoffset] set mystarttime [clock format $starttimelocal -format %R] # # Get duration # set duration [dbobj $sp get Duration] # # Get GMT stop time # set stoptime [expr $starttimelocal + $duration] set mystoptime [clock format $stoptime -format %R] # # Day of week # set dowlocal [dbobj $sp get DayOfWeekLocal] if {$dowlocal == 0} { set dayofweek "Sunday" } elseif {$dowlocal == 1} { set dayofweek "Monday" } elseif {$dowlocal == 2} { set dayofweek "Tuesday" } elseif {$dowlocal == 3} { set dayofweek "Wednesday" } elseif {$dowlocal == 4} { set dayofweek "Thursday" } elseif {$dowlocal == 5} { set dayofweek "Friday" } elseif {$dowlocal == 6} { set dayofweek "Saturday" } elseif {$dowlocal == "0 1 2 3 4 5 6"} { set dayofweek "Sunday - Saturday" } elseif {$dowlocal == "1 2 3 4 5"} { set dayofweek "Monday - Friday" } else { set dayofweek "UNKNOWN" } # # This section happens if the recording occurs on more than one day. # # For each of the days it is supposed to record check when the next # time that happens and find the one that is most near. # # The result is the next record time (rectime) of the manual season # pass. # if { [llength $dowlocal] > 1 } { set rectime "" foreach dowl $dowlocal { set tmprectime [get_nextmanualrectime $dowl $starttime] if { $rectime == "" || $tmprectime < $rectime } { set rectime $tmprectime } } } else { set rectime [get_nextmanualrectime $dowlocal $starttime] } # # This finds which Station/Day pair to search in /Schedule. # set datestr [format "%d:%d:" $stationfsid [expr $rectime / 86400]] # # This gets the list of schedule items for that Station/Day. # set schedlist [get_fsidbyprefix "/Schedule" $datestr] # # This finds the first matching item for that day in the schedule. # If it's too late, it checks the previous day. # set timestr "" scan [lindex $schedlist 1] "%d:%d:%d:" dummy dummy2 timestr if { $timestr > $starttime } { set datestr [format "%d:%05d:" $stationfsid \ [expr ($rectime / 86400) - 1]] set schedlist [get_fsidbyprefix "/Schedule" $datestr] } # # If we got a list of schedule times, check them. # if { $schedlist != "" } { set stationday [db $db openid [lindex $schedlist 0]] set showings [dbobj $stationday get Showing] set mshowing "" # Code from TVD # Deal with the day issue... if { $starttime > 86400 } { set starttime [expr $starttime - 86400] } elseif { $starttime < 0 } { set starttime [expr $starttime + 86400] } # # Make sure the recording occurs during a showing. # foreach showing $showings { set stime [dbobj $showing get Time] set sdur [dbobj $showing get Duration] if { $stime <= $starttime && $starttime < [expr $stime + $sdur] } { set mshowing $showing break } } # # Get the title of the season pass. # set title "" if { $mshowing != "" } { set program [dbobj $mshowing get Program] set series [dbobj $program get Series] set title [strim [dbobj $series get Title]] } } ltk_output $chan $priority "Manual Recording: $title" $channum $channame $callsign $recordquality $keepatmost $keepuntil "$dayofweek, $mystarttime-$mystoptime" "" "" # # Wishlist Season Passes # } elseif { $type == 3 } { set theme [dbobj $sp get Theme] set themefsid [dbobj $theme fsid] set title [strim [dbobj $theme get Name]] ltk_output $chan $priority "Wishlist: $title" "" "" "" $recordquality $keepatmost $keepuntil "" "" "" } } } register_module "tvd_spass" "TVD Season Pass List" "TVD's list of Season Passes."