2011-06-16 03:10:41 +00:00
|
|
|
|
2012-01-13 21:23:03 +00:00
|
|
|
if {![exists -proc class]} { package require oo }
|
|
|
|
source /mod/var/mongoose/lib/setup
|
|
|
|
require tdelete
|
2011-06-16 03:10:41 +00:00
|
|
|
|
2011-10-11 19:51:58 +00:00
|
|
|
set dmsfile /mnt/hd2/dms_cds.db
|
|
|
|
|
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
|
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 \
|
2011-12-27 18:43:40 +00:00
|
|
|
start end flags_list guidance bookmarks schedstart scheddur
|
2011-11-03 23:43:17 +00:00
|
|
|
|
|
|
|
set flags [split [string range $flags_list 0 end-1] ,]
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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]
|
|
|
|
}
|
|
|
|
|
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-01-10 19:51:45 +00:00
|
|
|
set root [file rootname $file]
|
|
|
|
# Protect special characters in root.
|
|
|
|
# In particular [] characters which are used a lot
|
|
|
|
# for torrent names.
|
|
|
|
regsub -all {([\\["$])} $root {\\\1} root
|
|
|
|
foreach f [glob -nocomplain "${root}.*"] {
|
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-01-16 22:28:20 +00:00
|
|
|
ts method move {dst {touch 0}} {
|
2012-01-10 19:51:45 +00:00
|
|
|
set root [file rootname $file]
|
|
|
|
regsub -all {([\\["$])} $root {\\\1} root
|
|
|
|
foreach f [glob -nocomplain "${root}.*"] {
|
2012-01-16 22:28:20 +00:00
|
|
|
set nf "$dst/[file tail $f]"
|
|
|
|
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} {
|
|
|
|
set root [file rootname $file]
|
|
|
|
regsub -all {([\\["$])} $root {\\\1} root
|
|
|
|
foreach f [glob -nocomplain "${root}.*"] {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-10-11 19:51:58 +00:00
|
|
|
ts method dlnaloc {} {
|
|
|
|
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]
|
|
|
|
set url "http://$::env(HTTP_HOST):9000/web/$xuri"
|
|
|
|
}
|
|
|
|
$db close
|
|
|
|
|
|
|
|
if {$url ne "" } { return [list $url $mime] } else { return {} }
|
|
|
|
}
|
|
|
|
|
2011-06-26 23:05:38 +00:00
|
|
|
proc {ts renamegroup} {from to} {
|
|
|
|
set dir [file dirname $from]
|
|
|
|
set root [file rootname $from]
|
|
|
|
|
|
|
|
# Catch from string without a . character in it
|
|
|
|
if {$root eq $from} { return }
|
|
|
|
|
|
|
|
# Protect special characters in root. In particular [] characters
|
|
|
|
# which are used a lot for torrent names.
|
|
|
|
regsub -all {([\\["$])} $root {\\\1} root
|
|
|
|
|
|
|
|
foreach f [glob -nocomplain "${root}.*"] {
|
|
|
|
set ext [file extension $f]
|
|
|
|
#puts "rename $f \"${dir}/${to}${ext}\""
|
|
|
|
file rename $f "${dir}/${to}${ext}"
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|