62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
from turbogears import controllers, expose, flash, redirect
|
|
from model import *
|
|
from json import *
|
|
import cherrypy
|
|
import backup
|
|
|
|
# import logging
|
|
# log = logging.getLogger("oxdbarchive.controllers")
|
|
|
|
'''
|
|
/md5/frame/position.jpg
|
|
/md5/clip/position.jpg
|
|
/md5/metadata
|
|
'''
|
|
|
|
def httpExpires(sec):
|
|
exp_date = cherrypy.lib.httptools.HTTPDate(time.gmtime(time.mktime(time.gmtime()) + sec))
|
|
return exp_date
|
|
|
|
class Root(controllers.RootController):
|
|
@expose()
|
|
def default(self, md5Hash = None, action = None, position = None):
|
|
if not md5Hash:
|
|
return dict()
|
|
try:
|
|
f = ArchiveFile.byMd5sum(md5Hash)
|
|
except:
|
|
#return dict()
|
|
f = backup.Backup(md5Hash)
|
|
if not f.exists():
|
|
return dict()
|
|
if action == 'metadata':
|
|
return dict(metadata = f)
|
|
elif action in ('timeline', 'timeline.png'):
|
|
cherrypy.response.headerMap['Content-Type'] = "image/png"
|
|
cherrypy.response.headerMap["Expires"] = httpExpires(60*60*24*15)
|
|
return f.timeline()
|
|
elif position: #clip / frame
|
|
position = position.replace('.png', '').replace('.jpg', '')
|
|
position = position.replace('.flv', '').replace('.ogv', '')
|
|
position = position.replace('-', ':').replace('.',':')
|
|
cherrypy.response.headerMap["Expires"] = httpExpires(60*60*24*15)
|
|
if action == 'clip':
|
|
cherrypy.response.headerMap['Content-Type'] = "video/x-flv"
|
|
return f.flvClip(position)
|
|
if action == 'ogv':
|
|
cherrypy.response.headerMap['Content-Type'] = "video/ogg"
|
|
return f.oggClip(position)
|
|
elif action == 'frame':
|
|
cherrypy.response.headerMap['Content-Type'] = "image/jpeg"
|
|
return f.frame(position)
|
|
elif action == 'still':
|
|
cherrypy.response.headerMap['Content-Type'] = "image/png"
|
|
return f.still(position)
|
|
elif action == 'posterStill':
|
|
cherrypy.response.headerMap['Content-Type'] = "image/png"
|
|
return f.posterStill(position)
|
|
return dict()
|
|
|