From b99327a5625dfc99199943df24eb77052fb15b59 Mon Sep 17 00:00:00 2001 From: MymsMan Date: Sun, 10 May 2020 20:12:52 +0100 Subject: [PATCH 1/4] Updates to rsv.class and epg.class to support schedchk package --- webif/lib/epg.class | 41 ++++++++++++++----- webif/lib/rsv.class | 98 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 127 insertions(+), 12 deletions(-) mode change 100755 => 100644 webif/lib/rsv.class diff --git a/webif/lib/epg.class b/webif/lib/epg.class index 3dac46a..a52b56b 100644 --- a/webif/lib/epg.class +++ b/webif/lib/epg.class @@ -185,33 +185,35 @@ epg method get_rsv {} { } } -epg method process_sched {} { - $self scheduled +epg method process_sched {{debug 0}} { + $self scheduled $debug } set rsvlookup "" -epg method scheduled {} { +epg method scheduled {{debug 0}} { global rsvlookup if {$sched_type >= 0} { return $sched_type } set sched_type 0 if {$rsvlookup eq ""} { + set st [clock milliseconds] set rsvlookup [rsv lookuptab] - #puts $rsvlookup + if {$debug} {puts "mS $([clock milliseconds]-$st) --- $rsvlookup} } set p 0 foreach key [list \ "$service_id:$event_id" \ + "$channel_hsvc:$event_id" \ [string tolower "$service_id:$channel_crid$series_crid"] \ [string tolower "$service_id:$channel_crid$event_crid"] \ ] { - #puts "Check key ($key)" + if {$debug} {puts "Check key ($key)"} if {[dict exists $rsvlookup $key]} { set p $rsvlookup($key) - #puts "FOUND ($p)" + if {$debug} {puts "FOUND ($p)"} break } } @@ -219,14 +221,35 @@ epg method scheduled {} { switch $p { S { set sched_type 2 } E { set sched_type 1 } + R { set sched_type 3 } + X { set sched_type 4 } default { set sched_type 0 } } - #puts "SCHED_TYPE: ($sched_type)" + if {$debug} {puts "SCHED_TYPE: ($sched_type)"} return $sched_type } + +proc {epg update_lookup_tab} {svcid evtid {add true} {type "S"} } { + global rsvlookup + # Update the reservations look up table (if present) with single entry + if {$rsvlookup==""} {return} + set key $svcid:$evtid + if {$add} { + # add new entry + dict set rsvlookup $key $type + } else { + # remove existing entry + if {[dict exists $rsvlookup $key]} { + dict unset rsvlookup $key + } + } + #puts "$svcid:$evtid $add $type == $rsvlookup " +} + + epg method icon_set {{height 0}} { if {$height > 0} { set height "height=$height" } else { set height "" } set icon [$self type_icon] @@ -431,9 +454,9 @@ proc {epg dbfetch} {mode args} { " } -crid { append q \ - "and e.event_crid = '$v' " } + "and e.event_crid = '$v' collate nocase " } -scrid { append q \ - "and e.series_crid = '$v' " } + "and e.series_crid = '$v' collate nocase " } -type { append q \ "and e.content_code = $v " } -service { append q \ diff --git a/webif/lib/rsv.class b/webif/lib/rsv.class old mode 100755 new mode 100644 index 7614f64..6ab2220 --- a/webif/lib/rsv.class +++ b/webif/lib/rsv.class @@ -308,6 +308,11 @@ rsv method iconset {{height 20}} { return $iconlist } +# source /df +rsv method set {ivName val} { + set $ivName $val +} + rsv method setorigstart {o} { set _origstart $o } @@ -336,6 +341,80 @@ rsv method set_refresh {} { set aulEventToRecordInfo "" } +rsv method update_aul {new_event old_aul} { + # Add new_event (optional) to the aulEventToRecordInfo and szEventToRecord + # remove old_aul (optional) from " " + # Maintain list in time order + set curauls [$self aul] + set ecrids [split $szEventToRecord "|"] + set evtaul {} + set insert 1 + set start 0 + # Do we have new event to add? + if {$new_event != 0 && $new_event !={}} { + set service_id [$new_event get channel_hsvc] + set start [$new_event get start] + set end [$new_event end] + set evtid [$new_event get event_id] + set evtaul [list $service_id $start $end $evtid] + set evtcrid [string toupper "1[$new_event get channel_crid][$new_event get event_crid]"] + set insert 0 + } + # rebuild aul and events list with new event in correct order + lmap aul $curauls ecrid $ecrids { + #puts "$aul $ecrid" + if {$aul == $old_aul} {continue; #remove current entry} + if {$aul == ""} {continue; #null entry} + if {!$insert && $start <= [lindex $aul 1]} { + set insert 1 + lappend newaul $evtaul + append newevnts "$evtcrid|" + } + lappend newaul $aul + append newevnts "$ecrid|" + } + # add to end if not inserted + if {!$insert} { + set insert 1 + lappend newaul $evtaul + append newevnts "$evtcrid|" + } + set action 5 + $self setaul [$self buildaul $newaul] + set szEventToRecord $newevnts + } + +rsv method set_next_event {} { + # Update reservation next event info in ucVolume + if {[string length $aulEventToRecordInfo] >0} { + binary scan [string range $aulEventToRecordInfo 0 15]\ + iiii service_id start end event_id + set dur $($end-$start) + if {$hsvc != $service_id || + $nsttime != $start || + $nduration != $dur || + $usevtid != $event_id} { + set nduration $dur + set ucVolume "$service_id:$event_id:$start" + } + } else { + # The next event is not yet in the EPG + set time $([clock seconds] - 86400) + set ucVolume "$hsvc:$usLastRecordedEvtId:$time" + } +} + +rsv method reset_next_event {} { + # Ensure our copy matches the updated reservation + if {$ucVolume!=0} { + lassign [split $ucVolume ":"] service_id event_id start + set hsvc $service_id + set nsttime $start + set usevtid $event_id + set ucVolume 0 + } +} + rsv method set_skip {event} { set action 5 @@ -665,7 +744,7 @@ proc {rsv lookuptab} {} { foreach tab {tbl_reservation pending} { set res [[rsv dbhandle] query " select usSvcId, usevtid, ucCRIDType, szCRID, - ucRecKind + ucRecKind, aulEventToRecordInfo from $tab left join channel.TBL_SVC on $tab.hSvc = channel.TBL_SVC.hSvc where ersvtype <= 3 @@ -687,8 +766,21 @@ proc {rsv lookuptab} {} { } else { continue } - set records([\ - string tolower "$rec(usSvcId):$rec(szCRID)"]) $p + set aul $rec(aulEventToRecordInfo) + + if {[string length $aul]} { + for {set i 0} {$i < [string length $aul]} {incr i 16} { + binary scan [string range $aul $i $($i + 15)]\ + iiii service start end event_id + set records([\ + string tolower "$service:$event_id"]) $p + } + + } else { + + set records([\ + string tolower "$rec(usSvcId):$rec(szCRID)"]) $p + } } } From e3da17ca6c3817ada4e25887c6918ecb1022d34f Mon Sep 17 00:00:00 2001 From: MymsMan Date: Thu, 14 May 2020 15:59:40 +0100 Subject: [PATCH 2/4] use s-crid:e-crid as key for recorded programmes --- webif/lib/epg.class | 5 ++--- webif/lib/rsv.class | 49 ++++++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/webif/lib/epg.class b/webif/lib/epg.class index a52b56b..72156cc 100644 --- a/webif/lib/epg.class +++ b/webif/lib/epg.class @@ -206,9 +206,9 @@ epg method scheduled {{debug 0}} { set p 0 foreach key [list \ "$service_id:$event_id" \ - "$channel_hsvc:$event_id" \ + "$channel_hsvc:$event_id" \ [string tolower "$service_id:$channel_crid$series_crid"] \ - [string tolower "$service_id:$channel_crid$event_crid"] \ + [string tolower "$channel_crid$series_crid:$channel_crid$event_crid"] \ ] { if {$debug} {puts "Check key ($key)"} if {[dict exists $rsvlookup $key]} { @@ -567,4 +567,3 @@ proc {epg channellist} {{field usLcn}} { return $channels } - diff --git a/webif/lib/rsv.class b/webif/lib/rsv.class index 6ab2220..e38ec45 100644 --- a/webif/lib/rsv.class +++ b/webif/lib/rsv.class @@ -208,7 +208,7 @@ rsv method channel_name {} { rsv method szsttime_stamp {} { set spaced [regsub {^(....)(..)(..)(..)(..)(..).*} \ $szsttime {\1 \2 \3 \4 \5 \6}] - + if {[catch { set stamp [clock scan $spaced -format "%Y %m %d %H %M %S"] }]} { @@ -744,7 +744,8 @@ proc {rsv lookuptab} {} { foreach tab {tbl_reservation pending} { set res [[rsv dbhandle] query " select usSvcId, usevtid, ucCRIDType, szCRID, - ucRecKind, aulEventToRecordInfo + ucRecKind, aulEventToRecordInfo, + szRecordedProgCrid from $tab left join channel.TBL_SVC on $tab.hSvc = channel.TBL_SVC.hSvc where ersvtype <= 3 @@ -766,23 +767,36 @@ proc {rsv lookuptab} {} { } else { continue } - set aul $rec(aulEventToRecordInfo) - - if {[string length $aul]} { - for {set i 0} {$i < [string length $aul]} {incr i 16} { - binary scan [string range $aul $i $($i + 15)]\ - iiii service start end event_id - set records([\ - string tolower "$service:$event_id"]) $p - } - } else { + foreach r [split $rec(szRecordedProgCrid) "|"] { + if {$r != {}} { + set records([string tolower "\ + $rec(szCRID):\ + [string range $r 1 end]"]) "R" + } + } - set records([\ - string tolower "$rec(usSvcId):$rec(szCRID)"]) $p - } + set aul $rec(aulEventToRecordInfo) + + if {[string length $aul]} { + for {set i 0} {$i < [string length $aul]} {incr i 16} { + binary scan [string range $aul $i $($i + 15)]\ + iiii service start end event_id + set records([\ + string tolower "$service:$event_id"]) $p + } + + } else { + set records([\ + string tolower "$rec(usSvcId):$rec(szCRID)"]) $p + } } } + # Add all skipped epsisodes for all series + set skiplist [rsv _skiplist] + foreach skip $skiplist { + set records($skip) "X" + } return $records } @@ -1440,7 +1454,7 @@ proc {rsv allevents} {{xota 0}} { incr start 86400 incr end 86400 - + # Sun == 0 set day [clock format $start -format "%w"] @@ -1469,7 +1483,7 @@ proc {rsv allevents} {{xota 0}} { {*}$trailer] } } - + } return $xevents @@ -1700,4 +1714,3 @@ proc {rsv reassert_skips} {{debug false}} { rsv commit } } - From cd9e9924f6212e50a9d6b9dbce00ccbdcf6f3220 Mon Sep 17 00:00:00 2001 From: MymsMan Date: Mon, 18 May 2020 22:46:37 +0100 Subject: [PATCH 3/4] add issplit method to rsv.class --- webif/lib/rsv.class | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webif/lib/rsv.class b/webif/lib/rsv.class index e38ec45..2066720 100644 --- a/webif/lib/rsv.class +++ b/webif/lib/rsv.class @@ -158,6 +158,10 @@ rsv method isseries {} { if {$ucRecKind == 4} { return 1 } else { return 0 } } +rsv method issplit {} { + if {$ucRecKind == 2} { return 1 } else { return 0 } +} + rsv method _strip {str} { return [system strip $str] } From 022e6459fc67e16d048ca3ab12d72037a3545f2a Mon Sep 17 00:00:00 2001 From: HummyPkg Date: Wed, 3 Jun 2020 11:19:29 +0100 Subject: [PATCH 4/4] Adjust whitespace and indentation to match project --- webif/lib/epg.class | 48 ++++++----- webif/lib/rsv.class | 203 +++++++++++++++++++++++--------------------- 2 files changed, 129 insertions(+), 122 deletions(-) diff --git a/webif/lib/epg.class b/webif/lib/epg.class index 72156cc..5c9420f 100644 --- a/webif/lib/epg.class +++ b/webif/lib/epg.class @@ -186,7 +186,7 @@ epg method get_rsv {} { } epg method process_sched {{debug 0}} { - $self scheduled $debug + $self scheduled $debug } set rsvlookup "" @@ -198,19 +198,21 @@ epg method scheduled {{debug 0}} { set sched_type 0 if {$rsvlookup eq ""} { - set st [clock milliseconds] + set st [clock milliseconds] set rsvlookup [rsv lookuptab] - if {$debug} {puts "mS $([clock milliseconds]-$st) --- $rsvlookup} + if {$debug} { + puts "mS $([clock milliseconds] - $st) --- $rsvlookup" + } } set p 0 foreach key [list \ "$service_id:$event_id" \ - "$channel_hsvc:$event_id" \ + "$channel_hsvc:$event_id" \ [string tolower "$service_id:$channel_crid$series_crid"] \ [string tolower "$channel_crid$series_crid:$channel_crid$event_crid"] \ ] { - if {$debug} {puts "Check key ($key)"} + if {$debug} { puts "Check key ($key)" } if {[dict exists $rsvlookup $key]} { set p $rsvlookup($key) if {$debug} {puts "FOUND ($p)"} @@ -226,30 +228,29 @@ epg method scheduled {{debug 0}} { default { set sched_type 0 } } - if {$debug} {puts "SCHED_TYPE: ($sched_type)"} + if {$debug} { puts "SCHED_TYPE: ($sched_type)" } return $sched_type } -proc {epg update_lookup_tab} {svcid evtid {add true} {type "S"} } { - global rsvlookup - # Update the reservations look up table (if present) with single entry - if {$rsvlookup==""} {return} - set key $svcid:$evtid - if {$add} { - # add new entry - dict set rsvlookup $key $type - } else { - # remove existing entry - if {[dict exists $rsvlookup $key]} { - dict unset rsvlookup $key - } - } - #puts "$svcid:$evtid $add $type == $rsvlookup " +proc {epg update_lookup_tab} {svcid evtid {add true} {type "S"}} { + global rsvlookup + # Update the reservations look up table (if present) with single entry + if {$rsvlookup == ""} return + set key $svcid:$evtid + if {$add} { + # add new entry + dict set rsvlookup $key $type + } else { + # remove existing entry + if {[dict exists $rsvlookup $key]} { + dict unset rsvlookup $key + } + } + #puts "$svcid:$evtid $add $type == $rsvlookup" } - epg method icon_set {{height 0}} { if {$height > 0} { set height "height=$height" } else { set height "" } set icon [$self type_icon] @@ -502,7 +503,7 @@ proc {epg dbfetch} {mode args} { lappend params "%$v%" } append q ") " - } + } -param { lappend params $v } -nocase { append q "collate nocase " } default { error "Invalid option, $arg" } @@ -567,3 +568,4 @@ proc {epg channellist} {{field usLcn}} { return $channels } + diff --git a/webif/lib/rsv.class b/webif/lib/rsv.class index 2066720..f9d95a0 100644 --- a/webif/lib/rsv.class +++ b/webif/lib/rsv.class @@ -312,9 +312,8 @@ rsv method iconset {{height 20}} { return $iconlist } -# source /df rsv method set {ivName val} { - set $ivName $val + set $ivName $val } rsv method setorigstart {o} { @@ -346,77 +345,78 @@ rsv method set_refresh {} { } rsv method update_aul {new_event old_aul} { - # Add new_event (optional) to the aulEventToRecordInfo and szEventToRecord - # remove old_aul (optional) from " " - # Maintain list in time order - set curauls [$self aul] - set ecrids [split $szEventToRecord "|"] - set evtaul {} - set insert 1 - set start 0 - # Do we have new event to add? - if {$new_event != 0 && $new_event !={}} { - set service_id [$new_event get channel_hsvc] - set start [$new_event get start] - set end [$new_event end] - set evtid [$new_event get event_id] - set evtaul [list $service_id $start $end $evtid] - set evtcrid [string toupper "1[$new_event get channel_crid][$new_event get event_crid]"] - set insert 0 - } - # rebuild aul and events list with new event in correct order - lmap aul $curauls ecrid $ecrids { - #puts "$aul $ecrid" - if {$aul == $old_aul} {continue; #remove current entry} - if {$aul == ""} {continue; #null entry} - if {!$insert && $start <= [lindex $aul 1]} { - set insert 1 - lappend newaul $evtaul - append newevnts "$evtcrid|" - } - lappend newaul $aul - append newevnts "$ecrid|" - } - # add to end if not inserted - if {!$insert} { - set insert 1 - lappend newaul $evtaul - append newevnts "$evtcrid|" - } - set action 5 - $self setaul [$self buildaul $newaul] - set szEventToRecord $newevnts - } + # Add new_event (optional) to aulEventToRecordInfo and szEventToRecord + # remove old_aul (optional) from " " + # Maintain list in time order + set curauls [$self aul] + set ecrids [split $szEventToRecord "|"] + set evtaul {} + set insert 1 + set start 0 + # Do we have new event to add? + if {$new_event != 0 && $new_event !={}} { + set service_id [$new_event get channel_hsvc] + set start [$new_event get start] + set end [$new_event end] + set evtid [$new_event get event_id] + set evtaul [list $service_id $start $end $evtid] + set evtcrid [string toupper + "1[$new_event get channel_crid][$new_event get event_crid]"] + set insert 0 + } + # rebuild aul and events list with new event in correct order + lmap aul $curauls ecrid $ecrids { + #puts "$aul $ecrid" + if {$aul == $old_aul} {continue; #remove current entry} + if {$aul == ""} {continue; #null entry} + if {!$insert && $start <= [lindex $aul 1]} { + set insert 1 + lappend newaul $evtaul + append newevnts "$evtcrid|" + } + lappend newaul $aul + append newevnts "$ecrid|" + } + # add to end if not inserted + if {!$insert} { + set insert 1 + lappend newaul $evtaul + append newevnts "$evtcrid|" + } + set action 5 + $self setaul [$self buildaul $newaul] + set szEventToRecord $newevnts +} rsv method set_next_event {} { - # Update reservation next event info in ucVolume - if {[string length $aulEventToRecordInfo] >0} { - binary scan [string range $aulEventToRecordInfo 0 15]\ - iiii service_id start end event_id - set dur $($end-$start) - if {$hsvc != $service_id || - $nsttime != $start || - $nduration != $dur || - $usevtid != $event_id} { - set nduration $dur - set ucVolume "$service_id:$event_id:$start" - } - } else { - # The next event is not yet in the EPG - set time $([clock seconds] - 86400) - set ucVolume "$hsvc:$usLastRecordedEvtId:$time" - } + # Update reservation next event info in ucVolume + if {[string length $aulEventToRecordInfo] >0} { + binary scan [string range $aulEventToRecordInfo 0 15] \ + iiii service_id start end event_id + set dur $($end-$start) + if {$hsvc != $service_id || + $nsttime != $start || + $nduration != $dur || + $usevtid != $event_id} { + set nduration $dur + set ucVolume "$service_id:$event_id:$start" + } + } else { + # The next event is not yet in the EPG + set time $([clock seconds] - 86400) + set ucVolume "$hsvc:$usLastRecordedEvtId:$time" + } } rsv method reset_next_event {} { - # Ensure our copy matches the updated reservation - if {$ucVolume!=0} { - lassign [split $ucVolume ":"] service_id event_id start - set hsvc $service_id - set nsttime $start - set usevtid $event_id - set ucVolume 0 - } + # Ensure our copy matches the updated reservation + if {$ucVolume != 0} { + lassign [split $ucVolume ":"] service_id event_id start + set hsvc $service_id + set nsttime $start + set usevtid $event_id + set ucVolume 0 + } } rsv method set_skip {event} { @@ -554,8 +554,8 @@ rsv method apply_skip {service event} { lassign [epg dbfetch dump -service $service -event $event] epg if {$epg eq ""} { - error "Cannot find event in EPG." - } + error "Cannot find event in EPG." + } $epg get_channel_info # First check to see if there is already a pending skip for this @@ -572,7 +572,7 @@ rsv method apply_skip {service event} { $ev set_skip $epg if {[catch {$ev insert_deferred} msg]} { error "Error during insert." - } + } } rsv method remove_pending {} { @@ -749,7 +749,7 @@ proc {rsv lookuptab} {} { set res [[rsv dbhandle] query " select usSvcId, usevtid, ucCRIDType, szCRID, ucRecKind, aulEventToRecordInfo, - szRecordedProgCrid + szRecordedProgCrid from $tab left join channel.TBL_SVC on $tab.hSvc = channel.TBL_SVC.hSvc where ersvtype <= 3 @@ -772,35 +772,39 @@ proc {rsv lookuptab} {} { continue } - foreach r [split $rec(szRecordedProgCrid) "|"] { - if {$r != {}} { - set records([string tolower "\ - $rec(szCRID):\ - [string range $r 1 end]"]) "R" - } - } + foreach r [split $rec(szRecordedProgCrid) "|"] { + if {$r != {}} { + set records([string tolower "\ + $rec(szCRID):\ + [string range $r 1 end]"]) "R" + } + } - set aul $rec(aulEventToRecordInfo) + set aul $rec(aulEventToRecordInfo) - if {[string length $aul]} { - for {set i 0} {$i < [string length $aul]} {incr i 16} { - binary scan [string range $aul $i $($i + 15)]\ - iiii service start end event_id - set records([\ - string tolower "$service:$event_id"]) $p - } - - } else { - set records([\ - string tolower "$rec(usSvcId):$rec(szCRID)"]) $p - } + if {[string length $aul]} { + for {set i 0} { + $i < [string length $aul]} {incr i 16} { + binary scan [string range \ + $aul $i $($i + 15)] \ + iiii service start end event_id + set records([ + string tolower \ + "$service:$event_id"]) $p + } + } else { + set records([ + string tolower \ + "$rec(usSvcId):$rec(szCRID)"]) $p + } } } - # Add all skipped epsisodes for all series - set skiplist [rsv _skiplist] - foreach skip $skiplist { - set records($skip) "X" - } + + # Add all skipped episodes for all series + set skiplist [rsv _skiplist] + foreach skip $skiplist { + set records($skip) "X" + } return $records } @@ -1224,7 +1228,7 @@ proc {rsv restore} {file} { # Need to fix up the AUL table service IDs too. set newaul "" foreach aul [$rsv aul] { - # {service start end event_id} + # {service start end event_id} lassign $aul ohsvc start end eid if {![dict exists $hsvcmap $ohsvc]} { # Should not happen @@ -1263,7 +1267,7 @@ proc {rsv restore} {file} { puts "Restoring skiplist..." set fields "ulslot state service_id event_id hSvc start - ucCRIDType szCRID szSkipCRID" + ucCRIDType szCRID szSkipCRID" foreach line $data { set vals [lrange [lassign [split $line "\t"] key] 0 end-1] @@ -1718,3 +1722,4 @@ proc {rsv reassert_skips} {{debug false}} { rsv commit } } +