webif/webif/lib/svc.class
2020-04-19 12:00:49 +01:00

77 lines
1.5 KiB
Tcl
Executable File

source /mod/webif/lib/setup
if {![exists -proc class]} { package require oo }
if {![exists -proc sqlite3.open]} { package require sqlite3 }
require system.class
class svc {
hSvc -1
usSvcId 0
szSvcName {}
aucDefaultAuthority {}
usLcn 0
eVideoType 0
eSystem 0
}
proc {svc dbhandle} {args} {
if {"-close" in $args} {
if {[info exists ::svc::db]} {
catch {$::svc::db close}
unset ::svc::db
return 1
}
return 0
}
if {[info exists ::svc::db]} {
return $::svc::db
}
set ::svc::db [sqlite3.open /var/lib/humaxtv/channel.db]
return $::svc::db
}
alias {svc cleanup} svc dbhandle -close
proc {svc _import} {data} {
set data(szSvcName) [system strip $data(szSvcName)]
return [svc new $data]
}
proc {svc _load_clause} {clause vals} {
set res [[svc dbhandle] query "
select szSvcName, usLcn, usSvcId, eVideoType,
TBL_SVC.aucDefaultAuthority as aucDefaultAuthority,
hSvc, eSystem
from TBL_SVC join TBL_TS using (tsIdx)
where $clause
limit 1
" {*}$vals]
if {[llength $res] > 0} {
return [svc _import [lindex $res 0]]
}
return 0
}
proc {svc load} {field val} {
return [svc _load_clause "TBL_SVC.%s = %s" [list $field $val]]
}
proc {svc channel} {channel} {
return [svc _load_clause "szSvcName = '%s'
or szSvcname = '\025%s'" [list $channel $channel]]
}
proc {svc hsvc} {hsvc} {
return [svc _load_clause "hSvc = %s" [list $hsvc]]
}
svc method definition {} {
if {$eVideoType == 2} { return "HD" }
return "SD"
}