2011-06-16 03:10:41 +00:00
|
|
|
|
2011-07-01 22:56:53 +00:00
|
|
|
if {![exists -proc class ]} { package require oo }
|
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-06-16 03:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ts method duration {} {
|
|
|
|
return [expr [expr $end - $start] / 60]
|
|
|
|
}
|
|
|
|
|
|
|
|
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"]
|
|
|
|
|
|
|
|
set title [lindex $vars 0]
|
|
|
|
set synopsis [lindex $vars 1]
|
|
|
|
set definition [lindex $vars 2]
|
|
|
|
set channel_num [lindex $vars 3]
|
|
|
|
set channel_name [lindex $vars 4]
|
|
|
|
set start [lindex $vars 5]
|
|
|
|
set end [lindex $vars 6]
|
|
|
|
set flags [split [string range [lindex $vars 7] 0 end-1] ,]
|
2011-06-27 19:57:32 +00:00
|
|
|
set guidance [lindex $vars 8]
|
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 {} {
|
2011-06-16 23:49:48 +00:00
|
|
|
# Extract file basename
|
|
|
|
foreach f [glob -nocomplain "[file rootname $file].*"] {
|
|
|
|
puts "Removed $f<br>"
|
|
|
|
file delete $f
|
|
|
|
}
|
2011-06-16 03:10:41 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|