source /mod/var/mongoose/lib/setup if {![exists -proc class ]} { package require oo } if {![exists -proc sqlite3.open ]} { package require sqlite3 } require settings.class progressbar rsv.class set ::channeldb 0 catch { set ::channeldb [sqlite3.open /var/lib/humaxtv/channel.db] } set ::epgpath /mnt/hd1/dvbepg/epg.dat set ::hdepgpath /media/drive1/epgsavedata if {![file exists $::epgpath] && [file exists $::hdepgpath]} { set ::epgpath $::hdepgpath } set ::rsvlookup [rsv lookuptab] # * service_id, event_id, start, duration, encrypted, name, text # * warning, content code, content type, # * event CRID, series CRID, rec CRID class epg { service_id 0 event_id 0 start 0 duration 0 encrypted 0 name "" text "" warning "" content_code 0 content_type "" event_crid "" series_crid "" rec_crid "" channel_num 0 channel_name "" channel_crid "" channel_hsvc 0 sched_type 0 rsv 0 } epg method _parse {line} { set vars [split $line "\t"] set service_id [lindex $vars 0] set event_id [lindex $vars 1] set start [lindex $vars 2] set duration [lindex $vars 3] set encrypted [lindex $vars 4] set name [lindex $vars 5] set text [lindex $vars 6] set warning [lindex $vars 7] set content_code [lindex $vars 8] set content_type [lindex $vars 9] set event_crid [lindex $vars 10] set series_crid [lindex $vars 11] set rec_crid [lindex $vars 12] } epg method percent {} { set now [clock seconds] if {$start > $now} { return 0 } if {$start + $duration < $now} { return 100 } return [expr [expr $now - $start] * 100 / $duration] } epg method showing {} { set now [clock seconds] if {$start > $now} { return 0 } if {$start + $duration < $now} { return 0 } return 1 } epg method ended {} { if {$start + $duration < [clock seconds]} { return 1 } return 0 } epg method elapsed {} { set percent [$self percent] if {$percent == 0} { return 0 } if {$percent == 100} { return $duration } return [expr $duration * $percent / 100] } epg method remaining {} { return [expr $duration - [$self elapsed]] } epg method type_icon {} { set img "" switch -- $content_code { 1 { set img "Movie" } 2 { set img "News" } 3 { set img "Show" } 4 { set img "Sports" } 5 { set img "Children" } 6 { set img "Music" } 7 { set img "Art" } 8 { set img "Society" } 9 { set img "Education" } 10 { set img "Leisure" } } if {$img != ""} { return "/images/173_3_00_G3_$img.png" } else { return "" } } proc {epg channelicon} {name {width 0} {style ""}} { set str " 0} { append str " width=$width" } if {$style ne ""} { append str " style=\"$style\" } append str " alt=\"\">" return $str } epg method channel_icon {{width 0} {style ""}} { set str " 0} { append str " width=$width" } if {$style ne ""} { append str " style=\"$style\" } append str " alt=\"\">" return $str } epg method get_channel_info {} { global channeldb if {!$channel_num && $channeldb != ""} { set chan [lindex [$channeldb query { select szSvcName, usLcn, aucDefaultAuthority, hsvc from TBL_SVC where usSvcId = '%s'} $service_id ] 0] if {[dict exists $chan usLcn]} { set channel_num $chan(usLcn) set channel_name [string range $chan(szSvcName) 1 end] set channel_crid [string toupper $chan(aucDefaultAuthority)] set channel_hsvc $chan(hSvc) } } } epg method get_rsv {} { if {$hsvc == 0} { $self get_channel_info } if {$hsvc == 0} { return } if {$rsv == 0 && $event_crid ne ""} { set rsv [rsv entry $event_crid $hsvc] } if {$rsv == 0 && $series_crid ne ""} { set rsv [rsv entry $series_crid $hsvc] } } epg method process_sched {} { set sched_type 0 if {$event_crid ne "" && "$channel_hsvc$event_crid" in $::rsvlookup} { set sched_type 1 } elseif {$series_crid ne "" && "$channel_hsvc$series_crid" in $::rsvlookup} { set sched_type 2 } } epg method icon_set {{height 0}} { if {$height > 0} { set height "height=$height" } else { set height "" } set icon [$self type_icon] set set "" if {$icon != ""} { lappend set "\"$content_type\"" } $self process_sched if {$sched_type == 1} { lappend set \ "" } if {$sched_type == 2} { lappend set \ "" } elseif {$series_crid ne ""} { lappend set \ "" } if {$rec_crid ne ""} { lappend set \ "" } if {[string match {/*#?} $event_crid]} { lappend set \ "" } return $set } epg method cell {} { set percent [$self percent] puts "" puts [join [$self icon_set 14] ""] if {$series_crid ne ""} { set recopts 2 } else { set recopts 1 } puts " $name " puts "
" puts "" puts "[clock format $start -format %H:%M]" puts " ([clock format $duration -format %T])" if {$percent > 0 && $percent < 100} { puts "
[progressbar $percent]" puts "$percent% [clock format [$self elapsed] -format %T] / [clock format [$self remaining] -format %T]" } puts "
" puts "" } epg method next {} { set tm $($start + $duration + 60) set nextlist [epg fetch dump -service $service_id -time $tm] if {[llength nextlist] > 0} { return [lindex $nextlist 0] } else { return "" } } epg method recommended {} { set rec "" if {$rec_crid ne ""} { catch { set rec [lindex [ epg fetch dump -crid $rec_crid] 0] } } return $rec } epg method othertimes {} { if {$event_crid eq ""} { return "" } set others "" foreach other [epg fetch dump -crid $event_crid] { if {[$other get service_id] == $service_id && [$other get event_id] == $event_id} { continue } lappend others $other } return $others } proc {epg parse} {line} { set e [epg new] $e _parse $line return $e } proc {epg cleanup} {} { global channeldb if {$channeldb != ""} { $channeldb close } } proc {epg exec} {mode args} { set raw 0 set cmd [list /mod/bin/epg -f $::epgpath] set extra "" foreach arg $args { if {[string first "-" $arg] == 0} { switch -- $arg { -raw { set raw 1 } -crid { lappend cmd -C $args($arg) } -scrid { lappend cmd -R $args($arg) } -type { lappend cmd -T $args($arg) } -service { lappend cmd -S $args($arg) } -event { lappend cmd -E $args($arg) } -time { lappend cmd -@ $args($arg) } -day { lappend cmd -/ $args($arg) } -extra { set extra $args($arg) } default { error "Invalid option, $arg" } } } } if { $raw == 0 } { lappend cmd -p } lappend cmd $mode lappend cmd $extra #puts "CMD -$cmd-" return [exec {*}$cmd] } proc {epg fetch} {mode args} { set records "" foreach line [split [epg exec $mode {*}$args] "\n"] { lappend records [epg parse $line] } return $records } proc {epg favlist} {} { global channeldb set num [[settings] channel_group] if {!$num} { return "" } return [lmap i [$channeldb query " select TBL_SVC.usSvcid from TBL_SVC join TBL_FAV using(hSvc) where TBL_FAV.eFavGroup == $num "] { lindex $i end }] } proc {epg channellist} {} { global channeldb set channels {} lmap i [$channeldb query " select usSvcid, szSvcName from TBL_SVC "] { set channels([string range [lindex $i 3] 1 end]) [lindex $i 1] } return $channels }