#!/mod/bin/jimsh package require cgi source /mod/var/mongoose/lib/setup require ts.class pretty_size system.class settings.class escape puts "Content-Type: text/html" puts "" set nicesplice [system pkginst nicesplice] set flatten [system pkginst flatten] set ignore {.nts .thm .hmt .hmi} set include {.ts .avi .mpg .mpeg .wmv .mkv .mp3 .mp4 .mov} cgi_input #cgi_dump if {![dict exists $env REQUEST_URI]} { set env(REQUEST_URI) "" set _cgi(dir) "/media/My Video/" } if {![dict exists $env QUERY_STRING]} { set env(QUERY_STRING) "root" } set order [cgi_get order -] if {$order eq "-"} { set order [[settings new] sortorder] } else { [settings new] sortorder $order } proc directory {file bfile} { global flatten regsub -all " +" $bfile "" tbfile puts "
" puts "" puts "" puts "" puts "$bfile " set noflat 0 if $flatten { if {[string match {\[*\]} [file tail $file]]} { set noflat 1 } if {[file exists "$file/.noflatten"]} { set noflat 1 } if $noflat { puts "\"No-flatten\"" } } puts -nonewline " " puts "
" puts "
" } proc entry {file} {{i 0}} { set bfile [file tail $file] if {[string index $bfile 0] == "\025"} { set bfile [string range $bfile 1 end] } if [file isdirectory "$file"] { directory $file $bfile continue } set ext [file extension $file] if {$ext in $::ignore || $ext ni $::include} { continue } file stat $file st set sz [pretty_size $st(size)] set base [file rootname $file] if {$ext eq ".ts" && [file exists "${base}.nts"]} { set type ts set ts [ts fetch $file 1] set img Video_TS } else { set type gen set ts 0 set img Video_Other } set new 0 if {$type eq "ts"} { if {[$ts flag "New"] > 0} { set new 1 } } else { if {![file exists "[file rootname $file].hmi"]} { set new 1 } } if {$new} { append img _New } set fscl "fs" if {$type eq "ts"} { set fscl "fs fsts" } puts "
$bfile " # Size puts " ($sz) " # Icons set locked 0 set encd 0 set odencd 1 set def unknown set bx 0 if {$type eq "ts"} { # HD / SD if {[$ts get definition] eq "HD"} { set def HD set img "172_1_00_HD" } else { set def SD set img "172_1_26_SD" } puts "" # Locked if {[$ts flag "Locked"] > 0} { set locked 1 puts "" } # Encrypted if {[$ts flag "Encrypted"] > 0} { set encd 1 puts "" } if {![$ts flag "ODEncrypted"]} { puts "" set odencd 0 } # Guidance if {[$ts flag "Guidance"] > 0} { puts "" } set bx [$ts get bookmarks] } # Opt+ button puts "
" puts "
" } set dir [cgi_get dir [system mediaroot]] ###################################################################### # Render web page header puts {
} puts "$dir" # Breadcrumb path puts "
" set stub "" foreach part [split $dir /] { if {$stub eq "/"} { set name $part } else { set name "/$part" } append stub $name puts "$name } puts "" puts "" # Parent directory set parent [join [lrange [split $dir /] 0 end-1] /] if {$parent ne ""} { puts "
\[parent directory\]
" } # Strip double slashes regsub -all -- {\/+} "$dir/*" "/" dir # Escape square brackets (for glob) regsub -all {([\\[])} $dir {\\\1} dir proc s_time {a b} { set ad [file isdirectory $a] set bd [file isdirectory $b] if {$ad && !$bd} { return -1 } if {$bd && !$ad} { return 1 } if {$ad && $bd} { if {$a < $b} { return -1 } if {$a > $b} { return 1 } return 0 } file stat $a l set at $l(ctime) file stat $b l set bt $l(ctime) if {$at < $bt} { return -1 } if {$at > $bt} { return 1 } return 0 } set files [glob -nocomplain $dir] switch $order { 1 { set files [lsort -command s_time $files] } default { set files [lsort $files] } } foreach file $files { entry $file } puts "Select all | none" # Sort icons puts "
" set sortlist {{0 sort_name name} {1 sort_date date}} foreach sl $sortlist { lassign $sl index img descr if {$index} { puts " | " } set tag "Currently sorting" if {$order != $index} { puts " " set tag "Sort" } puts " $tag by $descr" if {$order != $index} { puts "" } } puts "
" puts "
" puts "
" puts { } # Join if $nicesplice { puts { } } puts "
" # De-duplicate puts { } # Streamer file if {[file exists /mnt/hd3/Streamer_down_file]} { puts { } } puts "
" footer