From 2fb26975e27ed835655e1a1939d0055ccda1fef5 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Thu, 29 Sep 2011 23:22:02 +0000 Subject: [PATCH] new db based EPG git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@433 2a923420-c742-0410-a762-8d5b09965624 --- var/mongoose/html/fepg.shtml | 4 -- var/mongoose/html/img/channels/S4/C.png | 1 + var/mongoose/include/epg.jim | 55 ++++++++------- var/mongoose/include/fepg.jim | 94 ------------------------- var/mongoose/include/xepg.jim | 34 +++------ var/mongoose/lib/channelsort | 22 ++++++ var/mongoose/lib/epg.class | 62 +++++++++++++++- 7 files changed, 122 insertions(+), 150 deletions(-) delete mode 100644 var/mongoose/html/fepg.shtml create mode 120000 var/mongoose/html/img/channels/S4/C.png delete mode 100755 var/mongoose/include/fepg.jim create mode 100644 var/mongoose/lib/channelsort diff --git a/var/mongoose/html/fepg.shtml b/var/mongoose/html/fepg.shtml deleted file mode 100644 index d5857e7..0000000 --- a/var/mongoose/html/fepg.shtml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/var/mongoose/html/img/channels/S4/C.png b/var/mongoose/html/img/channels/S4/C.png new file mode 120000 index 0000000..9a9543b --- /dev/null +++ b/var/mongoose/html/img/channels/S4/C.png @@ -0,0 +1 @@ +../S4C.png \ No newline at end of file diff --git a/var/mongoose/include/epg.jim b/var/mongoose/include/epg.jim index 7a32192..c9c12d4 100755 --- a/var/mongoose/include/epg.jim +++ b/var/mongoose/include/epg.jim @@ -13,7 +13,14 @@ require epg.class spinner.class altrow epg_search totop require epg_popup set start [clock milliseconds] -set records [epg fetch dump -time [clock seconds]] +set now [clock seconds] +set then $($now + 7200) +if {$::qepg} { + set records [epg dbfetch dump -trange "$now:$then"] +} else { + require channelsort + set records [channelsort [epg fetch dump -trange "$now:$then"]] +} set got [clock milliseconds] set favlist [epg favlist] @@ -24,41 +31,37 @@ puts { Channel On Now On Next + On Later } -proc rsort {v1 v2} { - set v1s [$v1 get channel_num] - set v2s [$v2 get channel_num] - - if {$v1s == $v2s} { return 0 } - if {$v1s > $v2s } { return 1 } - return -1 -} - +set lcn 0 +set num 0 foreach record $records { - $record get_channel_info -} - -foreach record [lsort -command rsort $records] { if {$favlist != "" && [$record get service_id] ni $favlist} { continue } - set num [$record get channel_num] - if {$num == 0} { continue } - altrow - puts "$num" - puts "[$record channel_icon 50] - + set chnum [$record get channel_num] + if {$chnum == 0} { continue } + + if {$chnum != $lcn} { + if {$lcn > 0} { puts "" } + altrow + puts "$chnum" + puts "[$record channel_icon 50] + - [$record get channel_name] - " - catch { - puts [$record cell] - puts [[$record next] cell] + [$record get channel_name] + " + set lcn $chnum + set num 0 + } + incr num + if {$num < 4} { + catch { puts [$record cell] } } - puts "" } +if {$lcn > 0} { puts "" } puts "" puts " diff --git a/var/mongoose/include/fepg.jim b/var/mongoose/include/fepg.jim deleted file mode 100755 index 79dd0dc..0000000 --- a/var/mongoose/include/fepg.jim +++ /dev/null @@ -1,94 +0,0 @@ -#!/mod/bin/jimsh - -package require cgi -source /mod/var/mongoose/lib/setup -require epg.class spinner.class altrow epg_search totop - -[spinner new { - text "Loading Now/Next Information..." - size "1.2em" - style "margin: 1em;" - }] start - -require epg_popup - -set start [clock milliseconds] -set now [clock seconds] -set then $($now + 7200) -set records [epg fetch dump -trange "$now:$then"] -set got [clock milliseconds] - -set favlist [epg favlist] - -puts { - - - - - - -} - -proc rsort {v1 v2} { - set v1s [$v1 get channel_num] - set v2s [$v2 get channel_num] - - if {$v1s > $v2s } { return 1 } - if {$v1s == $v2s} { - set v1t [$v1 get start] - set v2t [$v2 get start] - if {$v1t > $v2t} { return 1 } - if {$v1t == $v2t} { return 0 } - return -1 - } - return -1 -} - -foreach record $records { - $record get_channel_info -} - -set lcn 0 -set num 0 -foreach record [lsort -command rsort $records] { - if {$favlist != "" && [$record get service_id] ni $favlist} { - continue - } - set chnum [$record get channel_num] - if {$chnum == 0} { continue } - - if {$chnum != $lcn} { - if {$lcn > 0} { puts "" } - altrow - puts "" - puts " - " - set lcn $chnum - set num 0 - } - incr num - if {$num < 4} { - catch { puts [$record cell] } - } -} -if {$lcn > 0} { puts "" } -puts "
ChannelOn NowOn Next
$chnum[$record channel_icon 50] - - [$record get channel_name] -
" - -puts " - - - Visit settings to change EPG options. -
-" - -set end [clock milliseconds] -puts " - Retrieved in: [expr [expr $got - $start] / 1000.0] seconds. - Rendered in: [expr [expr $end - $start] / 1000.0] seconds. - " - -epg cleanup - diff --git a/var/mongoose/include/xepg.jim b/var/mongoose/include/xepg.jim index 27a630e..9d706d9 100755 --- a/var/mongoose/include/xepg.jim +++ b/var/mongoose/include/xepg.jim @@ -20,30 +20,16 @@ set stt [clock seconds] set stt [expr int($stt / 1800) * 1800] set ett $($stt + 14400) -set records [epg fetch dump -trange "$stt:$ett"] +if {$::qepg} { + set records [epg dbfetch dump -trange "$stt:$ett"] +} else { + require channelsort + set records [channelsort [epg fetch dump -trange "$stt:$ett"]] +} set got [clock milliseconds] set favlist [epg favlist] -proc rsort {v1 v2} { - set v1s [$v1 get channel_num] - set v2s [$v2 get channel_num] - - if {$v1s > $v2s } { return 1 } - if {$v1s == $v2s} { - set v1t [$v1 get start] - set v2t [$v2 get start] - if {$v1t > $v2t} { return 1 } - if {$v1t == $v2t} { return 0 } - return -1 - } - return -1 -} - -foreach record $records { - $record get_channel_info -} - puts { @@ -67,7 +53,7 @@ puts "" set lcn 0 set bg "odd" -foreach record [lsort -command rsort $records] { +foreach record $records { if {$favlist != "" && [$record get service_id] ni $favlist} { continue } @@ -143,13 +129,13 @@ puts { $(document).ready(function() { $('#epgswitch').button().click(function() { - window.location = '/epg.html'; + window.location = '/epg.shtml'; }); $('#earlier').button().click(function() { - window.location = '/xepg.html?stt='; + window.location = '/xepg.shtml?stt='; }); $('#later').button().click(function() { - window.location = '/xepg.html?stt='; + window.location = '/xepg.shtml?stt='; }); }); diff --git a/var/mongoose/lib/channelsort b/var/mongoose/lib/channelsort new file mode 100644 index 0000000..483d5af --- /dev/null +++ b/var/mongoose/lib/channelsort @@ -0,0 +1,22 @@ +proc _channelsort {v1 v2} { + set v1s [$v1 get channel_num] + set v2s [$v2 get channel_num] + + if {$v1s > $v2s } { return 1 } + if {$v1s == $v2s} { + set v1t [$v1 get start] + set v2t [$v2 get start] + if {$v1t > $v2t} { return 1 } + if {$v1t == $v2t} { return 0 } + return -1 + } + return -1 +} + +proc channelsort {records} { + foreach record $records { + $record get_channel_info + } + return [lsort -command _channelsort $records] +} + diff --git a/var/mongoose/lib/epg.class b/var/mongoose/lib/epg.class index d43393a..d03f893 100644 --- a/var/mongoose/lib/epg.class +++ b/var/mongoose/lib/epg.class @@ -5,13 +5,21 @@ 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 ::epgdbpath /mnt/hd1/epg.db set ::hdepgpath /media/drive1/epgsavedata if {![file exists $::epgpath] && [file exists $::hdepgpath]} { set ::epgpath $::hdepgpath + set ::epgdbpath /media/drive1/epg.db +} + +set ::channeldb 0 +set ::qepg 0 +catch { set ::channeldb [sqlite3.open /var/lib/humaxtv/channel.db] } +if {[file exists $::epgdbpath]} { + $::channeldb query {attach database '%s' as epg} $::epgdbpath + set ::qepg 1 } set ::rsvlookup [rsv lookuptab] @@ -312,6 +320,56 @@ proc {epg exec} {mode args} { return [exec {*}$cmd] } +proc {epg dbfetch} {mode args} { + set records {} + set extra "" + set q "select distinct *, + usLcn as channel_num, + substr(szSvcName, 2) as channel_name, + aucDefaultAuthority as channel_crid, + hSvc as channel_hsvc + from epg.epg e join TBL_SVC c + on e.service_id = c.usSvcId where 1 " + foreach arg $args { + if {[string first "-" $arg] == 0} { + set v $args($arg) + switch -- $arg { + -crid { append q \ + "and e.event_crid = '$v' " } + -scrid { append q \ + "and e.series_crid = '$v' " } + -type { append q \ + "and e.content_type = $v " } + -service { append q \ + "and e.service_id = $v " } + -event { append q \ + "and e.event_id = $v " } + -time { append q \ + "and e.start < $v and e.end > $v " } + -trange { + lassign [split $v :] stt ett + append q "and ( + (e.start > $stt and e.start < $ett) or + (e.end > $stt and e.end < $ett) or + (e.start < $stt and e.end > $stt) + ) " + } + + default { error "Invalid option, $arg" } + } + } + } + append q "order by channel_num, start" + + #puts "QUERY -$q-" + + set records {} + foreach rec [$::channeldb query $q] { + lappend records [epg new $rec] + } + return $records +} + proc {epg fetch} {mode args} { set records "" foreach line [split [epg exec $mode {*}$args] "\n"] {