# Advisory Code search module for TiVoWeb. # Based very heavily on other parts of TiVoWeb! # # LJ @ http://www.tivocommunity.com/ # # 01Dec02 15:56 v1.2 # 15Dec02 15:11 v1.3 Add description hover. proc action_advsearch {chan type env} { global channeltablestation channeltablenum global logotablename logotableindex global db global guideindexdir global nothingfound global advcode global advtext global acsrchtype set advcode "2" set type "3" set acsrchtype "1" eval $env puts $chan [html_start "Advisory Code Search"] set advvals "1 2 10 4 3 8 7 6 5" set advlabels "{AL - Language} {GL - Graphic Language} {AC - Adult Content} {BN - Brief Nudity} {N - Nudity} {SC - Strong Sexual Content} {MV - Mild Violence} {V - Violence} {GV - Graphic Violence}" set chnvals "3 2" set chnlabels "{Favourite Channels} {Channels Watched}" set typvals "0 1 2" set typlabels "{Individual Channel by Date} {Individual Channel} {All Channels}" puts $chan [html_form_start "GET" "/advsearch" "name=\"search\""] puts $chan [html_table_start "" "Search" "COLSPAN=2"] puts $chan [tr "" [td "Advisory Code:"] [td "" [html_form_select "advcode" $advvals $advlabels $advcode]]] puts $chan [tr "" [td "Channels:"] [td "" [html_form_select "type" $chnvals $chnlabels $type]]] puts $chan [tr "" [td "Search Type:"] [td "" [html_form_select "acsrchtype" $typvals $typlabels $acsrchtype]]] puts $chan [html_table_end] puts $chan [html_form_input "submit" "submit" "Search"] puts $chan [html_form_end] if { $env != ""} { set advtext [lindex $advlabels [lsearch $advvals $advcode]] if { $acsrchtype < "2" } { puts $chan [html_table_start "" "" ""] puts $chan [tr "ALIGN=CENTER" [th "Logo"] [th "Num"] [th "Callsign"] [th "Name"]] } else { puts $chan [h2 "Programmes with Advisory Code: $advtext"] puts $chan [html_table_start "" "" ""] } if { $type == "1" } { if { $acsrchtype == "2" } { # search entire channel puts $chan [tr "ALIGN=CENTER" [th "Num"] [th "Callsign"] [th "Date"] [th "Time"] [th "Series"] [th "Episode"]] } RetryTransaction { set channelfsid [lindex [mfs find $guideindexdir/ChannelTable] 0] set channeltabledata [mfs get $channelfsid] } binary scan [string range $channeltabledata 0 3] I numkeys set incrsize 50 set varname [lindex $::datagroup [lsearch $::datagroup "SF_Serial*"]] set varname [string range $varname 9 11] for {set i 0} {$i < $numkeys} {incr i $incrsize} { set maxchannelcount [expr ($numkeys > $i + $incrsize) ? ($i + $incrsize) : $numkeys] RetryTransaction { for {set count $i} {$count < $maxchannelcount} {incr count} { binary scan [string range $channeltabledata [expr $count*8 + 4] [expr $count*8 + 11]] ISS stationfsid dummy chnum set station [db $db openid $stationfsid] set callsign [dbobj $station get CallSign] set channame [strim [dbobj $station get Name]] set logoindex [dbobj $station get ${varname}oIndex] set logoname [lindex $logotablename(1) [lsearch $logotableindex(1) $logoindex]] if { $logoname != "" } { set logostr [img "alt=\"\"" "$logoname-s1-p1.png"] } else { set logostr "" } if { $acsrchtype < "2" } { puts $chan [tr "" [td $logostr] [td $chnum] [td [html_link "/advlistings/$stationfsid" $callsign]] [td $channame]] } else { # search entire channel action_advlistings $chan "/$stationfsid" $env } } } } unset channeltabledata } else { if { $acsrchtype == "2" } { # search entire channel puts $chan [tr "ALIGN=CENTER" [th "Num"] [th "Callsign"] [th "Date"] [th "Time"] [th "Series"] [th "Episode"]] } foreach channum [lsort -integer [array names channeltablenum]] { set stationfsid $channeltablenum($channum) set data $channeltablestation($stationfsid) set favorite [lindex $data 1] if { $type == "3" && $favorite == 0 } { continue } set callsign [lindex $data 2] set channame [lindex $data 3] set logoindex [lindex $data 4] set logoname [lindex $logotablename(1) [lsearch $logotableindex(1) $logoindex]] if { $logoname != "" } { set logostr [img "alt=\"\"" "$logoname-s1-p1.png"] } else { set logostr "" } set channame [strim $channame] if { $acsrchtype < "2" } { puts $chan [tr "" [td $logostr] [td $channum] [td [html_link "/advlistings/$stationfsid" $callsign]] [td $channame]] } else { # search entire channel action_advlistings $chan "/$stationfsid" $env } } } puts -nonewline $chan [html_table_end] } puts $chan [html_end] } proc action_advlistings {chan path env} { global db global tzoffset global channeltablestation global channeltablenum global logotablename global logotableindex global nothingfound global acsrchtype global advtext if { $acsrchtype < "2" } { puts $chan [html_start "Matching Listings"] } if {[string index $path 0] == "/"} { set path [string range $path 1 end] } set firstslash [string first "/" $path] set seconds "" if { $firstslash != -1 } { set stationid [string range $path 0 [expr $firstslash - 1]] set seconds [string range $path [expr $firstslash + 1] end] } else { set stationid $path } if { [catch {set data $channeltablestation($stationid)}] != 1 } { set channum [lindex $data 0] set callsign [lindex $data 2] set logoindex [lindex $data 4] set logoname [lindex $logotablename(1) [lsearch $logotableindex(1) $logoindex]] } else { puts $chan "Error: Unknown Station '$stationid'" puts $chan [html_end] return 0 } if { $logoname != "" } { set logostr [img "alt=\"\"" "$logoname-s1-p1.png"] } else { set logostr "" } if { $acsrchtype == "2" } { set nothingfound 1 set minday "99999" set maxday "00000" ForeachMfsFile fsid name type "/Schedule" "$stationid:" { scan $name "%d:%d:" schedsid schedday if {$minday > $schedday} { set minday $schedday } if {$maxday < $schedday} { set maxday $schedday } } set minseconds [expr ($minday - 1) * 86400] set maxseconds [expr $maxday * 86400] ForeachMfsFile fsid name type "/Schedule" "$stationid:" { if {[catch [do_advlistingsrow $chan $fsid $minseconds $maxseconds $channum $callsign] error]} { puts "do_advlistingrow $fsid $miseconds $maxseconds" puts "$error" } } } elseif { $acsrchtype == "1" } { set nothingfound 1 puts $chan [h1 "$logostr $channum $callsign"] puts $chan [h2 "Programmes with Advisory Code: $advtext"] puts $chan [html_table_start "" "" ""] puts $chan [tr "ALIGN=CENTER" [th "Date"] [th "Time"] [th "Series"] [th "Episode"]] set minday "99999" set maxday "00000" ForeachMfsFile fsid name type "/Schedule" "$stationid:" { scan $name "%d:%d:" schedsid schedday if {$minday > $schedday} { set minday $schedday } if {$maxday < $schedday} { set maxday $schedday } } set minseconds [expr ($minday - 1) * 86400] set maxseconds [expr $maxday * 86400] ForeachMfsFile fsid name type "/Schedule" "$stationid:" { if {[catch [do_advlistingsrow $chan $fsid $minseconds $maxseconds 0 0] error]} { puts "do_advlistingrow $fsid $miseconds $maxseconds" puts "$error" } } puts -nonewline $chan [html_table_end] } elseif { $seconds == "" } { puts $chan [h1 "$logostr $channum $callsign"] set minday "99999" set maxday "00000" ForeachMfsFile fsid name type "/Schedule" "$stationid:" { scan $name "%d:%d:" schedsid schedday if {$minday > $schedday} { set minday $schedday } if {$maxday < $schedday} { set maxday $schedday } } set minseconds [expr ($minday - 1) * 86400] set maxseconds [expr $maxday * 86400] puts $chan [html_table_start "" "" ""] puts $chan [tr "" [th "Day"]] for {set i $minseconds} {$i <= $maxseconds} {incr i 86400} { # set timestr [clock format $i -format "%a %1m/%1d"] 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"] puts $chan [tr "" [td [html_link "/advlistings/$stationid/$i" $timestr]]] } puts -nonewline $chan [html_table_end] puts $chan "

