Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/opt/bin/jimsh
- package require cgi
- source /opt/webif/lib/setup
- require ts.class pretty_size progressbar
- puts "Cache-Control: no-cache"
- puts "Content-Type: text/html"
- puts ""
- set ignore {.nts .thm .hmt .hmi}
- set include {.ts .avi .mpg .mpeg .wmv .mkv .mp3 .mp4 .mov .jpg}
- set playable {.ts .mp3}
- set ::NeedJavaRefresh 0
- cgi_input
- #cgi_dump
- #set _cgi(dir) "/media/Video"
- proc directory {file bfile} {
- regsub -all " +" $bfile "" tbfile
- if {$file eq "/media/opt"} {continue}
- if {$file eq "/media/Channels"} {continue}
- puts "<div class=\"va\">"
- puts "<img class=\"va\" id=\"img$tbfile\"
- src=\"/images/711_1_09_Media_Folder.png\" alt=\"\">"
- puts "<a class=\"dbf\"
- href=\"/cgi-bin/browse.jim?dir=[cgi_quote_url $file]\"
- file=\"[cgi_quote_url $file]\">"
- puts "$bfile</a><span class=\"filesize\" id=\"$tbfile\"></span>"
- # Enable folder delete and rename options on media folders and USB (including NASmounts) only
- if {([string first "/media/Video/" $file] != 0) &&
- ([string first "/media/Music/" $file] != 0) &&
- ([string first "/media/Photo/" $file] != 0) &&
- ([string first "/media/sda1/" $file] != 0) &&
- ([string first "/media/sdb1/" $file] != 0) &&
- ([string first "/media/sdc1/" $file] != 0)} {continue}
- puts "<a href=\"#\">
- <img class=\"dopt va\" width=\"45\" src=\"/images/181_1_00_Help5_OPT_Plus.png\" alt=\"\"></a>
- <div class=\"results blood\" style=\"margin: 0 0 0 5em\"></div>
- </div>"
- }
- 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 [string tolower [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]
- # Don't show the cache file (0.ts)
- if {$bfile eq "0.ts"} { continue }
- if {$ext eq ".ts" && [file exists "${base}.nts"]} {
- set type ts
- set ts [ts fetch $file 1]
- set img Video_TS
- } else {
- if {$ext eq ".mp3"} {
- set type mp3
- set ts 0
- set img Video_Other
- } else {
- if {$ext eq ".jpg"} {
- set type jpg
- set img Camera
- set ts 0
- } else {
- set type gen
- set ts 0
- set img Video_Other
- }
- }
- }
- # Determine whether the play button should be displayed
- # Only non encrypted ts files and mp3 files
- set player 0
- if {[file exists /opt/webif/plugin/vlcplayer/player.jim] && ($ext in $::playable)} {
- if {$ext eq ".ts" && [file exists "${base}.nts"] && [file exists "${base}.hmt"]} {
- if {[$ts flag "Encrypted"] == 0} {
- set player 1
- }
- } else {
- set player 1
- }
- }
- puts "
- <div class=\"va bf\" id=\"[incr i]\">
- <a class=\"bf\" file=\"$file\" player=\"$player\" type=\"$type\" href=\"#\">
- "
- 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 }
- puts "<img class=\"va\" src=\"/img/$img.png\" alt=\"\">"
- puts "
- $bfile
- </a>
- "
- # Size
- puts "<span class=\"filesize\"> ($sz) </span>"
- # Icons
- set locked 0
- set encd 0
- set prot 0
- set converted 0
- set def unknown
- 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 "<img class=\"va\" src=\"/images/$img.png\" height=\"21\" alt=\"\">"
- # Locked
- if {[$ts flag "Locked"] > 0} {
- set locked 1
- puts "<img class=\"va\" src=\"/images/178_1_00_Icon_Lock.png\"
- height=\"21\" alt=\"\">"
- }
- # Protected
- if {[$ts flag "Protected"] > 0} {
- set prot 1
- puts "<img class=\"va\" src=\"/images/norecycle_32.png\"
- height=\"21\" alt=\"\">"
- }
- # Encrypted
- if {[$ts flag "Encrypted"] > 0} {
- set encd 1
- puts "<img class=\"va\"
- src=\"/images/749_1_26_Video_Encryption.png\"
- height=\"21\" alt=\"\">"
- # Disable the OPT+ 'convert' option
- set converted 0
- }
- # Guidance
- if {[$ts flag "Guidance"] > 0} {
- puts "<img class=\"va\"
- src=\"/images/174_1_26_GuidancePolicy.png\"
- height=\"21\" alt=\"\">"
- }
- # New Flag
- if {[$ts flag "New"] > 0} {
- puts "<img class=\"va\"
- src=\"/images/New.png\"
- height=\"21\" alt=\"\">"
- }
- # File Conversion Flags
- # Don't show anything if file is unconverted
- # Show small progress bar if in progress or fully converted
- if {[$ts flag "Converting"] > 0} {
- # Default state is to assume that the file IS actually being converted so
- # disable the OPT+ option to convert
- set converted 1
- # But check becuase this could be a file conversion that terminated e.g. because of a HDR reboot
- # See if there's a lock file and if there is, whether it refers to this file
- # If there's no lock file or the lock file referes to a different file then this conversion
- # has terminated half way through so allow conversion
- set ReallyConverting 1
- set curFile ""
- if {![file exists "/tmp/convert-ts.lock"]} {
- set ReallyConverting 0
- } else {
- if {![catch {set lock_fd [open "/tmp/convert-ts.lock" r]}]} {
- set curFile [read $lock_fd]
- set curFile [string map {"/mnt/hd3/Video/" "/media/Video/"} $curFile]
- $lock_fd close
- }
- if {$curFile ne $file} {
- set ReallyConverting 0
- }
- }
- if {$ReallyConverting == 1} {
- set tmpfile ${base}.tmp
- if {[file exists $tmpfile]} {
- set perc [format %.1f [expr {100.0*[file size $file]/[file size $tmpfile]}]]
- set imgfile [format "%02.0f" [expr {$perc * 25 / 100 + 1}]]
- # Account for possible split second where file is fully converted but the HMT flag
- # has not yet been updated - so % complete = 100% and imgfile would be 26!
- if {$imgfile == "26"} {
- set imgfile "25"
- }
- set prefix 345_2_14_ST_HDD
- set ::NeedJavaRefresh 1
- puts " <input type=\"hidden\" id=\"RefreshFileName\" name=\"RefreshFileName\" value=\"$file\">
- <img id=\"RefreshImage\" style=\"background:url('/images/345_1_27_ST_USB_BG.png') no-repeat; background-size: 21px 21px\"
- src=\"/images/${prefix}_$imgfile.png\" alt=\"$perc%\" height=\"21\">
- <span id=\"RefreshSpan\" style=\"font-size: 80%; font-weight: bold;\">$perc%</span>
- "
- }
- } else {
- set converted 0
- }
- }
- if {[$ts flag "Converted"] > 0} {
- # Disable the OPT+ 'convert' option
- set converted 1
- puts "<img class=\"va\"
- src=\"/images/dlna.png\"
- height=\"21\" alt=\"\">"
- }
- }
- # Opt+ button
- puts "
- <a href=\"#\">
- <img class=\"opt va\" width=\"45\" src=\"/images/181_1_00_Help5_OPT_Plus.png\" alt=\"\"
- type=\"$type\" did=\"$i\" locked=\"$locked\" encd=\"$encd\" def=\"$def\" new=\"$new\" protected=\"$prot\" converted=\"$converted\">
- </a>
- <div class=\"results blood\" style=\"margin: 0 0 0 5em\"></div>
- "
- puts "</div>"
- }
- if {[dict exists $_cgi dir]} {
- set dir [dict get $_cgi dir]
- } else {
- set dir "/media/Video"
- }
- ######################################################################
- # Render web page
- header
- puts {
- <script type="text/javascript" src="/js/jquery.contextMenu.js"></script>
- <link href=/css/jquery.contextMenu.css rel=stylesheet type=text/css />
- <ul id=optmenu class=contextMenu>
- <li class="delete"><a href=#delete>Delete</a></li>
- <li class="lock"><a href=#lock>Toggle Lock</a></li>
- <li class="protect"><a href=#prot>Toggle Protected</a></li>
- <li class="new"><a href=#new>Toggle New</a></li>
- <li class="rename"><a href=#rename>Rename</a></li>
- <li class="download"><a href=#download>Download</a></li>
- }
- if {[file exists "/opt/bin/convert-ts"]} {
- puts {<li class="convert"><a href=#convert>Convert for Streaming</a></li>}
- }
- puts {</ul>}
- puts {
- <ul id=doptmenu class=contextMenu>
- <li class="delete"><a href=#delete>Delete</a></li>
- <li class="folder"><a href=#rename>Rename</a></li>
- </ul>
- }
- puts {
- <div id=renamefile title="Rename Media File" style="display: none">
- <form id="renamefile_form">
- <input type="hidden" name="origfname" id="origfname" value="">
- <input type="hidden" name="origtitle" id="origtitle" value="">
- <table style="border:0">
- <tr>
- <th>
- <label for="newfname">
- <b>New File Name</b>
- </label>
- </th>
- <td>
- <input type=text name="newfname" id="newfname"
- value="" size="70" maxlength="255"
- class="text ui-widget-content ui-corner-all">
- </td>
- </tr>
- <tr style="display: none" class=tstype>
- <th>
- <label for="newtitle" style="padding-top: 0.5em">
- <b>New EPG Title</b>
- </label>
- </th>
- <td>
- <input type=text name="newtitle" id="newtitle"
- value="" size="70" maxlength="250"
- class="text ui-widget-content ui-corner-all">
- </td>
- </tr>
- <tr style="display: none" class="tstype">
- <td colspan="2" id="synopsis" style="font-style: italic"></td>
- </tr>
- </table>
- </form>
- </div>
- <div id=renamedir title="Rename Media Folder" style="display: none">
- <form id="renamedir_form">
- <input type="hidden" name="origdname" id="origdname" value="">
- <table style="border:0">
- <tr>
- <th>
- <label for="newdname">
- <b>New Folder Name</b>
- </label>
- </th>
- <td>
- <input type=text name="newdname" id="newdname"
- value="" size="70" maxlength="255"
- class="text ui-widget-content ui-corner-all">
- </td>
- </tr>
- </table>
- <div id="renamedirout"><span class="footnote"></span></div>
- </form>
- </div>
- <div id="dialogue"></div>
- <div id="confirm" title="Confirmation Required"></div>
- <script type="text/javascript" src="/cgi-bin/browse/browse.js"></script>
- }
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- puts "<span style=\"display:none\" id=dir>$dir</span>"
- # Breadcrumb path
- puts "
- <fieldset style=\"margin: 1em\">
- <legend style=\"font-size: 1.5em; padding: 0 0.5em 0.5em 0.5em;\">
- "
- set stub ""
- foreach part [split $dir /] {
- if {$stub eq "/"} { set name $part } else { set name "/$part" }
- append stub $name
- puts "<a href=\"/cgi-bin/browse.jim?dir=[cgi_quote_url $stub]\">$name</a>
- }
- puts "<span class=\"filesize\" id=\"dirsize\"></span>"
- puts "</legend>"
- # Parent directory
- set parent [join [lrange [split $dir /] 0 end-1] /]
- if {$parent ne ""} {
- puts "
- <div class=\"va\">
- <a href=\"/cgi-bin/browse.jim?dir=[cgi_quote_url $parent]\">
- <img src=\"/images/711_3_09_Media_Folder_UP.png\" class=\"va\" alt=\"\">
- \[parent directory\]</a>
- </div>
- "
- }
- # Strip double slashes
- regsub -all -- {\/+} "$dir/*" "/" dir
- # Account for spaces in the path name
- regsub -all -- { +} "$dir" "\\ " dir
- foreach file [lsort [glob -nocomplain "$dir"]] {
- # Check for unicode characters in filename
- # Ignore if present
- if {[string is ascii -strict $file] == 1} {
- entry $file
- }
- }
- puts "</fieldset>"
- if {$::NeedJavaRefresh == 1} {
- puts {
- <script langauge="javascript">
- window.setInterval("refreshDiv()", 2500);
- function refreshDiv(){
- var fname = document.getElementById("RefreshFileName").value;
- var http = new XMLHttpRequest();
- var url = '/cgi-bin/browse/convertprogress.jim?file=' + encodeURIComponent(fname);
- http.open('GET', url, false);
- http.send();
- var resptext = http.responseText.trim();
- var respsplit = resptext.split("|");
- var perc = respsplit[0];
- var imgsrc = respsplit[1];
- if (imgsrc == '/images/345_2_14_ST_HDD_26.png') {
- // No more refreshing - file is converted - reload screen
- document.location.reload();
- } else {
- $("#RefreshImage").attr('src', imgsrc);
- $("#RefreshSpan").html(perc + '%');
- }
- }
- </script>
- }
- }
- footer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement