From a12e207a2807d2b719676b600c703106e173d170 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 15 Sep 2010 15:03:00 +0200 Subject: [PATCH] save derivatives --- pandora/archive/extract.py | 11 ++++++----- pandora/backend/models.py | 22 ++++++++++++++-------- pandora/static/js/pandora.local.js | 2 +- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index c46ca5d8..e3852592 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -173,17 +173,18 @@ def stream(video, target, profile, info): cmd += ['-f','webm', target] print cmd - p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - p.wait() + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) + p.communicate() if format == 'mp4': cmd = ['qt-faststart', "%s.mp4"%target, target] print cmd - p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - p.wait() + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) + p.communicate() os.unlink("%s.mp4"%target) + return True def run_command(cmd, timeout=10): - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen(cmd, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) while timeout > 0: time.sleep(0.2) timeout -= 0.2 diff --git a/pandora/backend/models.py b/pandora/backend/models.py index 1381e685..918b19ce 100644 --- a/pandora/backend/models.py +++ b/pandora/backend/models.py @@ -443,7 +443,7 @@ class Movie(models.Model): ''' def frame(self, position, width=128): stream = self.streams.filter(profile=settings.VIDEO_PROFILE+'.webm')[0] - path = os.path.join(settings.MEDIA_ROOT, movieid_path(self.movieId), 'frame', "%d"%width, "%s.jpg"%position) + path = os.path.join(settings.MEDIA_ROOT, movieid_path(self.movieId), 'frames', "%d"%width, "%s.jpg"%position) if not os.path.exists(path): extract.frame(stream.video.path, path, position, width) return path @@ -832,7 +832,7 @@ class Collection(models.Model): return self.users.filter(id=user.id).count() > 0 def movieid_path(h): - return os.path.join('movie', h[:2], h[2:4], h[4:6], h[6:]) + return os.path.join('movies', h[:2], h[2:4], h[4:6], h[6:]) def stream_path(stream): return os.path.join(movieid_path(stream.movie.movieId), stream.profile) @@ -854,25 +854,31 @@ class Stream(models.Model): def extract_derivatives(self): if settings.VIDEO_H264: profile = self.profile.replace('.webm', '.mp4') - if Stream.objects.filter(profile=profile, source=self).count() == 0: - derivative = Stream(movie=self.movie, source=self, profile=profile) + derivative, created = Stream.objects.get_or_create(profile=profile, movie=self.movie) + if created: + derivative.source = self derivative.video.name = self.video.name.replace(self.profile, profile) derivative.encode() + derivative.save() for p in settings.VIDEO_DERIVATIVES: profile = p + '.webm' target = self.video.path.replace(self.profile, profile) - if Stream.objects.filter(profile=profile, source=self).count() == 0: - derivative = Stream(movie=movie.file, source=self, profile=profile) + derivative, created = Stream.objects.get_or_create(profile=profile, movie=self.movie) + if created: + derivative.source = self derivative.video.name = self.video.name.replace(self.profile, profile) derivative.encode() + derivative.save() if settings.VIDEO_H264: profile = p + '.mp4' - if Stream.objects.filter(profile=profile, source=self).count() == 0: - derivative = Stream(movie=self.movie, source=self, profile=profile) + derivative, created = Stream.objects.get_or_create(profile=profile, movie=self.movie) + if created: + derivative.source = self derivative.video.name = self.video.name.replace(self.profile, profile) derivative.encode() + derivative.save() return True def encode(self): diff --git a/pandora/static/js/pandora.local.js b/pandora/static/js/pandora.local.js index b6c2b13d..af120047 100644 --- a/pandora/static/js/pandora.local.js +++ b/pandora/static/js/pandora.local.js @@ -1,6 +1,7 @@ if(typeof(app.afterLaunch) == "undefined") app.afterLaunch = []; +//app.afterLaunch[0](); app.afterLaunch.push(function() { if (typeof(OxFF) == 'undefined') return; @@ -32,7 +33,6 @@ app.afterLaunch.push(function() { .append("For this part of the page to work, you have to allow OxFF to send data to this site") .open(); } else { - Ox.print('we got it, lets party'); _this.api.login(app.user.username); _this.api.volumes(function(result) { var data = JSON.parse(result);