1 import transcode
, os
, socket
, re
2 from Cheetah
.Template
import Template
3 from plugin
import Plugin
4 from urllib
import unquote_plus
, quote
, unquote
5 from urlparse
import urlparse
6 from xml
.sax
.saxutils
import escape
8 SCRIPTDIR
= os
.path
.dirname(__file__
)
12 content_type
= 'x-container/tivo-videos'
14 def SendFile(self
, handler
, container
, name
):
17 if handler
.headers
.getheader('Range') and not handler
.headers
.getheader('Range') == 'bytes=0-':
18 handler
.send_response(404)
22 o
= urlparse("http://fake.host" + handler
.path
)
23 path
= unquote_plus(o
.path
)
24 handler
.send_response(200)
26 transcode
.output_video(container
['path'] + path
[len(name
)+1:], handler
.wfile
)
28 def QueryContainer(self
, handler
, query
):
30 subcname
= query
['Container'][0]
31 cname
= subcname
.split('/')[0]
33 if not handler
.server
.containers
.has_key(cname
) or not self
.get_local_path(handler
, query
):
34 handler
.send_response(404)
38 path
= self
.get_local_path(handler
, query
)
40 return os
.path
.isdir(os
.path
.join(path
, file))
42 handler
.send_response(200)
44 t
= Template(file=os
.path
.join(SCRIPTDIR
,'templates', 'container.tmpl'))
46 t
.files
, t
.total
, t
.start
= self
.get_files(handler
, query
, lambda f
: os
.path
.isdir(os
.path
.join(path
, f
)) or transcode
.suported_format(os
.path
.join(path
,f
)) )
50 handler
.wfile
.write(t
)