handle split recording, inprove fmtrv to list enumerations

This commit is contained in:
Bob Buxton 2020-05-18 22:51:15 +01:00
parent 8ef0887bd5
commit b59cc9e687
3 changed files with 188 additions and 136 deletions

View File

@ -137,6 +137,17 @@ proc rsvscan {} {
set resvs [rsv list TBL_RESERVATION $::select]
# Enumerations
set rsvtype { 1 Reminder 2 "Manual reminder" 3 Recording 4 "Manual Recording"
5 "Wake-up" 6 Sleep 7 "Auto Update" 11 "DSO"}
set reckind {0 "" 1 1-off 2 "split recording" 3 "unknown" 4 "series"}
set CRIDType {49 1-off 50 "series"}
set repeat {0 "no repeats"
1 Daily
2 Weekly
3 Weekdays
4 Weekend}
# for each reservation
foreach resv $resvs {
set name [$resv name]
@ -189,12 +200,12 @@ proc rsvscan {} {
set auls [$resv aul]
puts "ulslot = $ulslot "
puts "ersvtype = $ersvtype "
puts "ersvtype = $ersvtype $rsvtype($ersvtype) "
puts "hsvc = $hsvc "
puts "nsttime = $nsttime [clock format $nsttime -format "%d/%m/%Y %H:%M"]"
puts "szsttime = $szsttime "
puts "nduration = $nduration [clock format $nduration -format "%H:%M"]"
puts "erepeat = $erepeat "
puts "erepeat = $erepeat $repeat($erepeat)"
puts "usevtid = $usevtid "
puts "szevtname = $szevtname ($name) "
puts "ulPreOffset = $ulPreOffset "
@ -204,8 +215,8 @@ proc rsvscan {} {
puts "ucVolume = $ucVolume "
puts "ucInputMode = $ucInputMode "
puts "usChNum = $usChNum "
puts "ucRecKind = $ucRecKind "
puts "ucCRIDType = $ucCRIDType "
puts "ucRecKind = $ucRecKind $reckind($ucRecKind)"
puts "ucCRIDType = $ucCRIDType $CRIDType($ucCRIDType)"
puts "szCRID = $szCRID "
puts "szFPBRecPath = $szFPBRecPath "
puts "szRecordedProgCrid = $szRecordedProgCrid "
@ -230,6 +241,14 @@ proc rsvscan {} {
[format "%7d" $event_id] \
$ecrid"
}
set skips [$resv skiplist]
if {[llength $skips]} {
puts "Skiplist Svcid:Evtid"
foreach skip $skips {
puts $skip
}
}
puts "========================================================"
puts ""

View File

@ -17,13 +17,6 @@ set optarray {
{{No inplace} {noInplace} n {Update reservation by skipping & 1-off rather than inplace}}
}
# set optlist_file "[file dirname [info script]]/schedchk.optlist"
# set hand [open $optlist_file]
# set data [read -nonewline $hand]
# set optarray [split $data \n]
# close $hand
# foreach optl $optarray {
# lassign $optl desc key default helptxt
# }

View File

@ -23,6 +23,10 @@ rsv method set {ivName val} {
set $ivName $val
}
rsv method issplit {} {
if {$ucRecKind == 2} { return 1 } else { return 0 }
}
# Parse command options and apply defaults
proc checkopts {argv} {
global optarray
@ -211,25 +215,19 @@ proc rsvscan {} {
if {!$ended} {
log "Reservation - $dresv" 2
# Check whether active recording really is recording
if {$s - $sp < $now} {
#
# Should be recording now, check if it is
#
log "Already started? Status = $rstatus - $dresv" 1
if {$::opts(nonotrec)} {
log "-noNotRec - Not checking for failed recording" 2
continue
}
# need to check whether it has actually started and schedule alternate if not recording
if {$rstatus=="recording"} {
# Recording but is it actually growing
# How to associate recording with slot?22
puts [system nugget recordings]
}
chkActive $resv $dresv $rstatus
# don't check active recordings further
continue
}
# If split recording check for repeats
if {[$resv issplit]} {
if {[chkSplit $resv $dresv]} {continue}
}
# add any missing episodes
if {[$resv isseries]} {
miss_epsd $resv $dresv
@ -237,10 +235,16 @@ proc rsvscan {} {
set d [$resv get nduration]
set e $($s + $d)
}
if {$s > $thresh} {
log "Start > Threshold - $dresv" 2
# check for new series in same time slot
if {[$resv isseries]} {
scrid_chg $resv $dresv $lasttime
}
continue
}
set elist [$resv aul]
set enum -1
set ecrids [split [string toupper [$resv get szEventToRecord]] "|"]
@ -317,6 +321,102 @@ proc rsvscan {} {
log "===============================================" 2
epg cleanup
}
#
# Should be recording now, check if it is
#
proc chkActive {resv dresv rstatus} {
log "Already started? Status = $rstatus - $dresv" 1
if {$::opts(nonotrec)} {
log "-noNotRec - Not checking for failed recording" 2
return
}
# need to check whether it has actually started and schedule alternate if not recording
if {$rstatus=="recording"} {
# Recording but is it actually growing
# How to associate recording with slot?22
puts [system nugget recordings]
}
}
#
# Split recording, check for repeats incorrectly scheduled
#
proc chkSplit {resv dresv} {
global svcmap conflicts svcdef now thresh slot name def
log "Split recording - $dresv" 2
if {$::opts(nosplit} {
log "-noSplit - Not checking for split recordings" 2
return 0
}
# need to check whether any portion is greater than 3hrs after previous
set elist [$resv aul]
set problems false
if {[llength $elist] <= 2} {return 0}
set enum -1
set pend [$resv end]
set pstart [$resv start]
set 3hrs $(3*60*60)
set epg {}
set first 0
set last 0
set ok true
foreach epsd $elist {
lassign $epsd service_id start end event_id
#puts "$start $end $pend $3hrs"
incr enum
if {$start > $pend+$3hrs } {
log "Split recording >3hrs gap - $dresv" 0
set problems true
if {$ok} {
break
}
# try the next repeat showing
set ok true
set first $enum
}
set last $enum
set pend $end
set svc $svcmap($service_id)
# Check if segment conflicts
if {"$slot$end" in $conflicts} {
set ok 0
}
# Retrieve epg record for the episode
set epg($enum) [lindex [\
epg dbfetch dump -service $svc -event $event_id -sort ""] 0]
if {$epg($enum) ==0} {
set ok 0
}
}
if {$problems} {
set crid "1[$resv get szCRID]#|"
set aul {}
set torec {}
if {$::opts(noinplace)} {
cancel $resv $dresv "Replace Split recording"
}
loop enum $first $($last+1) {
lappend aul [lindex $elist $enum]
set torec "$torec$crid"
if {$::opts(noinplace)} {
# Mark as Unscheduled
epg update_lookup_tab $service_id $event_id 0
# Reschedule as 1-off event
schedule $epg($enum) $dresv "Replace Split recording"
}
}
if {!$::opts(noinplace)} {
$resv set szEventToRecord $torec
$resv setaul [$resv buildaul $aul]
log "$aul $torec" 2
update_event $resv {} {} $dresv "Replace Split recording"
}
conflict-list
}
return $problems
}
#
# check each episode for changes and conflicts
@ -328,10 +428,6 @@ proc chkEpisode {resv epsd ecrid} {
set ecrid [string range $ecrid 1 end]
set dur $($end-$start)
set deps "[clock format $start -format {%d/%m/%y %H:%M}] [clock format $dur -format {%H:%M}] === slot $slot === $name === [$resv channel_name]"
set svc $svcmap($service_id)
# Retrieve epg record for the episode
set record [lindex [\
@ -369,7 +465,7 @@ proc chkEpisode {resv epsd ecrid} {
conflict-list
return
}
# attempt to schedule the alternate (new even+skip)
# attempt to schedule the alternate (new event+skip)
if {[schedule $other $dother "Event Changed"]} {
if {![$resv isseries]} {
# delete single recording
@ -413,7 +509,7 @@ proc chkEpisode {resv epsd ecrid} {
set reason "no reason"
if {$start != [$record get start]} {
set ok 0
set reason "Start Mismatch: $start != [$record get start"
set reason "Start Mismatch: $start != [$record get start]"
log "+++ $reason +++ $deps" 1
}
if {$dur != [$record get duration]} {
@ -422,7 +518,12 @@ proc chkEpisode {resv epsd ecrid} {
log "+++ $reason +++ $deps" 1
}
set evt_crid [string toupper [$record get event_crid]]
if {$epgcrid != $evt_crid
if {[$resv issplit]} {
set cl [string first "#" $evt_crid]
} else {
set cl [string length $evt_crid]
}
if {![string equal -length $cl $epgcrid $evt_crid]
&& $epgcrid != ""} {
set ok 0
set reason "Crid Mismatch: $epgcrid != $evt_crid"
@ -430,18 +531,24 @@ proc chkEpisode {resv epsd ecrid} {
}
if {!$ok && !$::opts(noepgchg)} {
if {!$::opts(noinplace)} {
update_event $resv $record $epsd "$deps" $reason
update_event $resv $record $epsd $deps $reason
} else {
refresh $resv $deps $reason
}
conflict-list
}
# Check for conflicts ($condlicts is null if checking supressed)
# Check for conflicts ($conflicts is null if checking supressed)
if {"$slot$end" in $conflicts} {
set ok 0
log "+++ Confict exists +++ $deps" 1
if {[$resv issplit]} {
# dont conflict check split recordings
# (might end up with 2 first half or parts out of order)
# also cant find alternates with different #IMI
return
}
#set others [$record othertimes]
set others [epg dbfetch dump -crid $epgcrid -nocase 1 -sort "start"]
set other [findAlternate $resv $others $start $def 0]
@ -505,6 +612,10 @@ proc scanAlternates {resv others start definition sametime samedef} {
# should favour same definition
if {$odef != $definition && $samedef} {continue}
log "Alternate Episode $dother" 2
if {[$other scheduled]} {
log "Already scheduled - $dother" 2
continue
}
set oconflicts [rsv checkconflict \
$ostart $odur \
[system tuners]]
@ -513,7 +624,7 @@ proc scanAlternates {resv others start definition sametime samedef} {
if {"$oname" in $oconflicts} {incr cl -1}
if {$cl >= [system tuners]} {
# Alternate has Conflicts
log "Alternate conflicts $oconflicts" 2
log "Alternate conflicts $oconflicts - $dother" 2
continue
}
return $other
@ -523,7 +634,7 @@ proc scanAlternates {resv others start definition sametime samedef} {
# Strip new: prefix from name prior to search
proc strip_new {name} {
foreach pfx {"new:" "new series." new} {
foreach pfx {"new:" "new series." "new "} {
if {[string first $pfx [string tolower $name]] == 0} {
set name [string range $name [string length $pfx] end]
break
@ -533,7 +644,7 @@ proc strip_new {name} {
}
# Check for prossible changes to series CRID
# Unscheduled series at same time/channel as an existing ulSeries
# Unscheduled series at same time/channel as an existing Series
# Also one-off programmes matching series name
proc scrid_chg {resv desc lasttime} {
global thresh svcmap now
@ -548,8 +659,10 @@ proc scrid_chg {resv desc lasttime} {
set svc $svcmap([$resv get hsvc])
set start [$resv start]
set timeslot [clock format $start -format "%H:%M"]
#if {$lasttime < $now} {set lasttime $now}
set lasttime $now
set others [epg dbfetch dump -service $svc -term [strip_new $name] -after $lasttime -before $thresh -sort "start"]
set others [epg dbfetch dump -service $svc -term [strip_new $name] -after $lasttime -before $thresh -sort "start" -debug 0]
foreach other $others {
set ostart [$other get start]
@ -561,7 +674,11 @@ proc scrid_chg {resv desc lasttime} {
set oscrid [$other get series_crid]
set oecrid [$other get event_crid]
set dother "[clock format $ostart -format {%d/%m/%y %H:%M}] [clock format $odur -format {%H:%M}] === $oname === $ocname"
log "Potential event - $dother" 2
if {$ostart <= $now} {
log "Already started - $dother" 2
continue
}
if {$oscrid !=""} {
# Event is part of a series, check start time matches
if {$ostarttime == $timeslot} {
@ -570,10 +687,12 @@ proc scrid_chg {resv desc lasttime} {
continue
}
if {[string first [string toupper $oscrid] $scrid] >= 0} {
# found episode of current series - shouldn't happen
# found episode of current series
log "Current series - $dother" 2
continue
}
if {[$other scheduled]} {
log "Already scheduled - $dother" 2
continue
}
set oconflicts [rsv checkconflict \
@ -581,7 +700,7 @@ proc scrid_chg {resv desc lasttime} {
[system tuners]]
set cl [llength $oconflicts]
if {$cl >= [system tuners]} {
log "Alternate conflicts $oconflicts" 2
log "Potential New series conflicts $oconflicts - $dother " 1
continue
}
log "Found new series matching $name - $dother - $oscrid" 1
@ -608,6 +727,7 @@ proc scrid_chg {resv desc lasttime} {
continue
}
if {[$other scheduled]} {
log "Potential 1-off already scheduled - $dother" 2
continue
}
@ -616,7 +736,7 @@ proc scrid_chg {resv desc lasttime} {
[system tuners]]
set cl [llength $oconflicts]
if {$cl >= [system tuners]} {
log "Alternate conflicts $oconflicts" 2
log "Potential 1-off conflicts $oconflicts - $dother" 1
continue
}
log "Found 1-off matching $name - $dother" 1
@ -679,6 +799,7 @@ proc miss_epsd {resv desc} {
# Create a new reservation
proc schedule {event desc {reason ""} {type 1} } {
global svcmap
if {[$event scheduled]} {
log "*** Already scheduled *** $desc === $reason" 0
return 1
@ -686,13 +807,19 @@ proc schedule {event desc {reason ""} {type 1} } {
# mark new event as scheduled
set service_id [$event get channel_hsvc]
set event_id [$event get event_id]
epg update_lookup_tab service_id event_id 1
epg update_lookup_tab [$event get service_id] $event_id 1
epg update_lookup_tab $service_id $event_id 1
if {$::opts(test)} {
log "*** Test mode =scheduled *** $desc === $reason" 0
return 1
}
set r [rsv construct $event $type]
if {[$r issplit]} {
# turn split rcording into 1off by removing #imi from url
#$r set ucRecKind 1
$r set szEventToRecord "1[$r get szCRID]|"
}
if {[catch {$r insert pending} msg]} {
log "+++ Error while scheduling: $msg ++++ $desc === $reason" 0
return 0
@ -728,10 +855,12 @@ proc refresh {resv desc {reason ""}} {
# Cancel reservation
proc cancel {resv desc {reason ""}} {
global svcmap
# mark event as not scheduled
set service_id [$resv get hsvc]
set event_id [$resv get usevtid]
epg update_lookup_tab service_id event_id 0
epg update_lookup_tab $service_id $event_id 0
epg update_lookup_tab $svcmap($service_id) $event_id 0
if {$::opts(test)} {
log "*** Test mode =cancelled *** $desc === $reason" 0
@ -793,108 +922,19 @@ proc replaceskip {resv skipcrid desc {reason ""}} {
}
}
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
}
}
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
}
}
}
# Update reservation with new event details
proc update_event {resv other origaul desc {reason ""}} {
if {$origaul != {}} {
# mark event not scheduled
lassign $origaul service_id start end event_id
epg update_lookup_tab service_id event_id 0
epg update_lookup_tab $service_id $event_id 0
}
if {$other != {}} {
# mark new event as scheduled
set service_id [$other get channel_hsvc]
set event_id [$other get event_id]
epg update_lookup_tab service_id event_id 1
epg update_lookup_tab $service_id $event_id 1
}
if {$::opts(test)} {
log "*** Test mode =Updated *** $desc === $reason" 0
@ -904,7 +944,7 @@ proc update_event {resv other origaul desc {reason ""}} {
# update header with next event
$resv set_next_event
log "$desc - [$resv aul]-[$resv get ucVolume] " 3
if {[catch {
$resv insert
} msg]} {