2011-06-16 03:10:41 +00:00
|
|
|
|
2012-01-13 21:23:03 +00:00
|
|
|
if {![exists -proc class]} { package require oo }
|
2013-07-11 22:13:36 +00:00
|
|
|
if {![exists -proc pack]} { package require pack }
|
2012-05-21 20:23:41 +00:00
|
|
|
source /mod/webif/lib/setup
|
2012-06-15 21:34:07 +00:00
|
|
|
require tdelete system.class
|
2011-06-16 03:10:41 +00:00
|
|
|
|
2011-10-11 19:51:58 +00:00
|
|
|
set dmsfile /mnt/hd2/dms_cds.db
|
|
|
|
|
2012-08-07 22:22:30 +00:00
|
|
|
set tsgroup {ts nts hmt thm}
|
|
|
|
|
2011-06-16 03:10:41 +00:00
|
|
|
class ts {
|
|
|
|
file ""
|
2011-06-16 23:49:48 +00:00
|
|
|
base ""
|
2011-06-16 03:10:41 +00:00
|
|
|
title ""
|
|
|
|
synopsis ""
|
|
|
|
definition ""
|
|
|
|
channel_num 0
|
|
|
|
channel_name ""
|
|
|
|
start 0
|
|
|
|
end 0
|
|
|
|
flags ""
|
|
|
|
error ""
|
2011-06-27 19:57:32 +00:00
|
|
|
guidance ""
|
2011-11-03 23:43:17 +00:00
|
|
|
bookmarks 0
|
2011-12-27 18:43:40 +00:00
|
|
|
schedstart 0
|
|
|
|
scheddur 0
|
2013-01-06 23:50:39 +00:00
|
|
|
genre 0
|
2011-06-16 03:10:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-03 23:43:17 +00:00
|
|
|
ts method duration {{raw 0}} {
|
|
|
|
set d [expr $end - $start]
|
|
|
|
if {!$raw} { set d $($d / 60) }
|
|
|
|
return $d
|
2011-06-16 03:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ts method size {} {
|
2011-06-22 23:36:30 +00:00
|
|
|
file stat $file st
|
|
|
|
return $st(size)
|
2011-06-16 03:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ts method _parse {line} {
|
|
|
|
set vars [split $line "\t"]
|
|
|
|
|
2011-11-03 23:43:17 +00:00
|
|
|
lassign [split $line "\t"] \
|
|
|
|
title synopsis definition channel_num channel_name \
|
2013-01-06 23:50:39 +00:00
|
|
|
start end flags_list guidance bookmarks schedstart scheddur \
|
|
|
|
genre
|
2011-11-03 23:43:17 +00:00
|
|
|
|
|
|
|
set flags [split [string range $flags_list 0 end-1] ,]
|
|
|
|
}
|
|
|
|
|
2013-02-25 22:31:54 +00:00
|
|
|
ts method inuse {} {
|
|
|
|
if {[system inuse [file rootname $file]]} { return 1 }
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-11-03 23:43:17 +00:00
|
|
|
ts method bookmarks {} {
|
|
|
|
return [exec /mod/bin/hmt -bookmarks $file]
|
2011-06-16 03:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ts method flag {f} {
|
|
|
|
if {$f in $flags} {return 1} else {return 0}
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method unlock {} {
|
|
|
|
set cmd [list /mod/bin/hmt -lock $file]
|
|
|
|
exec {*}$cmd
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method lock {} {
|
|
|
|
set cmd [list /mod/bin/hmt +lock $file]
|
2011-07-08 20:39:57 +00:00
|
|
|
exec {*}$cmd
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2013-02-25 22:31:54 +00:00
|
|
|
ts method set_shrunk {} {
|
|
|
|
set cmd [list /mod/bin/hmt +shrunk $file]
|
|
|
|
exec {*}$cmd
|
2013-04-17 18:05:12 +00:00
|
|
|
lappend flags "Shrunk"
|
2013-02-25 22:31:54 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method set_deduped {} {
|
|
|
|
set cmd [list /mod/bin/hmt +dedup $file]
|
|
|
|
exec {*}$cmd
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2011-07-08 20:39:57 +00:00
|
|
|
ts method unenc {} {
|
|
|
|
set cmd [list /mod/bin/hmt -protect $file]
|
|
|
|
exec {*}$cmd
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method enc {} {
|
|
|
|
set cmd [list /mod/bin/hmt +protect $file]
|
|
|
|
exec {*}$cmd
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method set_new {} {
|
|
|
|
set cmd [list /mod/bin/hmt +new $file]
|
|
|
|
exec {*}$cmd
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method set_watched {} {
|
|
|
|
set cmd [list /mod/bin/hmt -new $file]
|
2011-06-16 03:10:41 +00:00
|
|
|
exec {*}$cmd
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method setfile {f} { set file $f }
|
|
|
|
|
|
|
|
proc {ts parse} {file line} {
|
|
|
|
set e [ts new]
|
|
|
|
$e setfile $file
|
|
|
|
$e _parse $line
|
|
|
|
return $e
|
|
|
|
}
|
|
|
|
|
|
|
|
proc {ts exec} {file} {
|
|
|
|
set raw 0
|
|
|
|
set cmd [list /mod/bin/hmt]
|
|
|
|
lappend cmd "-p"
|
|
|
|
lappend cmd $file
|
|
|
|
|
|
|
|
#puts "CMD -$cmd-"
|
|
|
|
|
|
|
|
return [exec {*}$cmd]
|
|
|
|
}
|
|
|
|
|
2012-08-07 22:22:30 +00:00
|
|
|
ts method fileset {} {
|
|
|
|
global tsgroup
|
|
|
|
|
|
|
|
set root [file rootname $file]
|
|
|
|
set fset {}
|
|
|
|
foreach ext $tsgroup {
|
|
|
|
if {[file exists "$root.$ext"]} {
|
|
|
|
lappend fset "$root.$ext"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $fset
|
|
|
|
}
|
|
|
|
|
2011-06-25 20:59:50 +00:00
|
|
|
proc {ts fetch} {file {checked 0}} {
|
|
|
|
# Check that this is a .ts file which has at least one sidecar
|
|
|
|
# file (.nts)
|
|
|
|
if {!$checked} {
|
|
|
|
if {[file extension $file] ne ".ts"} { return 0 }
|
|
|
|
if {![file exists "[file rootname $file].nts"]} { return 0 }
|
|
|
|
}
|
|
|
|
|
2011-06-16 03:10:41 +00:00
|
|
|
return [ts parse $file [ts exec $file]]
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method delete {} {
|
2012-08-07 22:22:30 +00:00
|
|
|
foreach f [$self fileset] {
|
2012-01-13 21:23:03 +00:00
|
|
|
tdelete $f
|
2011-06-16 23:49:48 +00:00
|
|
|
puts "Removed $f<br>"
|
|
|
|
}
|
2011-06-16 03:10:41 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2012-05-02 17:41:23 +00:00
|
|
|
ts method move {dst {touch 0} {force 0}} {
|
2012-08-07 22:22:30 +00:00
|
|
|
foreach f [$self fileset] {
|
2012-01-16 22:28:20 +00:00
|
|
|
set nf "$dst/[file tail $f]"
|
2012-05-02 17:41:23 +00:00
|
|
|
while {[file exists $nf]} {
|
|
|
|
set nf "$dst/_[file tail $nf]"
|
|
|
|
}
|
2012-01-16 22:28:20 +00:00
|
|
|
file rename $f $nf
|
|
|
|
if {$touch} {
|
|
|
|
exec /mod/bin/busybox/touch $nf
|
|
|
|
}
|
2012-01-10 19:51:45 +00:00
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method copy {dst} {
|
2012-08-07 22:22:30 +00:00
|
|
|
foreach f [$self fileset] {
|
2012-01-10 19:51:45 +00:00
|
|
|
file copy $f "$dst/[file tail $f]"
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2011-06-26 23:05:38 +00:00
|
|
|
ts method settitle {newtitle} {
|
|
|
|
if {[string length newtitle] > 48} { return }
|
|
|
|
|
|
|
|
exec /mod/bin/hmt "+settitle=${newtitle}" $file
|
|
|
|
}
|
|
|
|
|
2012-11-18 12:07:53 +00:00
|
|
|
ts method setsynopsis {newsynopsis} {
|
2013-02-09 22:46:15 +00:00
|
|
|
if {[string length newsynopsis] > 252} { return }
|
2012-11-18 12:07:53 +00:00
|
|
|
|
|
|
|
exec /mod/bin/hmt "+setsynopsis=${newsynopsis}" $file
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method setguidance {newguidance} {
|
|
|
|
if {[string length newguidance] > 48} { return }
|
|
|
|
|
2013-02-12 00:08:54 +00:00
|
|
|
if {$newguidance eq ""} {
|
|
|
|
exec /mod/bin/hmt "-guidance" $file
|
|
|
|
} else {
|
|
|
|
exec /mod/bin/hmt "+setguidance=${newguidance}" $file
|
|
|
|
}
|
2012-11-18 12:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 23:50:39 +00:00
|
|
|
ts method setgenre {newgenre} {
|
|
|
|
exec /mod/bin/hmt "+setgenre=-${newgenre}" $file
|
|
|
|
}
|
|
|
|
|
2012-11-05 21:57:29 +00:00
|
|
|
ts method dlnaloc {{urlbase 0}} {
|
2011-10-11 19:51:58 +00:00
|
|
|
set mime "video/ts"
|
|
|
|
if {![file exists $::dmsfile]} { return {} }
|
|
|
|
if {[catch {set db [sqlite3.open $::dmsfile]}]} { return {} }
|
|
|
|
set url ""
|
|
|
|
set rfile [file normalize $file]
|
2012-02-05 20:07:49 +00:00
|
|
|
if {[catch {set muri [$db query "
|
|
|
|
select tblresource.mimetype, contenturi
|
|
|
|
from tblresource join tblmedia using (mediaid)
|
|
|
|
where localurl = '%s'" $rfile]}]} {
|
|
|
|
set muri ""
|
|
|
|
}
|
2011-10-11 19:51:58 +00:00
|
|
|
if {$muri ne ""} {
|
|
|
|
set rec [lindex $muri 0]
|
|
|
|
set xuri [lindex $rec 3]
|
|
|
|
set mime [lindex $rec 1]
|
2012-11-05 21:57:29 +00:00
|
|
|
if {$urlbase ne "0"} {
|
|
|
|
set url "http://$urlbase:9000/web/$xuri"
|
|
|
|
} else {
|
|
|
|
set url "http://[system ip]:9000/web/$xuri"
|
|
|
|
}
|
2011-10-11 19:51:58 +00:00
|
|
|
}
|
|
|
|
$db close
|
|
|
|
|
|
|
|
if {$url ne "" } { return [list $url $mime] } else { return {} }
|
|
|
|
}
|
|
|
|
|
2013-03-11 23:00:41 +00:00
|
|
|
ts method cleanbmp {} {
|
|
|
|
set bfile [file rootname $file]
|
|
|
|
foreach f [glob -nocomplain "${bfile}*.bmp"] {
|
|
|
|
file delete $f
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method mkbmps {{offset 0}} {
|
|
|
|
set bfile [file rootname $file]
|
|
|
|
if {[catch {
|
|
|
|
exec /mod/bin/ffmpeg -loglevel fatal -ss $offset -i $file \
|
|
|
|
-vf fps=fps=2 -frames 5 \
|
|
|
|
-pix_fmt argb -vf vflip -s 140x78 "${bfile}%d.bmp"
|
|
|
|
} msg]} {
|
|
|
|
puts "ERROR: $msg"
|
|
|
|
return 0
|
2013-03-07 23:37:56 +00:00
|
|
|
}
|
2013-03-11 23:00:41 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method mkbmp {{offset 0} {ext ""}} {
|
2013-03-07 23:37:56 +00:00
|
|
|
set bfile [file rootname $file]
|
2013-03-11 23:00:41 +00:00
|
|
|
if {[catch {
|
|
|
|
exec /mod/bin/ffmpeg -loglevel fatal -ss $offset -i $file \
|
|
|
|
-frames 1 -pix_fmt argb -vf vflip -s 140x78 "$bfile$ext.bmp"
|
|
|
|
} msg]} {
|
|
|
|
puts "ERROR: $msg"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ts method mkthm {{offset 0}} {
|
|
|
|
if {![$self mkbmp $offset]} { return 0 }
|
|
|
|
set bfile [file rootname $file]
|
|
|
|
if {[catch {
|
|
|
|
exec /bin/dd if=$bfile.bmp of=$bfile.thm~ bs=54 skip=1
|
|
|
|
} msg]} {
|
|
|
|
puts "ERROR: $msg"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
exec /bin/echo -n " " >> $bfile.thm~
|
|
|
|
file rename -force $bfile.thm~ $bfile.thm
|
2013-03-07 23:37:56 +00:00
|
|
|
tdelete $bfile.bmp
|
2013-03-11 23:00:41 +00:00
|
|
|
return 1
|
2013-03-07 23:37:56 +00:00
|
|
|
}
|
|
|
|
|
2011-06-26 23:05:38 +00:00
|
|
|
proc {ts renamegroup} {from to} {
|
2012-08-07 22:22:30 +00:00
|
|
|
global tsgroup
|
|
|
|
|
2011-06-26 23:05:38 +00:00
|
|
|
set dir [file dirname $from]
|
|
|
|
set root [file rootname $from]
|
|
|
|
|
|
|
|
# Catch from string without a . character in it
|
|
|
|
if {$root eq $from} { return }
|
|
|
|
|
2012-08-07 22:22:30 +00:00
|
|
|
foreach ext $tsgroup {
|
|
|
|
set f "$root.$ext"
|
|
|
|
if {![file exists $f]} continue
|
2012-08-09 23:06:30 +00:00
|
|
|
file rename $f "${dir}/${to}.${ext}"
|
2011-06-26 23:05:38 +00:00
|
|
|
}
|
2011-10-31 13:47:47 +00:00
|
|
|
|
|
|
|
exec /mod/bin/hmt "+setfilename=$to" "${dir}/${to}.hmt"
|
|
|
|
|
|
|
|
set ndir [file normalize $dir]
|
|
|
|
|
|
|
|
if {![catch {set db [sqlite3.open $::dmsfile]}]} {
|
2012-02-05 22:49:27 +00:00
|
|
|
catch {
|
2011-10-31 13:47:47 +00:00
|
|
|
set x [lindex [$db query {select mediaid from tblMedia
|
|
|
|
where localUrl = '%s'} [file normalize $from]] 0]
|
|
|
|
lassign $x key mediaid
|
|
|
|
if {$mediaid ne ""} {
|
|
|
|
$db query {update tblMedia set localUrl = '%s'
|
|
|
|
where mediaid = %s} "${ndir}/{$to}.ts" $mediaid
|
|
|
|
$db query {update tblMedia set title = '%s'
|
|
|
|
where mediaid = %s} "{$to}.ts" $mediaid
|
|
|
|
}
|
2012-02-05 22:49:27 +00:00
|
|
|
}
|
2011-10-31 13:47:47 +00:00
|
|
|
$db close
|
|
|
|
}
|
2011-06-26 23:05:38 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 21:32:06 +00:00
|
|
|
proc {ts genrelist} {} {
|
|
|
|
return {
|
|
|
|
0 { Unclassified Unclassified }
|
|
|
|
16 { Film Movie }
|
|
|
|
32 { "News & Factual" News }
|
2013-01-08 22:43:43 +00:00
|
|
|
48 { Entertainment Special }
|
2013-01-07 21:32:06 +00:00
|
|
|
64 { Sport Sports }
|
|
|
|
80 { Children Children }
|
|
|
|
96 { Entertainment Special }
|
|
|
|
144 { Education Education }
|
|
|
|
160 { Lifestyle Leisure }
|
|
|
|
240 { Drama Show }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-11 22:13:36 +00:00
|
|
|
proc {ts resetnew} {dir} {
|
|
|
|
if {![file isdirectory $dir]} return
|
|
|
|
if {![file exists "$dir/.series"]} return
|
|
|
|
|
|
|
|
set tot 0
|
|
|
|
set watched 0
|
|
|
|
foreach file [readdir -nocomplain $dir] {
|
|
|
|
if {![string match {*.ts} $file]} { continue }
|
|
|
|
incr tot
|
|
|
|
if {[set ts [ts fetch "$dir/$file"]] != 0} {
|
|
|
|
if {![$ts flag "New"]} { incr watched }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set fd [open "$dir/.series"]
|
|
|
|
set bytes [read $fd]
|
|
|
|
close $fd
|
|
|
|
set recs [unpack $bytes -uintle 0 32]
|
|
|
|
set played [unpack $bytes -uintle 32 32]
|
|
|
|
|
|
|
|
#puts "Current: $played/$recs"
|
|
|
|
#hexdump $bytes
|
|
|
|
#puts "Calculated: $watched/$tot"
|
|
|
|
|
|
|
|
pack bytes $tot -intle 32 0
|
|
|
|
pack bytes $watched -intle 32 32
|
|
|
|
|
|
|
|
#hexdump $bytes
|
|
|
|
|
|
|
|
set fd [open "$dir/.series" "w"]
|
|
|
|
puts -nonewline $fd $bytes
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
|