fixed xhtml+xml, added basic upload with video validation and duplicate check
git-svn-id: http://yolanda.mister-muffin.de/svn@376 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
parent
fc850dc449
commit
3e56a2eb1b
7 changed files with 31 additions and 18 deletions
|
@ -17,6 +17,6 @@ port = 5000
|
|||
|
||||
[app:main]
|
||||
use = config:development.ini
|
||||
sqlalchemy.url = sqlite:///%(here)s/mydatabasefilename.sqlite
|
||||
sqlalchemy.url = sqlite:///%(here)s/database.sqlite
|
||||
|
||||
# Add additional test specific configuration options as necessary.
|
||||
|
|
|
@ -35,5 +35,7 @@ def load_environment(global_conf, app_conf):
|
|||
# CONFIGURATION OPTIONS HERE (note: all config options will override
|
||||
# any Pylons config options)
|
||||
|
||||
config['pylons.response_options']['content_type'] = "application/xhtml+xml"
|
||||
|
||||
model.metadata.bind = engine_from_config(config, 'sqlalchemy.')
|
||||
model.metadata.bind.echo = True
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import logging
|
||||
|
||||
from yolanda.lib.base import *
|
||||
from yolanda.lib.gstreamer import info, snapshot
|
||||
from yolanda.lib.gstreamer import info, snapshot, encode
|
||||
import os
|
||||
import hashlib
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -12,20 +13,29 @@ class UploadController(BaseController):
|
|||
return render('/xhtml/upload.mako')
|
||||
|
||||
def upload(self):
|
||||
myfile = request.params['file']
|
||||
permanent_file = open(os.path.join(myfile.filename.lstrip(os.sep)),'w')
|
||||
|
||||
#u.copyfileobj(myfile.file, permanent_file)
|
||||
upload = request.params['file']
|
||||
|
||||
foo=model.Video(title=u"foooooo")
|
||||
#check if file is video
|
||||
videoinfo = info.Info(upload.file)
|
||||
if not videoinfo.get_info():
|
||||
return "not a valid video"
|
||||
|
||||
#check if file is duplicate
|
||||
sha256 = hashlib.sha256(upload.file.read(1024*1024)).hexdigest()
|
||||
|
||||
if model.Video.query.filter_by(sha256=sha256).count():
|
||||
return "duplicate"
|
||||
|
||||
video = model.Video(title=request.params['title'],sha256=sha256)
|
||||
model.session.commit()
|
||||
|
||||
videoinfo = info.Info(myfile.file)
|
||||
videoinfo.get_info()
|
||||
print videoinfo.print_info()
|
||||
|
||||
myfile.file.close()
|
||||
permanent_file = open(os.path.join(config['cache.dir'], str(video.id)), 'w')
|
||||
upload.file.seek(0)
|
||||
u.copyfileobj(upload.file, permanent_file)
|
||||
upload.file.close()
|
||||
permanent_file.close()
|
||||
|
||||
return 'Successfully uploaded: %s'%""
|
||||
|
||||
|
||||
videoencode = encode.Encode(os.path.join(config['cache.dir'], str(video.id)))
|
||||
videoencode.run()
|
||||
|
||||
return 'Successfully uploaded: %s'%video.query.all()
|
||||
|
|
|
@ -21,7 +21,6 @@ class BaseController(WSGIController):
|
|||
# WSGIController.__call__ dispatches to the Controller method
|
||||
# the request is routed to. This routing information is
|
||||
# available in environ['pylons.routes_dict']
|
||||
response.headers['Content-type'] = "application/xhtml+xml"
|
||||
return WSGIController.__call__(self, environ, start_response)
|
||||
|
||||
# Include the '_' function in the public names
|
||||
|
|
|
@ -151,8 +151,9 @@ class Info(Discoverer):
|
|||
The function returns wether or not the discovering was successful.
|
||||
"""
|
||||
self.mainloop.run()
|
||||
#only return true if source is a valid video file
|
||||
return self.finished and self.mimetype and \
|
||||
(self.is_video or self.is_audio)
|
||||
self.is_video and self.videorate.num/self.videorate.denom
|
||||
|
||||
def _discovered(self, discoverer, ismedia):
|
||||
"""When we discover something - quit main loop"""
|
||||
|
|
|
@ -4,3 +4,4 @@ class Video(Entity):
|
|||
using_options(tablename='videos')
|
||||
|
||||
title = Field(Unicode(255))
|
||||
sha256 = Field(String(64))
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
${h.form(h.url_for(action='upload'), multipart=True)}
|
||||
${h.file_field('file')}<br />
|
||||
${h.text_field('name')}<br />
|
||||
${h.text_field('title')}<br />
|
||||
${h.submit('Upload')}
|
||||
|
||||
${h.end_form()}
|
||||
|
|
Loading…
Reference in a new issue