#!/mod/bin/jimsh

package require cgi
source /mod/var/mongoose/lib/setup
require ts.class pretty_size

puts "Content-Type: text/html\r\n"

cgi_input
#cgi_dump

header

set rfile [cgi_get file]
set ts [ts fetch $rfile]
if {[catch {$ts get file}]} {
	puts "Invalid TS file, '$rfile'"
	exit
}

if {![$ts flag "ODEncrypted"]} {
	set url $rfile
} else {
	lassign [$ts dlnaloc] url
	if {$url eq ""} {
		alert("Media is encrypted and not indexed by the DLNA Server.");
	}
}

puts "
<span id=url style=\"display: none\">$url</span>
"

puts {
<script language="javascript" src="/js/jquery-vlc.js"></script>
<link rel="stylesheet" type="text/css" href="/css/vlc.css" />
<script type=text/javascript src=play.js></script>

<fieldset class=cleft style="margin: 0 1em 1em 1em">
<legend>VLC Player</legend>
}
puts "<span class=also>Now playing: $rfile, [$ts duration] minutes.</span>"
puts {
<div id=vlc></div>

<div class=also id=info style="float: right">
</div>

</fieldset>
}