" } else { set nothingfound 1 set day [expr $seconds / 86400] set startsecs [expr $seconds] set endsecs [expr $startsecs + 86400] # set timestr [clock format $startsecs -format "%a %1m/%1d"] set timestr [clock format $startsecs -format "%a %e[switch -glob [clock format $startsecs -format "%e"] {1? {format th} *1 {format st} *2 {format nd} *3 {format rd} default {format th} }] %b"] puts $chan [h1 "$logostr $channum $callsign - $timestr"] set firstday 0 set lastday 0 set yesterday [expr $seconds - 86400] set tommorow [expr $seconds + 86400] # set timestr [clock format $yesterday -format "%a %1m/%1d"] set timestr [clock format $yesterday -format "%a %e[switch -glob [clock format $yesterday -format "%e"] {1? {format th} *1 {format st} *2 {format nd} *3 {format rd} default {format th} }] %b"] # set timestr2 [clock format $tommorow -format "%a %1m/%1d"] set timestr2 [clock format $tommorow -format "%a %e[switch -glob [clock format $tommorow -format "%e"] {1? {format th} *1 {format st} *2 {format nd} *3 {format rd} default {format th} }] %b"] puts $chan [h2 "Programmes with Advisory Code: $advtext"] if { !$firstday } { puts $chan [html_link "/advlistings/$stationid/$yesterday" "<< $timestr"] } if { !$lastday } { puts $chan [html_link "/advlistings/$stationid/$tommorow" "$timestr2 >>"] } puts $chan "

" puts $chan [html_table_start "" "" ""] puts $chan [tr "ALIGN=CENTER" [th "Time"] [th "Series"] [th "Episode"]] set firstday 1 ForeachMfsFile fsid name type "/Schedule" "$stationid:$day:" { if {[catch [do_advlistingsrow $chan $fsid $startsecs $endsecs 0 0] error]} { puts "do_advlistingrow $fsid $startsecs $endsecs" puts "$error" } } incr day set lastday 1 ForeachMfsFile fsid name type "/Schedule" "$stationid:$day:" { if {[catch [do_advlistingsrow $chan $fsid $startsecs $endsecs 0 0] error]} { puts "do_advlistingrow $fsid $startsecs $endsecs" puts "$error" } } puts -nonewline $chan [html_table_end] } if { $nothingfound && $acsrchtype < "2" } { puts $chan "No matching programmes found" } if { $acsrchtype < "2" } { puts $chan [html_end] } } proc do_advlistingsrow {chan fsid startsecs endsecs channum callsign} { global db global tzoffset global advisorynums advisoryvals global nothingfound global acsrchtype global advcode 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 secs [expr [dbobj $showing get Date] * 86400 + [dbobj $showing get Time] + $tzoffset] if { $secs >= $startsecs && $secs < $endsecs } { set program [dbobj $showing get Program] if { $::dtivo } { # Blurp puts $chan "Detected a DTiVo - sorry not supported :(
" } else { set advisorys [dbobj $program get Advisory] if { $advisorys != "" } { if { [lsearch $advisorys $advcode] > 0 } { set nothingfound 0 # set timestr [clock format $secs -format "%l:%M %P"] set timestr [clock format $secs -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 title [strim [dbobj $program get Title]] 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] } set description [strim [dbobj $program get Description]] if { $::description_hover && $description != "" } { set description [htmlEncode $description] regsub -all {\"} $description {\"} description set attrs "title=\"$description\"" } else { set attrs "" } if { $acsrchtype == "2" } { # set datestr [clock format $secs -format "%a %1m/%1d"] set datestr [clock format $secs -format "%a %e[switch -glob [clock format $secs -format "%e"] {1? {format th} *1 {format st} *2 {format nd} *3 {format rd} default {format th} }] %b"] puts $chan [tr "" [td $channum] [td $callsign] [td $datestr] [td $timestr] [td $title] [td [html_link "/showing/$showingfsid" $eptitle $attrs]]] } elseif { $acsrchtype == "1" } { # set datestr [clock format $secs -format "%a %1m/%1d"] set datestr [clock format $secs -format "%a %e[switch -glob [clock format $secs -format "%e"] {1? {format th} *1 {format st} *2 {format nd} *3 {format rd} default {format th} }] %b"] puts $chan [tr "" [td $datestr] [td $timestr] [td $title] [td [html_link "/showing/$showingfsid" $eptitle $attrs]]] } else { puts $chan [tr "" [td $timestr] [td $title] [td [html_link "/showing/$showingfsid" $eptitle $attrs]]] } } } } } } } } } ########################################## register_module "advsearch\" title=\" ...module written by LJ - www.ljay.org.uk " "Search ACs" "Search by advisory codes"