# Now Playing with Sort module for TiVoWeb for non version 3 TiVos. # # Based very heavily on other parts of TiVoWeb! # # LJ @ http://www.tivocommunity.com/ # # 27Dec02 15:23 v1.0 # 27Dec02 18:32 v1.1 Force TiVo Suggestions to 'expire' before user selected programs. # Quicker process for generating sort data. # Add 'Genre' as a sort option. # 04Jan03 18:40 v1.2 Add delete checkboxes back in. proc action_np {chan path env} { global db global nowshowingdir global genrenums set sort 2 set shows "" eval $env if {$::multi_delete} { set nstype 6 } else { set nstype 0 } if {$::uktivo} { puts $chan [html_start "Now Playing with Sort"] } else { puts $chan [html_start "Now Showing with Sort"] } puts $chan "Sort by: " puts $chan "[html_link "/np/?sort=0" [expr {$sort == 0 ? "Classic" : "Classic"}]] " puts $chan "[html_link "/np/?sort=1" [expr {$sort == 1 ? "Expiry Date" : "Expiry Date"}]] " puts $chan "[html_link "/np/?sort=2" [expr {$sort == 2 ? "Title" : "Title"}]] " puts $chan "[html_link "/np/?sort=3" [expr {$sort == 3 ? "Title + Episode Title" : "Title + Episode Title"}]] " puts $chan "[html_link "/np/?sort=4" [expr {$sort == 4 ? "Duration" : "Duration"}]] " puts $chan "[html_link "/np/?sort=5" [expr {$sort == 5 ? "Genre" : "Genre"}]] " puts $chan "

" set delete_th "" if {$nstype == 6} { puts $chan " " puts $chan [html_form_start "POST" "/confirmdelete/6/" "name=\"form\""] set delete_th [th ""] } puts $chan [html_table_start "" "" ""] #LJ added mins #LJ if {$::uktivo} { puts $chan [tr "ALIGN=CENTER" [th ""] [th "Programme"] [th "Episode"] [th "Mins"] [th "COLSPAN=2" "Date"] $delete_th] } else { puts $chan [tr "ALIGN=CENTER" [th ""] [th "Program"] [th "Episode"] [th "Mins"] [th "COLSPAN=2" "Date"] $delete_th] } set rcount 0 ForeachMfsFileTrans fsid name type $nowshowingdir "" 15 { set rec [db $db openid $fsid] # 5: Genre 4: Duration 3: Title+EpTitle 2: Title, 1: Expiration, 0: Classic switch -exact -- $sort { 5 { set showing [dbobj $rec get Showing] set program [dbobj $showing get Program] set title [strim [dbobj $program get Title]] set sortkey "" set genr [dbobj $program get Genre] if {$genr != ""} { for {set i 0} {$i < [llength $genrenums]} {incr i 1} { if {[lsearch -exact $genr [lindex $genrenums $i]] > -1} { append sortkey "y" } else { append sortkey "n" } } } else { set sortkey "z" } set sortkey "$sortkey $title" lappend shows [list $nstype $fsid $sortkey] } 4 { set showing [dbobj $rec get Showing] set sortkey [dbobj $showing get Duration] lappend shows [list $nstype $fsid $sortkey] } 3 { set showing [dbobj $rec get Showing] set program [dbobj $showing get Program] set title [strim [dbobj $program get Title]] set sortkey "$title [strim [dbobj $program get EpisodeTitle]]" lappend shows [list $nstype $fsid $sortkey] } 2 { set showing [dbobj $rec get Showing] set program [dbobj $showing get Program] set sortkey [strim [dbobj $program get Title]] lappend shows [list $nstype $fsid $sortkey] } 1 { set showing [dbobj $rec get Showing] set expdate [dbobj $rec get ExpirationDate] set expsecs [expr $expdate * 86400 + [dbobj $rec get ExpirationTime]] set sortkey [expr {[string index $name 0] == "A" ? "B[expr abs($expsecs)]" : "A[expr abs($expsecs)]" }] lappend shows [list $nstype $fsid $sortkey] } 0 { if {$nstype == 6} { print_nowplayingrow $chan $rec $nstype $rcount incr rcount } else { print_nowplayingrow $chan $rec $nstype } } } } if { $sort > 0 } { # 5: Genre 4: Duration 3: Title+EpTitle 2: Title, 1: Expiration, 0: Classic switch -exact -- $sort { 5 { set shows [lsort -dictionary -index 2 $shows] } 4 { set shows [lsort -integer -index 2 $shows] } 3 { set shows [lsort -ascii -index 2 $shows] } 2 { set shows [lsort -ascii -index 2 $shows] } 1 { set shows [lsort -dictionary -index 2 $shows] } } set rcount 0 foreach show $shows { if {$nstype == 6} { RetryTransaction { set rec2 [db $db openid [lindex $show 1]] print_nowplayingrow $chan $rec2 [lindex $show 0] $rcount incr rcount } } else { RetryTransaction { set rec2 [db $db openid [lindex $show 1]] print_nowplayingrow $chan $rec2 [lindex $show 0] } } } } puts -nonewline $chan [html_table_end] if {$nstype == 6} { #LJ if {$::uktivo} { puts $chan [html_form_input "submit" "submit" "Delete Programmes"] } else { puts $chan [html_form_input "submit" "submit" "Delete Shows"] } puts $chan [html_form_end] } puts $chan [html_end] } # Copied across print_nowshowingrow as I have mods to show program duration. proc print_nowplayingrow {chan rec type args} { global db global tzoffset global images global cache_ns_rec global cache_ns_series if {[llength $args] > 0} { set rcount [lindex $args 0] } set showing [dbobj $rec get Showing] set showingfsid [dbobj $rec gettarget Showing] set station [dbobj $showing get Station] set program [dbobj $showing get Program] set title [strim [dbobj $program get Title]] set description [strim [dbobj $program get Description]] set manual 0 set suggestion 0 set vod 0 set watchonly 0 if {$::version3} { set recbeh [dbobj $rec get RecordingBehavior] set presbeh [dbobj $recbeh get PresentationBehavior] set progbeh [dbobj $recbeh get ProgramGuideBehavior] set diskbeh [dbobj $recbeh get DiskBehavior] if { $presbeh == 10 || $presbeh == 9 } { set manual 1 } if { $progbeh == 3 || $progbeh == 8 } { set manual 1 } if { $presbeh == 6 } { set suggestion 1 } if { $diskbeh == 7 } { # for multipart set watchonly 1 } } else { set seltype [dbobj $rec get SelectionType] if { $seltype == 10 || $seltype == 5 } { set manual 1 } if { $seltype == 6 } { set createby [dbobj $rec get CreatedBy] if { $createby == 2 } { set vod 1 } else { set suggestion 1 } } } if { $manual } { if { $title == "" } { set title "Manual Recording" } else { set title "Manual: $title" } } set state [dbobj $rec get State] set fsid [dbobj $rec fsid] set index [lsearch $cache_ns_rec $fsid] set seriesfsid "" set series [dbobj $program get Series] if { $index == -1 } { if {$series != ""} { set seriesfsid [dbobj $series fsid] lappend cache_ns_rec $fsid lappend cache_ns_series $seriesfsid } } else { set seriesfsid [lindex $cache_ns_series $index] } # VGhpcyBkb2Vzbid0IGRvIGFueXRoaW5nG1szMDszODttG1s4XQo= #set isepisode [dbobj $program get IsEpisode] if {$series != ""} { set episodic [defaultval 1 [dbobj $series get Episodic]] } else { set episodic 1 } if { $episodic == 1 } { set eptitle [strim [dbobj $program get EpisodeTitle]] if { $eptitle == "" } { set eptitle "No Episode Title" } } else { set eptitle "Not an Episode" } if { $::description_hover && $description != "" } { set description [htmlEncode $description] regsub -all {\"} $description {\"} description set attrs "title=\"$description\"" } else { set attrs "" } set seconds [expr [dbobj $showing get Date] * 86400 + [dbobj $showing get Time] + $tzoffset] if {$::uktivo} { set date "" set daystr [nth [clock format $seconds -format "%e"]] set day [clock format $seconds -format "%a $daystr %b"] } else { set day [clock format $seconds -format "%a"] set date [clock format $seconds -format "%1m/%1d"] } #LJ start addition set bookmark [dbobj $rec get Bookmark] if { $bookmark != "" } { set durn "[expr [dbobj $showing get Duration] / 60] ([expr [expr [dbobj $bookmark get TimeMs] / 1000] / (60)])" } else { set durn [expr [dbobj $showing get Duration] / 60] } #LJ end addition set expdate [dbobj $rec get ExpirationDate] set expsecs [expr $expdate * 86400 + [dbobj $rec get ExpirationTime]] set nowsecs [clock seconds] if {$state == 5} { set imagenum 20 } elseif {$state == 3} { set imagenum 8 } elseif {$suggestion} { set imagenum 10 } elseif {$vod} { set imagenum 21 } elseif {$expdate == 24855} { set imagenum 0 } elseif {$expsecs < $nowsecs} { set imagenum 5 } elseif {$expsecs < [expr $nowsecs + 24*60*60]} { set imagenum 3 } else { set imagenum -1 } if { $imagenum >= 0} { set imagef [lindex $images $imagenum] set imageh [img "alt=\"\"" $imagef] if { $imagenum == 20 } { ;# recycled set imageh [html_link "/confirmdelete/3/$fsid" [img "alt=\"undelete\"" $imagef]] } } else { set imageh "" } set delete_td "" if {$type == 6} { set delete_td [td "ALIGN=CENTER" [html_form_checkbox "fsid_${rcount}_$fsid" ""]] } if {$manual || $watchonly} { #LJ added durn to next two puts lines. puts $chan [tr "" [td $imageh] [td [html_link "/showing/$showingfsid" $title]] [td [html_link "/showing/$showingfsid" $eptitle $attrs]] [td $durn] [td $day] [td $date] $delete_td] } else { puts $chan [tr "" [td $imageh] [td [html_link "/series/$seriesfsid" $title]] [td [html_link "/showing/$showingfsid" $eptitle $attrs]] [td $durn] [td $day] [td $date] $delete_td] } } if {!$::version3} { if {$::uktivo} { register_module "np\" title=\" ...module written by LJ - www.ljay.org.uk " "Now Playing" "Now Playing with Sort" } else { register_module "np\" title=\" ...module written by LJ - www.ljay.org.uk " "Now Showing" "Now Showing with Sort" } }