本文整理汇总了Python中Cheetah.Template.Template.container方法的典型用法代码示例。如果您正苦于以下问题:Python Template.container方法的具体用法?Python Template.container怎么用?Python Template.container使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cheetah.Template.Template
的用法示例。
在下文中一共展示了Template.container方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Settings
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def Settings(self, handler, query):
# Read config file new each time in case there was any outside edits
config.reset()
shares_data = []
for section in config.config.sections():
if not section.startswith(('_tivo_', 'Server')):
if (not (config.config.has_option(section, 'type')) or
config.config.get(section, 'type').lower() not in
['settings', 'togo']):
shares_data.append((section,
dict(config.config.items(section,
raw=True))))
t = Template(SETTINGS_TEMPLATE, filter=EncodeUnicode)
t.mode = buildhelp.mode
t.options = buildhelp.options
t.container = handler.cname
t.quote = quote
t.server_data = dict(config.config.items('Server', raw=True))
t.server_known = buildhelp.getknown('server')
t.hd_tivos_data = dict(config.config.items('_tivo_HD', raw=True))
t.hd_tivos_known = buildhelp.getknown('hd_tivos')
t.sd_tivos_data = dict(config.config.items('_tivo_SD', raw=True))
t.sd_tivos_known = buildhelp.getknown('sd_tivos')
t.shares_data = shares_data
t.shares_known = buildhelp.getknown('shares')
t.tivos_data = [(section, dict(config.config.items(section, raw=True)))
for section in config.config.sections()
if section.startswith('_tivo_')
and not section.startswith(('_tivo_SD', '_tivo_HD'))]
t.tivos_known = buildhelp.getknown('tivos')
t.help_list = buildhelp.gethelp()
t.has_shutdown = hasattr(handler.server, 'shutdown')
handler.send_html(str(t))
示例2: Admin
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def Admin(self, handler, query):
#Read config file new each time in case there was any outside edits
config = ConfigParser.ConfigParser()
config.read(config_file_path)
shares_data = []
for section in config.sections():
if not(section.startswith('_tivo_') or section.startswith('Server')):
if not(config.has_option(section,'type')):
shares_data.append((section, dict(config.items(section, raw=True))))
elif config.get(section,'type').lower() != 'admin':
shares_data.append((section, dict(config.items(section, raw=True))))
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'settings.tmpl'))
t.container = cname
t.server_data = dict(config.items('Server', raw=True))
t.server_known = buildhelp.getknown('server')
t.shares_data = shares_data
t.shares_known = buildhelp.getknown('shares')
t.tivos_data = [ (section, dict(config.items(section, raw=True))) for section in config.sections() \
if section.startswith('_tivo_')]
t.tivos_known = buildhelp.getknown('tivos')
t.help_list = buildhelp.gethelp()
handler.wfile.write(t)
示例3: ToGo
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def ToGo(self, handler, query):
subcname = query['Container'][0]
cname = subcname.split('/')[0]
for name, data in config.getShares():
if cname == name:
if 'tivo_mak' in data:
tivo_mak = data['tivo_mak']
else:
tivo_mak = ""
if 'togo_path' in data:
togo_path = data['togo_path']
else:
togo_path = ""
if tivo_mak != "" and togo_path != "":
parse_url = urlparse(str(query['Url'][0]))
theurl = 'http://' + parse_url[1].split(':')[0] + parse_url[2] + "?" + parse_url[4]
password = tivo_mak #TiVo MAK
tivoIP = query['TiVo'][0]
name = unquote(parse_url[2])[10:300].split('.')
name.insert(-1," - " + unquote(parse_url[4]).split("id=")[1] + ".")
outfile = os.path.join(togo_path, "".join(name))
status[theurl] = {'running':True, 'error':'', 'rate':'', 'finished':False}
thread.start_new_thread(Admin.get_tivo_file, (self, theurl, password, tivoIP, outfile))
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '3'
t.url = '/'+ query['Redirect'][0]
t.text = '<h3>Transfer Initiated.</h3> <br>You selected transfer has been initiated.'+\
'<br> The <a href="/'+ query['Redirect'][0] +'"> ToGo</a> page will reload in 3 seconds.'
handler.wfile.write(t)
else:
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '10'
t.url = '/'+ query['Redirect'][0]
t.text = '<h3>Missing Data.</h3> <br>You must set both "tivo_mak" and "togo_path" before using this function.'+\
'<br> The <a href="/'+ query['Redirect'][0] +'"> ToGo</a> page will reload in 10 seconds.'
handler.wfile.write(t)
示例4: QueryContainer
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def QueryContainer(self, handler, query):
# Reject a malformed request -- these attributes should only
# appear in requests to send_file, but sometimes appear here
badattrs = ('Rotation', 'Width', 'Height', 'PixelShape')
for i in badattrs:
if i in query:
handler.send_error(404)
return
subcname = query['Container'][0]
cname = subcname.split('/')[0]
local_base_path = self.get_local_base_path(handler, query)
if not handler.server.containers.has_key(cname) or \
not self.get_local_path(handler, query):
handler.send_error(404)
return
def ImageFileFilter(f):
goodexts = ('.jpg', '.gif', '.png', '.bmp', '.tif', '.xbm',
'.xpm', '.pgm', '.pbm', '.ppm', '.pcx', '.tga',
'.fpx', '.ico', '.pcd', '.jpeg', '.tiff')
return os.path.splitext(f)[1].lower() in goodexts
def media_data(f):
if f.name in self.media_data_cache:
return self.media_data_cache[f.name]
item = {}
item['path'] = f.name
item['part_path'] = f.name.replace(local_base_path, '', 1)
item['name'] = os.path.split(f.name)[1]
item['is_dir'] = f.isdir
item['rotation'] = 0
item['cdate'] = '%#x' % f.cdate
item['mdate'] = '%#x' % f.mdate
self.media_data_cache[f.name] = item
return item
t = Template(photo_template, filter=EncodeUnicode)
t.name = subcname
t.container = cname
t.files, t.total, t.start = self.get_files(handler, query,
ImageFileFilter)
t.files = map(media_data, t.files)
t.quote = quote
t.escape = escape
page = str(t)
handler.send_response(200)
handler.send_header('Content-Type', 'text/xml')
handler.send_header('Content-Length', len(page))
handler.send_header('Connection', 'close')
handler.end_headers()
handler.wfile.write(page)
示例5: QueryContainer
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def QueryContainer(self, handler, query):
# Reject a malformed request -- these attributes should only
# appear in requests to send_file, but sometimes appear here
badattrs = ('Rotation', 'Width', 'Height', 'PixelShape')
for i in badattrs:
if i in query:
handler.send_error(404)
return
local_base_path = self.get_local_base_path(handler, query)
if not self.get_local_path(handler, query):
handler.send_error(404)
return
def ImageFileFilter(f):
goodexts = ('.jpg', '.gif', '.png', '.bmp', '.tif', '.xbm',
'.xpm', '.pgm', '.pbm', '.ppm', '.pcx', '.tga',
'.fpx', '.ico', '.pcd', '.jpeg', '.tiff', '.nef')
return os.path.splitext(f)[1].lower() in goodexts
def media_data(f):
if f.name in self.media_data_cache:
return self.media_data_cache[f.name]
item = {}
item['path'] = f.name
item['part_path'] = f.name.replace(local_base_path, '', 1)
item['name'] = os.path.basename(f.name)
item['is_dir'] = f.isdir
item['rotation'] = 0
item['cdate'] = '%#x' % f.cdate
item['mdate'] = '%#x' % f.mdate
self.media_data_cache[f.name] = item
return item
t = Template(PHOTO_TEMPLATE, filter=EncodeUnicode)
t.name = query['Container'][0]
t.container = handler.cname
t.files, t.total, t.start = self.get_files(handler, query,
ImageFileFilter)
t.files = map(media_data, t.files)
t.quote = quote
t.escape = escape
handler.send_xml(str(t))
示例6: Settings
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def Settings(self, handler, query):
# Read config file new each time in case there was any outside edits
config.reset()
shares_data = []
for section in config.config.sections():
if not (section.startswith('_tivo_')
or section.startswith('Server')):
if (not (config.config.has_option(section, 'type')) or
config.config.get(section, 'type').lower() not in
['settings', 'togo']):
shares_data.append((section,
dict(config.config.items(section,
raw=True))))
cname = query['Container'][0].split('/')[0]
t = Template(SETTINGS_TEMPLATE, filter=EncodeUnicode)
t.container = cname
t.quote = quote
t.server_data = dict(config.config.items('Server', raw=True))
t.server_known = buildhelp.getknown('server')
if config.config.has_section('_tivo_HD'):
t.hd_tivos_data = dict(config.config.items('_tivo_HD', raw=True))
else:
t.hd_tivos_data = {}
t.hd_tivos_known = buildhelp.getknown('hd_tivos')
if config.config.has_section('_tivo_SD'):
t.sd_tivos_data = dict(config.config.items('_tivo_SD', raw=True))
else:
t.sd_tivos_data = {}
t.sd_tivos_known = buildhelp.getknown('sd_tivos')
t.shares_data = shares_data
t.shares_known = buildhelp.getknown('shares')
t.tivos_data = [(section, dict(config.config.items(section, raw=True)))
for section in config.config.sections()
if section.startswith('_tivo_')
and not section.startswith('_tivo_SD')
and not section.startswith('_tivo_HD')]
t.tivos_known = buildhelp.getknown('tivos')
t.help_list = buildhelp.gethelp()
t.has_shutdown = hasattr(handler.server, 'shutdown')
handler.send_response(200)
handler.send_header('Content-Type', 'text/html; charset=utf-8')
handler.send_header('Expires', '0')
handler.end_headers()
handler.wfile.write(t)
示例7: ToGoStop
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def ToGoStop(self, handler, query):
parse_url = urlparse(str(query['Url'][0]))
theurl = 'http://' + parse_url[1].split(':')[0] + parse_url[2] + "?" + parse_url[4]
status[theurl]['running'] = False
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '3'
t.url = '/'+ query['Redirect'][0]
t.text = '<h3>Transfer Stopped.</h3> <br>Your transfer has been stopped.'+\
'<br> The <a href="/'+ query['Redirect'][0] +'"> ToGo</a> page will reload in 3 seconds.'
handler.wfile.write(t)
示例8: Reset
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def Reset(self, handler, query):
config.reset()
handler.server.reset()
if 'last_page' in query:
last_page = query['last_page'][0]
else:
last_page = 'Admin'
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '3'
t.url = '/TiVoConnect?Command='+ last_page +'&Container=' + cname
t.text = '<h3>The pyTivo Server has been soft reset.</h3> <br>pyTivo has reloaded the pyTivo.conf'+\
'file and all changed should now be in effect. <br> The'+ \
'<a href="/TiVoConnect?Command='+ last_page +'&Container='+ cname +'"> previous</a> page will reload in 3 seconds.'
handler.wfile.write(t)
debug.debug_write(__name__, debug.fn_attr(), ['The pyTivo Server has been soft reset.'])
debug.print_conf(__name__, debug.fn_attr())
示例9: SaveNPL
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def SaveNPL(self, handler, query):
config = ConfigParser.ConfigParser()
config.read(config_file_path)
if 'tivo_mak' in query:
config.set(query['Container'][0], 'tivo_mak', query['tivo_mak'][0])
if 'togo_path' in query:
config.set(query['Container'][0], 'togo_path', query['togo_path'][0])
f = open(config_file_path, "w")
config.write(f)
f.close()
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '2'
t.url = '/TiVoConnect?last_page=NPL&Command=Reset&Container=' + cname
t.text = '<h3>Your Settings have been saved.</h3> <br>You settings have been saved to the pyTivo.conf file.'+\
'pyTivo will now do a <b>Soft Reset</b> to allow these changes to take effect.'+\
'<br> The <a href="/TiVoConnect?last_page=NPL&Command=Reset&Container='+ cname +'"> Reset</a> will occur in 2 seconds.'
handler.wfile.write(t)
示例10: QueryContainer
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def QueryContainer(self, handler, query):
tsn = handler.headers.getheader("tsn", "")
subcname = query["Container"][0]
if not self.get_local_path(handler, query):
handler.send_error(404)
return
container = handler.container
force_alpha = container.get("force_alpha", "False").lower() == "true"
use_html = query.get("Format", [""])[0].lower() == "text/html"
files, total, start = self.get_files(handler, query, self.video_file_filter, force_alpha)
videos = []
local_base_path = self.get_local_base_path(handler, query)
for f in files:
video = VideoDetails()
mtime = f.mdate
try:
ltime = time.localtime(mtime)
except:
logger.warning("Bad file time on " + unicode(f.name, "utf-8"))
mtime = int(time.time())
ltime = time.localtime(mtime)
video["captureDate"] = hex(mtime)
video["textDate"] = time.strftime("%b %d, %Y", ltime)
video["name"] = os.path.basename(f.name)
video["path"] = f.name
video["part_path"] = f.name.replace(local_base_path, "", 1)
if not video["part_path"].startswith(os.path.sep):
video["part_path"] = os.path.sep + video["part_path"]
video["title"] = os.path.basename(f.name)
video["is_dir"] = f.isdir
if video["is_dir"]:
video["small_path"] = subcname + "/" + video["name"]
video["total_items"] = self.__total_items(f.name)
else:
if len(files) == 1 or f.name in transcode.info_cache:
video["valid"] = transcode.supported_format(f.name)
if video["valid"]:
video.update(self.metadata_full(f.name, tsn))
if len(files) == 1:
video["captureDate"] = hex(isogm(video["time"]))
else:
video["valid"] = True
video.update(metadata.basic(f.name))
if self.use_ts(tsn, f.name):
video["mime"] = "video/x-tivo-mpeg-ts"
else:
video["mime"] = "video/x-tivo-mpeg"
video["textSize"] = "%.3f GB" % (float(f.size) / (1024 ** 3))
videos.append(video)
if use_html:
t = Template(HTML_CONTAINER_TEMPLATE, filter=EncodeUnicode)
else:
t = Template(XML_CONTAINER_TEMPLATE, filter=EncodeUnicode)
t.container = handler.cname
t.name = subcname
t.total = total
t.start = start
t.videos = videos
t.quote = quote
t.escape = escape
t.crc = zlib.crc32
t.guid = config.getGUID()
t.tivos = config.tivos
t.tivo_names = config.tivo_names
if use_html:
handler.send_html(str(t))
else:
handler.send_xml(str(t))
示例11: QueryContainer
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def QueryContainer(self, handler, query):
tsn = handler.headers.getheader('tsn', '')
subcname = query['Container'][0]
cname = subcname.split('/')[0]
if (not cname in handler.server.containers or
not self.get_local_path(handler, query)):
handler.send_error(404)
return
container = handler.server.containers[cname]
precache = container.get('precache', 'False').lower() == 'true'
force_alpha = container.get('force_alpha', 'False').lower() == 'true'
files, total, start = self.get_files(handler, query,
self.video_file_filter,
force_alpha)
videos = []
local_base_path = self.get_local_base_path(handler, query)
for f in files:
video = VideoDetails()
mtime = f.mdate
try:
ltime = time.localtime(mtime)
except:
logger.warning('Bad file time on ' + unicode(f.name, 'utf-8'))
mtime = int(time.time())
ltime = time.localtime(mtime)
video['captureDate'] = hex(mtime)
video['textDate'] = time.strftime('%b %d, %Y', ltime)
video['name'] = os.path.split(f.name)[1]
video['path'] = f.name
video['part_path'] = f.name.replace(local_base_path, '', 1)
if not video['part_path'].startswith(os.path.sep):
video['part_path'] = os.path.sep + video['part_path']
video['title'] = os.path.split(f.name)[1]
video['is_dir'] = f.isdir
if video['is_dir']:
video['small_path'] = subcname + '/' + video['name']
video['total_items'] = self.__total_items(f.name)
else:
if precache or len(files) == 1 or f.name in transcode.info_cache:
video['valid'] = transcode.supported_format(f.name)
if video['valid']:
video.update(self.metadata_full(f.name, tsn))
else:
video['valid'] = True
video.update(metadata.basic(f.name))
video['textSize'] = ( '%.3f GB' %
(float(f.size) / (1024 ** 3)) )
videos.append(video)
t = Template(CONTAINER_TEMPLATE, filter=EncodeUnicode)
t.container = cname
t.name = subcname
t.total = total
t.start = start
t.videos = videos
t.quote = quote
t.escape = escape
t.crc = zlib.crc32
t.guid = config.getGUID()
t.tivos = config.tivos
t.tivo_names = config.tivo_names
handler.send_response(200)
handler.send_header('Content-Type', 'text/xml')
handler.send_header('Expires', '0')
handler.end_headers()
handler.wfile.write(t)
示例12: NPL
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def NPL(self, handler, query):
shows_per_page = 50 #Change this to alter the number of shows returned per page
subcname = query['Container'][0]
cname = subcname.split('/')[0]
folder = ''
AnchorItem = ''
AnchorOffset= ''
for name, data in config.getShares():
if cname == name:
if 'tivo_mak' in data:
tivo_mak = data['tivo_mak']
else:
tivo_mak = ""
if 'togo_path' in data:
togo_path = data['togo_path']
else:
togo_path = ""
if 'TiVo' in query:
tivoIP = query['TiVo'][0]
theurl = 'https://'+ tivoIP +'/TiVoConnect?Command=QueryContainer&ItemCount='+ str(shows_per_page) +'&Container=/NowPlaying'
if 'Folder' in query:
folder += str(query['Folder'][0])
theurl += '/' + folder
if 'AnchorItem' in query:
AnchorItem += str(query['AnchorItem'][0])
theurl += '&AnchorItem=' + quote(AnchorItem)
if 'AnchorOffset' in query:
AnchorOffset += str(query['AnchorOffset'][0])
theurl += '&AnchorOffset=' + AnchorOffset
password = tivo_mak #TiVo MAK
r=urllib2.Request(theurl)
auth_handler = urllib2.HTTPDigestAuthHandler()
auth_handler.add_password('TiVo DVR', tivoIP, 'tivo', password)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
if theurl in tivo_cache: #check to see if we have accessed this page before
if tivo_cache[theurl]['thepage'] == '' or (time.time() - tivo_cache[theurl]['thepage_time']) >= 60: #if page is empty or old then retreive it
try:
handle = urllib2.urlopen(r)
except IOError, e:
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '20'
t.url = '/TiVoConnect?Command=NPL&Container=' + cname
t.text = '<h3>Unable to Connect to TiVo.</h3> <br>pyTivo was unable to connect to the TiVo at ' + tivoIP +\
'<br>This most likely caused by an incorrect Media Access Key. Please return to the ToGo page and double check your Media Access Key.' +\
'<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '"> ToGo</a> page will reload in 20 seconds.'
handler.wfile.write(t)
return
tivo_cache[theurl]['thepage'] = handle.read()
tivo_cache[theurl]['thepage_time'] = time.time()
else: #not in cache
try:
handle = urllib2.urlopen(r)
except IOError, e:
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '20'
t.url = '/TiVoConnect?Command=NPL&Container=' + cname
t.text = '<h3>Unable to Connect to TiVo.</h3> <br>pyTivo was unable to connect to the TiVo at ' + tivoIP +\
'<br>This most likely caused by an incorrect Media Access Key. Please return to the ToGo page and double check your Media Access Key.' +\
'<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '"> ToGo</a> page will reload in 20 seconds.'
handler.wfile.write(t)
return
tivo_cache[theurl] = {}
tivo_cache[theurl]['thepage'] = handle.read()
tivo_cache[theurl]['thepage_time'] = time.time()
示例13: QueryContainer
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
#.........这里部分代码省略.........
#if track[0].isdigit:
# track = ' '.join(track.split(' ')[1:])
#item['SongTitle'] = track
#item['AlbumTitle'] = album
#item['ArtistName'] = artist
ext = os.path.splitext(f.name)[1].lower()
fname = f.name
try:
# If the file is an mp3, let's load the EasyID3 interface
if ext == '.mp3':
audioFile = MP3(fname, ID3=EasyID3)
else:
# Otherwise, let mutagen figure it out
audioFile = mutagen.File(fname)
if audioFile:
# Pull the length from the FileType, if present
if audioFile.info.length > 0:
item['Duration'] = int(audioFile.info.length * 1000)
# Grab our other tags, if present
def get_tag(tagname, d):
for tag in ([tagname] + TAGNAMES[tagname]):
try:
if tag in d:
value = d[tag][0]
if not isinstance(value, str):
value = str(value)
return value
except:
pass
return ''
artist = get_tag('artist', audioFile)
title = get_tag('title', audioFile)
if artist == 'Various Artists' and '/' in title:
artist, title = [x.strip() for x in title.split('/')]
item['ArtistName'] = artist
item['SongTitle'] = title
item['AlbumTitle'] = get_tag('album', audioFile)
item['AlbumYear'] = get_tag('date', audioFile)[:4]
item['MusicGenre'] = get_tag('genre', audioFile)
except Exception as msg:
logger.error(msg)
ffmpeg_path = config.get_bin('ffmpeg')
if 'Duration' not in item and ffmpeg_path:
cmd = [ffmpeg_path, '-hide_banner', '-nostdin', '-i', fname]
ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
# wait 10 sec if ffmpeg is not back give up
for i in range(200):
time.sleep(.05)
if not ffmpeg.poll() == None:
break
if ffmpeg.poll() != None:
output = ffmpeg.stderr.read()
d = durre(output)
if d:
millisecs = ((int(d.group(1)) * 3600 +
int(d.group(2)) * 60 +
int(d.group(3))) * 1000 +
int(d.group(4)) *
(10 ** (3 - len(d.group(4)))))
else:
millisecs = 0
item['Duration'] = millisecs
if 'Duration' in item and ffmpeg_path:
item['params'] = 'Yes'
self.media_data_cache[f.name] = item
return item
subcname = query['Container'][0]
local_base_path = self.get_local_base_path(handler, query)
if not self.get_local_path(handler, query):
handler.send_error(404)
return
if os.path.splitext(subcname)[1].lower() in PLAYLISTS:
t = Template(PLAYLIST_TEMPLATE)
t.files, t.total, t.start = self.get_playlist(handler, query)
else:
t = Template(FOLDER_TEMPLATE)
t.files, t.total, t.start = self.get_files(handler, query,
AudioFileFilter)
t.files = list(map(media_data, t.files))
t.container = handler.cname
t.name = subcname
t.quote = quote
t.escape = escape
handler.send_xml(str(t))
示例14: Template
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
ItemCount = 0
FirstAnchor = ''
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.send_header('Content-Type', 'text/html; charset=UTF-8')
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'npl.tmpl'))
t.folder = folder
t.status = status
t.tivo_mak = tivo_mak
t.togo_path = togo_path
t.tivos = handler.tivos
t.tivoIP = tivoIP
t.container = cname
t.data = data
t.unquote = unquote
t.len = len
t.TotalItems = int(TotalItems)
t.ItemStart = int(ItemStart)
t.ItemCount = int(ItemCount)
t.FirstAnchor = quote(FirstAnchor)
t.shows_per_page = shows_per_page
t.redirect = quote(unquote_plus(handler.path).split('/')[1])
handler.wfile.write(unicode(t).encode('utf-8'))
def get_tivo_file(self, url, mak, tivoIP, outfile):
#global status
cj = cookielib.LWPCookieJar()
示例15: QueryContainer
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import container [as 别名]
def QueryContainer(self, handler, query):
tsn = handler.headers.getheader('tsn', '')
subcname = query['Container'][0]
if not self.get_local_path(handler, query):
handler.send_error(404)
return
container = handler.container
force_alpha = container.getboolean('force_alpha')
ar = container.get('allow_recurse', 'auto').lower()
if ar == 'auto':
allow_recurse = not tsn or tsn[0] < '7'
else:
allow_recurse = ar in ('1', 'yes', 'true', 'on')
use_html = query.get('Format', [''])[0].lower() == 'text/html'
files, total, start = self.get_files(handler, query,
self.video_file_filter,
force_alpha, allow_recurse)
videos = []
local_base_path = self.get_local_base_path(handler, query)
resort = False
for f in files:
video = VideoDetails()
mtime = f.mdate
try:
ltime = time.localtime(mtime)
except:
logger.warning('Bad file time on ' + unicode(f.name, 'utf-8'))
mtime = time.time()
ltime = time.localtime(mtime)
video['captureDate'] = hex(int(mtime))
video['textDate'] = time.strftime('%b %d, %Y', ltime)
video['name'] = os.path.basename(f.name)
video['path'] = f.name
video['part_path'] = f.name.replace(local_base_path, '', 1)
if not video['part_path'].startswith(os.path.sep):
video['part_path'] = os.path.sep + video['part_path']
video['title'] = os.path.basename(f.name)
video['is_dir'] = f.isdir
if video['is_dir']:
video['small_path'] = subcname + '/' + video['name']
video['total_items'] = self.__total_items(f.name)
else:
if len(files) == 1 or f.name in transcode.info_cache:
video['valid'] = transcode.supported_format(f.name)
if video['valid']:
video.update(self.metadata_full(f.name, tsn,
mtime=mtime))
if len(files) == 1:
video['captureDate'] = hex(isogm(video['time']))
else:
video['valid'] = True
video.update(metadata.basic(f.name, mtime))
if 'time' in video and video['time'] != '':
if video['time'].lower() == 'oad':
video['time'] = video['originalAirDate']
resort = True
try:
video['captureDate'] = hex(isogm(video['time']))
video['textDate'] = time.strftime('%b %d, %Y', time.localtime(isogm(video['time'])))
resort = True
except:
logger.warning('Bad time format: "' + video['time'] +
'", using current time')
if self.use_ts(tsn, f.name):
video['mime'] = 'video/x-tivo-mpeg-ts'
else:
video['mime'] = 'video/x-tivo-mpeg'
video['textSize'] = metadata.human_size(f.size)
videos.append(video)
if use_html:
t = Template(HTML_CONTAINER_TEMPLATE, filter=EncodeUnicode)
else:
t = Template(XML_CONTAINER_TEMPLATE, filter=EncodeUnicode)
sortby = query.get('SortOrder', ['Normal'])[0].lower()
t.sortby = sortby
if use_html and resort:
if sortby == 'capturedate':
logger.info('re-sorting by captureDate, reverse=True')
videos.sort(key=itemgetter('captureDate'), reverse=True)
elif sortby == '!capturedate':
logger.info('re-sorting by captureDate, reverse=False')
videos.sort(key=itemgetter('captureDate'), reverse=False)
t.container = handler.cname
t.name = subcname
t.total = total
t.start = start
t.videos = videos
t.quote = quote
t.escape = escape
#.........这里部分代码省略.........