# What's On module for TiVoWeb. # Shows an hourly snapshot of what's on. # # Based very heavily on other parts of TiVoWeb! # # LJ @ http://www.tivocommunity.com/ # # 01Dec02 18:06 v1.0 # 01Dec02 19:40 v1.1 A bit faster! - doesn't read the starting time from the db twice in do_wochandata. # - aborts loop sooner if the title is "SIGN OFF". # Use time zone when working out current date. # 02Dec02 19:34 v1.2 Find all programmes when searching close to a day change. # Include channel links. # 03Dec02 20:43 v1.3 Tidy a few things to eek out a bit more speed! # Take account of the timezone properly. # 06Dec02 18:19 v1.4 Show appropriate icon if show scheduled for recording or in Now Showing. # Make Search button in focus on first run. # 08Dec02 11:40 v1.5 Add quick links for search back/forward 24/1 hours. # Make recycle symbol a link to undelete the programme. # 08Dec02 17:30 v1.6 Adding thumbs & rating/advisories (zvonar) # 15Dec02 08:26 v1.7 Show if any programmes scheduled to be recorded during the hour. # Include option to show only programmes that start in the hour/from now onwards. # 15Dec02 22:26 v1.8 Show 'Watch' buttons for programmes now on. # 28Dec02 11:38 v1.9 Change keys sent by watch buttons to cope with already being on Live TV. # 28Dec02 16:23 v1.10 Add 'Enter' key to end of channel change. # Add column for episode description. # 29Dec02 15:32 v1.11 Add call to slotfree code. proc action_whatson {chan path eenv} { global channeltablestation channeltablenum global logotablename logotableindex global db global guideindexdir global tzoffset global chnsel wodatetz wotimetz env chnvals chnlabels datevals datelabels timevals timelabels starting global minday maxday global reccount global usformat if { $env(TV_STD) != "PAL"} { set usformat 1 } else { set usformat 0 } set chnsel "2" set starting 0 set wodatetz [expr ([clock seconds] + $tzoffset) - (([clock seconds] + $tzoffset) % 86400)] set wotimetz [expr (([clock seconds] + $tzoffset - $wodatetz) / 3600 )] eval $eenv puts $chan [html_start "What's On Listing"] if { $eenv == "" } { set timevals "" set datevals "" set datelabels "" set timelabels "" set starting 1 set chnvals "3 2" if { $usformat } { set chnlabels "{Favorite Channels} {Channels Watched}" } else { set chnlabels "{Favourite Channels} {Channels Watched}" } for {set i 0} {$i < 24} {incr i 1} { append timevals "$i " if { $usformat } { append timelabels "[if {[expr $i % 12] == 0} { format "\{12" } else { format "\{[expr $i % 12]" }]" append timelabels "[if {$i < 12} { format " am\} " } else { format " pm\} " }]" } else { append timelabels "[string range "0$i" [expr [string length "$i"] - 1] end]\:00 " } } set minday "99999" set maxday "00000" set ictr 0 ForeachMfsFile fsid name type "/Schedule" "" { scan $name "%d:%d:" schedsid schedday if {$minday > $schedday} { set minday $schedday } if {$maxday < $schedday} { set maxday $schedday } incr ictr if { $ictr > 500 } { break } } set minseconds [expr $minday * 86400] set maxseconds [expr $maxday * 86400] for {set i $minseconds} {$i <= $maxseconds} {incr i 86400} { if { $usformat } { set timestr [clock format $i -format "%a %1m/%1d"] } else { set timestr [clock format $i -format "%a %e[switch -glob [clock format $i -format "%e"] {1? {format th} *1 {format st} *2 {format nd} *3 {format rd} default {format th} }] %b"] } append datevals "$i " append datelabels "\{$timestr\} " } } else { if { $submit == "Watch" } { if { [string length $channel] == 0 } { SendKey "livetv" } else { SendKey "guide" after 1500 SendKey "select" for {set i 0} {$i < [string length $channel]} {incr i 1} { after 200 SendKey "num[ string index $channel $i]" } after 200 SendKey "enter" } } } puts $chan [html_form_start "GET" "/whatson" "name=\"search\""] puts $chan [html_table_start "" "Search" "COLSPAN=2"] puts $chan [tr "" [td "Channels to search:"] [td "" [html_form_select "chnsel" $chnvals $chnlabels $chnsel]]] puts $chan [tr "" [td "Date to search:"] [td "" [html_form_select "wodatetz" $datevals $datelabels $wodatetz]]] puts $chan [tr "" [td "Hour to search:"] [td "" [html_form_select "wotimetz" $timevals $timelabels $wotimetz]]] if { $usformat } { set me "" } else { set me "me" } if { $wodatetz == [expr ([clock seconds] + $tzoffset) - (([clock seconds] + $tzoffset) % 86400)] \ && $wotimetz == [expr (([clock seconds] + $tzoffset - $wodatetz) / 3600 )] } { if { $starting } { puts $chan [tr "" [td "colspan=2" " Only show program$me\s that haven't started"]] } else { puts $chan [tr "" [td "colspan=2" " Only show program$me\s that haven't started"]] } set currenthour 1 } else { if { $starting } { puts $chan [tr "" [td "colspan=2" " Only show program$me\s that start in the hour"]] } else { puts $chan [tr "" [td "colspan=2" " Only show program$me\s that start in the hour"]] } set currenthour 0 } puts $chan [html_table_end] puts $chan [html_form_input "submit" "submit" "Search"] puts $chan [html_form_end] set chkdate [expr $wodatetz / 86400] if { $eenv != ""} { if { $starting && $currenthour } { set minseconds [clock seconds] set maxseconds [expr $wodatetz + ($wotimetz * 3600) - $tzoffset + 3600] } else { set minseconds [expr $wodatetz + ($wotimetz * 3600) - $tzoffset] set maxseconds [expr $minseconds + 3600] } set hr [expr $wotimetz - ($tzoffset / 3600)] if { $hr < 0 } { incr chkdate -1 } elseif { $hr > 23 } { incr chkdate 1 } puts $chan [html_table_start "" "" ""] if { $currenthour } { puts $chan [tr "ALIGN=CENTER" [th ""] [th ""] [th "Start Time"] [th "End Time"] [th ""] [th "Channel"] [th "Series"] [th "Episode"] [th "Description"]] } else { puts $chan [tr "ALIGN=CENTER" [th ""] [th "Start Time"] [th "End Time"] [th ""] [th "Channel"] [th "Series"] [th "Episode"] [th "Description"]] } set reccount 0 foreach channum [lsort -integer [array names channeltablenum]] { set stationfsid $channeltablenum($channum) set data $channeltablestation($stationfsid) set favorite [lindex $data 1] if { $chnsel == "3" && $favorite == 0 } { continue } set callsign [lindex $data 2] if { [expr ($wotimetz - ($tzoffset / 3600) + 24) % 24] < 5 && !$starting } { incr chkdate -1 ForeachMfsFile fsid name type "/Schedule" "$stationfsid:$chkdate" { if {[catch [do_wochandata $chan $fsid $minseconds $maxseconds $channum $callsign $stationfsid $starting $currenthour] error]} { puts "do_wochandata $fsid $minseconds $channum $callsign $stationfsid" puts "$error" } } incr chkdate 1 } ForeachMfsFile fsid name type "/Schedule" "$stationfsid:$chkdate" { if {[catch [do_wochandata $chan $fsid $minseconds $maxseconds $channum $callsign $stationfsid $starting $currenthour] error]} { puts "do_wochandata $fsid $minseconds $channum $callsign $stationfsid" puts "$error" } } } if { $reccount > 0 } { puts $chan "($reccount scheduled recording[ if {$reccount > 1} { format "s" } ] found.)
" } puts -nonewline $chan [html_table_end] } else { puts $chan " " } if { $chkdate > $minday } { puts -nonewline $chan "[html_link "/whatson?chnsel=$chnsel&wodatetz=[expr $wodatetz - 86400]&wotimetz=$wotimetz&starting=$starting&submit=Search" "<< A day earlier"]" } if { $chkdate > $minday || $wotimetz > 0 } { if { $wotimetz == 0 } { set datem1hrtz [expr $wodatetz - 86400] set timem1hrtz 23 } else { set datem1hrtz $wodatetz set timem1hrtz [expr $wotimetz - 1] } puts -nonewline $chan " [html_link "/whatson?chnsel=$chnsel&wodatetz=$datem1hrtz&wotimetz=$timem1hrtz&starting=$starting&submit=Search" "< One hour earlier"]" } puts -nonewline $chan " | " if { $chkdate < $maxday || $wotimetz < 23 } { if { $wotimetz == 23 } { set datep1hrtz [expr $wodatetz + 86400] set timep1hrtz 0 } else { set datep1hrtz $wodatetz set timep1hrtz [expr $wotimetz + 1] } puts -nonewline $chan " [html_link "/whatson?chnsel=$chnsel&wodatetz=$datep1hrtz&wotimetz=$timep1hrtz&starting=$starting&submit=Search" "One hour later >"]" } if { $chkdate < $maxday } { puts -nonewline $chan " [html_link "/whatson?chnsel=$chnsel&wodatetz=[expr $wodatetz + 86400]&wotimetz=$wotimetz&starting=$starting&submit=Search" "A day later >>"]" } puts $chan [html_end] } proc do_wochandata {chan fsid startsecs endsecs channum callsign stationfsid starting currenthour} { global db global tzoffset global usformat global images global tvratingnums tvratingvals global advisorynums advisoryvals global mpaaratingnums mpaaratingvals global reccount RetryTransaction { set stationday [db $db openid $fsid] set showings [dbobj $stationday gettarget Showing] } for {set x 0} {$x < [llength $showings]} {incr x 20} { RetryTransaction { foreach showingfsid [lrange $showings $x [expr $x+19]] { regexp {([0-9]*)/(.*)} $showingfsid junk showingobjid subobjid set showing [db $db openidconstruction $showingobjid $subobjid] set date [dbobj $showing get Date] set prgtime [dbobj $showing get Time] set secs [expr $date * 86400 + $prgtime] if { $secs >= $endsecs } { continue } set finsecs [expr $secs + [dbobj $showing get Duration]] if { $finsecs <= $startsecs } { continue } if { $starting && $secs < $startsecs } { continue } set program [dbobj $showing get Program] set title [strim [dbobj $program get Title]] if { $title == "SIGN OFF" } { continue } if { $usformat } { set timestrtz [clock format [expr $secs + $tzoffset] -format "%l:%M %P"] set timeendtz [clock format [expr $finsecs + $tzoffset] -format "%l:%M %P"] } else { set timestrtz [clock format [expr $secs + $tzoffset] -format "%H:%M"] set timeendtz [clock format [expr $finsecs + $tzoffset] -format "%H:%M"] } set partindex [dbobj $showing get PartIndex] set partcount [dbobj $showing get PartCount] set series [dbobj $program get Series] set seriesfsid "" if { $series != "" } { set seriesfsid [dbobj $series fsid] set episodic [defaultval 1 [dbobj $series get Episodic]] } else { set episodic 1 } set description [strim [dbobj $program get Description]] set eptitle [strim [dbobj $program get EpisodeTitle]] if { $eptitle == "" } { if { $episodic == 1 } { set eptitle "UNKNOWN" } else { set eptitle $title } } if { $partcount != "" && $partindex != "" } { append eptitle " ($partindex/$partcount)" } if { $seriesfsid != "" } { set title [html_link "/series/$seriesfsid" $title] } if { $::description_hover && $description != "" } { set description [htmlEncode $description] regsub -all {\"} $description {\"} description set attrs "title=\"$description\"" } else { set attrs "" } if { $description == "" } { set description " " } set imagenum -1 set today [expr [clock seconds] / 86400] if { $date >= $today } { set recfsid [lindex [get_fsidbyprefix "/Recording/Active" "4:$date:[string range "0000$prgtime" [expr [string length "$prgtime"] - 1] end]:"] 0] } else { set recfsid "" } if { $recfsid == "" && $date <= $today } { if { $prgtime == 0 } { incr date -1 set prgtime 86398 } else { incr prgtime -2 } set prgtime "[string range "0000$prgtime" [expr [string length "$prgtime"] - 1] end]" set recfsid [lindex [get_fsidbyprefix "/Recording/Active" "1:$date:$prgtime:"] 0] } if { $recfsid == "" && $date <= $today } { set recfsid [lindex [get_fsidbyprefix "/Recording/Active" "3:$date:$prgtime:"] 0] } if {$recfsid != ""} { set rec [db $db openid $recfsid] set recshowing [dbobj $rec get Showing] set recstation [dbobj $recshowing get Station] set recstationfsid [dbobj $recstation fsid] if {$recstationfsid == $stationfsid} { set state [dbobj $rec get State] if {$state == 4} { set imagenum 3 } elseif {$state == 5} { set imagenum 20 } elseif {$state == 3} { set imagenum 8 incr reccount 1 } elseif {$state == 6} { if {$::version3} { set recbeh [dbobj $rec get RecordingBehavior] set seltype [dbobj $recbeh get PresentationBehavior] if {$seltype == 6} { set imagenum 10 incr reccount 1 } elseif {$seltype == 2} { set imagenum 11 incr reccount 1 } elseif {$seltype == 3} { set imagenum 13 incr reccount 1 } else { set imagenum 1 incr reccount 1 } } else { set seltype [dbobj $rec get SelectionType] if {$seltype == 6} { set imagenum 10 incr reccount 1 } elseif {$seltype == 9} { set imagenum 11 incr reccount 1 } elseif {$seltype == 13} { set imagenum 13 incr reccount 1 } else { set imagenum 1 incr reccount 1 } } } else { set expdate [dbobj $rec get ExpirationDate] set expsecs [expr $expdate * 86400 + [dbobj $rec get ExpirationTime]] set nowsecs [clock seconds] if {$expdate == 24855} { set imagenum 0 } elseif {$expsecs < $nowsecs} { set imagenum 5 } elseif {$expsecs < [expr $nowsecs + 24*60*60]} { set imagenum 3 } } } } if {$imagenum >= 0} { set imagef [lindex $images $imagenum] if { $imagenum == 20 } { set imageh [html_link "/confirmdelete/3/$recfsid" "[img "align=absmiddle" $imagef]" "title=\"Click to undelete\""] } else { set imageh [img "align=absmiddle" $imagef] } } else { if { $secs > [clock seconds] } { # set imageh "[slotfree $secs [expr $finsecs - $secs] $chan] " set imageh " " } else { set imageh " " } } #Added thumbs set thumbs "" if { $series != "" } { set score [dbobj $series get ThumbData] if { $score != "" } { set imagenumt [get_thumbimage $score] if { $imagenumt >= 0} { set imagef [lindex $images $imagenumt] set thumbs [img "align=absmiddle alt=\"\"" $imagef] } } } if { $currenthour } { if { $secs <= [clock seconds] && $finsecs > [clock seconds] } { set butn [html_form_start "GET" "/whatson" "name=\"watch\""] if { $imagenum == 8 } { append butn [html_form_input "hidden" "channel" ""] } else { append butn [html_form_input "hidden" "channel" $channum] } append butn [html_form_input "submit" "submit" "Watch"] append butn [html_form_end] } else { set butn " " } puts $chan [tr "" [td "align=center valign=middle" $butn] [td "align=center" "$imageh"] [td "align=center" "$timestrtz"] [td "align=center" $timeendtz] [td "$thumbs"] [td [html_link "/channel/$stationfsid" "$channum $callsign"]] [td "$title"] [td [html_link "/showing/$showingfsid" $eptitle $attrs]] [td "$description"]] } else { puts $chan [tr "" [td "align=center" "$imageh"] [td "align=center" "$timestrtz"] [td "align=center" $timeendtz] [td "$thumbs"] [td [html_link "/channel/$stationfsid" "$channum $callsign"]] [td "$title"] [td [html_link "/showing/$showingfsid" $eptitle $attrs]] [td "$description"]] } } } } } ########################################## register_module "whatson" "What\'s On" "Hourly What\'s On listing"