fixed duplicate video bug, added proper placement of encoded video
git-svn-id: http://yolanda.mister-muffin.de/svn@377 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
parent
3e56a2eb1b
commit
243cf1fa7f
2 changed files with 16 additions and 10 deletions
|
@ -21,6 +21,7 @@ class UploadController(BaseController):
|
|||
return "not a valid video"
|
||||
|
||||
#check if file is duplicate
|
||||
upload.file.seek(0)
|
||||
sha256 = hashlib.sha256(upload.file.read(1024*1024)).hexdigest()
|
||||
|
||||
if model.Video.query.filter_by(sha256=sha256).count():
|
||||
|
@ -29,13 +30,17 @@ class UploadController(BaseController):
|
|||
video = model.Video(title=request.params['title'],sha256=sha256)
|
||||
model.session.commit()
|
||||
|
||||
permanent_file = open(os.path.join(config['cache.dir'], str(video.id)), 'w')
|
||||
temp_file = open(os.path.join(config['cache.dir'], str(video.id)), 'w')
|
||||
upload.file.seek(0)
|
||||
u.copyfileobj(upload.file, permanent_file)
|
||||
u.copyfileobj(upload.file, temp_file)
|
||||
upload.file.close()
|
||||
permanent_file.close()
|
||||
temp_file.close()
|
||||
|
||||
videoencode = encode.Encode(os.path.join(config['cache.dir'], str(video.id)))
|
||||
#here begins the later daemon's work
|
||||
videoencode = encode.Encode(
|
||||
os.path.join(config['cache.dir'], str(video.id)),
|
||||
os.path.join(config['pylons.paths']['static_files'], "videos", str(video.id)))
|
||||
videoencode.run()
|
||||
os.unlink(os.path.join(config['cache.dir'], str(video.id)))
|
||||
|
||||
return 'Successfully uploaded: %s'%video.query.all()
|
||||
|
|
|
@ -36,7 +36,7 @@ class Encode:
|
|||
def _build_pipeline(self):
|
||||
self.player = gst.Pipeline("player")
|
||||
source = gst.element_factory_make("filesrc", "file-source")
|
||||
source.set_property("location", self.filename)
|
||||
source.set_property("location", self.source)
|
||||
decodebin = gst.element_factory_make("decodebin", "decodebin")
|
||||
decodebin.connect("pad-added", self.decodebin_callback)
|
||||
audioconvert = gst.element_factory_make("audioconvert", "audioconvert")
|
||||
|
@ -61,7 +61,7 @@ class Encode:
|
|||
queuev = gst.element_factory_make("queue", "queuev")
|
||||
muxer = gst.element_factory_make("oggmux", "muxer")
|
||||
filesink = gst.element_factory_make("filesink", "filesink")
|
||||
filesink.set_property("location", self.filename+".ogg")
|
||||
filesink.set_property("location", self.destination)
|
||||
|
||||
self.player.add(source, decodebin, ffmpeg, muxer, filesink, videorate,
|
||||
videoscale, audioconvert, vorbisenc, theoraenc, queuea, queuev,
|
||||
|
@ -80,11 +80,12 @@ class Encode:
|
|||
bus.connect("message", self.on_message)
|
||||
self.player.set_state(gst.STATE_PLAYING)
|
||||
|
||||
def __init__(self, filename, videoquality=16, quick=True, sharpness=2,
|
||||
def __init__(self, source, destination, videoquality=16, quick=True, sharpness=2,
|
||||
video=True, audio=True, audioquality=0.1):
|
||||
if not os.path.isfile(filename):
|
||||
if not os.path.isfile(source):
|
||||
raise IOError, "cannot read file"
|
||||
self.filename = filename
|
||||
self.source = source
|
||||
self.destination = destination
|
||||
if not video and not audio:
|
||||
raise AttributeError, "must contain video or audio"
|
||||
self.video = bool(video)
|
||||
|
@ -132,7 +133,7 @@ def main(args):
|
|||
print 'usage: %s file' % args[0]
|
||||
return 2
|
||||
|
||||
encode = Encode(args[1])
|
||||
encode = Encode(args[1], args[1]+".ogg")
|
||||
encode.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue