diff --git a/trunk/test.ini b/trunk/test.ini
index 3857529..ecc3c05 100644
--- a/trunk/test.ini
+++ b/trunk/test.ini
@@ -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.
diff --git a/trunk/yolanda/config/environment.py b/trunk/yolanda/config/environment.py
index de61ec2..e12c7d4 100644
--- a/trunk/yolanda/config/environment.py
+++ b/trunk/yolanda/config/environment.py
@@ -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
diff --git a/trunk/yolanda/controllers/upload.py b/trunk/yolanda/controllers/upload.py
index c7094cc..bb2b8cd 100644
--- a/trunk/yolanda/controllers/upload.py
+++ b/trunk/yolanda/controllers/upload.py
@@ -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")
- model.session.commit()
+ #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()
- videoinfo = info.Info(myfile.file)
- videoinfo.get_info()
- print videoinfo.print_info()
+ if model.Video.query.filter_by(sha256=sha256).count():
+ return "duplicate"
+
+ video = model.Video(title=request.params['title'],sha256=sha256)
+ model.session.commit()
- 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()
diff --git a/trunk/yolanda/lib/base.py b/trunk/yolanda/lib/base.py
index 52a8c28..cfb9821 100644
--- a/trunk/yolanda/lib/base.py
+++ b/trunk/yolanda/lib/base.py
@@ -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
diff --git a/trunk/yolanda/lib/gstreamer/info.py b/trunk/yolanda/lib/gstreamer/info.py
index 2d98631..7d265cf 100644
--- a/trunk/yolanda/lib/gstreamer/info.py
+++ b/trunk/yolanda/lib/gstreamer/info.py
@@ -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"""
diff --git a/trunk/yolanda/model/entities.py b/trunk/yolanda/model/entities.py
index da30fd6..0cb50fb 100644
--- a/trunk/yolanda/model/entities.py
+++ b/trunk/yolanda/model/entities.py
@@ -4,3 +4,4 @@ class Video(Entity):
using_options(tablename='videos')
title = Field(Unicode(255))
+ sha256 = Field(String(64))
diff --git a/trunk/yolanda/templates/xhtml/upload.mako b/trunk/yolanda/templates/xhtml/upload.mako
index 59f177d..949ed6f 100644
--- a/trunk/yolanda/templates/xhtml/upload.mako
+++ b/trunk/yolanda/templates/xhtml/upload.mako
@@ -11,7 +11,7 @@
${h.form(h.url_for(action='upload'), multipart=True)}
${h.file_field('file')}
- ${h.text_field('name')}
+ ${h.text_field('title')}
${h.submit('Upload')}
${h.end_form()}