#!/mod/bin/jimsh package require cgi source /mod/webif/lib/setup require ts.class pretty_size system.class settings.class escape browse.class jqplugin contextMenu bar enadis jscss script.js style.css header set nicesplice [system pkginst nicesplice] set flatten [system pkginst flatten] set ignore {.nts .thm .hmi} set include {.ts .avi .mpg .mpeg .wmv .mkv .mp3 .mp4 .mov .hmt} if {![dict exists $env REQUEST_URI]} { set env(REQUEST_URI) "" cgi_input set _cgi(dir) "/media/My Video/" } if {![dict exists $env QUERY_STRING]} { set env(QUERY_STRING) "root" } set config [settings new] set order [cgi_get order -] if {$order eq "-"} { set order [$config sortorder] } else { $config sortorder $order } set nofcount [$config nounwatchedcount] set model [system model] set dustbin [system dustbin 1] proc icon {img {hover ""} {extra ""} {class "va"}} { puts -nonewline "\"$hover\"" } proc directory {file bfile tbfile} { puts "
" set img "/images/711_1_09_Media_Folder.png" if {$bfile eq $::dustbin} { set img "/img/Dustbin_Folder.png" } puts "" if {!$::nofcount} { puts "" } puts "" puts "" puts "$bfile " lassign [{dir iconset} $file] icons attrs puts "" puts [join $icons ""] puts "" if {[string first $::mroot $file] >= 0} { set class dopt } else { set class doopt } puts -nonewline " " puts "
" puts "
" } set dircount 0 set filecount 0 proc entry {file} {{i 0}} { global dircount filecount set bfile [file tail $file] regsub -all " +" $bfile "" tbfile if {[string index $bfile 0] == "\025"} { set bfile [string range $bfile 1 end] } if [file isdirectory "$file"] { incr dircount directory $file $bfile $tbfile return } set ext [string tolower [file extension $file]] if {$ext in $::ignore || $ext ni $::include} { return } file stat $file st set rsz $st(size) set sz [pretty_size $rsz] set base [file rootname $file] set thmok 0 if {$ext eq ".ts" && [file exists "${base}.nts"]} { set type ts set ts [ts fetch $file 1] set img Video_TS set omenu opt if {[file exists "${base}.thm"]} { set thmok 1 } } elseif {$ext eq ".hmt"} { if {[file exists "${base}.ts"]} { continue } # Sole hmt file indicates failure to track. set type bad set ts 0 set img Video_Failed set omenu oopt } else { set type gen set ts 0 set img Video_Other set omenu oopt } incr filecount set new 0 if {$type eq "ts"} { if {[$ts flag "New"] > 0} { set new 1 } } elseif {$type eq "gen"} { if {![file exists "${base}.hmi"]} { set new 1 } } if {$new} { append img _New } set fscl "fs" set synopsis "" if {$type eq "ts"} { set fscl "fs fsts" set synopsis [cgi_quote_html [$ts get synopsis]] } puts "
$bfile " # Size puts " ($sz) " # Icons set locked 0 set encd 0 set odencd 1 set def unknown set bx 0 set dlna 0 set shrunk 0 if {$type eq "ts"} { set genre [$ts get genre] set glist [ts genrelist] if {[dict exists $glist $genre]} { set ret $glist($genre) } else { set ret $glist(0) } lassign $ret txt img if {$img eq "Unclassified"} { icon "/images/173_3_26_G3_$img.png" $txt "" "va genre" } else { icon "/images/173_3_00_G3_$img.png" $txt "" "va genre" } # 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" } icon "/images/$img.png" # Locked if {[$ts flag "Locked"] > 0} { set locked 1 icon "/images/178_1_00_Icon_Lock.png" "Locked" } # Encrypted if {[$ts flag "Encrypted"] > 0} { set encd 1 icon "/images/749_1_26_Video_Encryption.png" "" } if {![$ts flag "ODEncrypted"]} { set odencd 0 icon "/img/Decrypted.png" "Decrypted" } # Guidance if {[$ts flag "Guidance"] > 0} { icon "/images/174_1_26_GuidancePolicy.png" } # Indexed if {$::model eq "HDR" && [llength [$ts dlnaloc]]} { icon "/img/dlna.png" "Indexed by DLNA Server" set dlna 1 } # Shrunk if {[$ts flag Shrunk]} { icon "/img/compress.png" "Shrunk" set shrunk 1 } set bx [$ts get bookmarks] } # Opt+ button puts "
" puts "
" } set mroot [system mediaroot] set dir [cgi_get dir $mroot] ###################################################################### # Render web page source assets.jim puts " $dir $mroot
" # Breadcrumb path 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\]
" } proc s_time {a b} { global dir set a "$dir/$a" set b "$dir/$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 } if {[catch {file stat $a l}]} { return 0} set at $l(mtime) if {[catch {file stat $b l}]} { return 0} set bt $l(mtime) if {$at < $bt} { return -1 } if {$at > $bt} { return 1 } return 0 } set files [readdir -nocomplain $dir] switch $order { 1 { set files [lsort -command s_time $files] } default { set files [lsort -nocase $files] } } foreach file $files { entry "$dir/$file" } puts " Select all | none    Directories: $dircount, Files: $filecount " # 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 {
File Clipboard
Loading...
} puts "
" puts { } # Join if $nicesplice { puts { } } puts "
" # De-duplicate puts { } # Streamer file if {[file exists /mnt/hd3/Streamer_down_file]} { puts { } } puts "
" footer