From b9b861a3e89124d625114034cdc5a62e0052ee55 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 21 Oct 2011 20:02:36 +0200 Subject: [PATCH] save color/cuts per stream --- pandora/archive/models.py | 5 +++++ pandora/item/models.py | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 81318f5b3..2a5e2e55e 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -442,6 +442,9 @@ class Stream(models.Model): duration = models.FloatField(default=0) aspect_ratio = models.FloatField(default=0) + cuts = fields.TupleField(default=[]) + color = fields.TupleField(default=[]) + @property def timeline_prefix(self): return os.path.join(settings.MEDIA_ROOT, self.path(), 'timeline') @@ -484,6 +487,8 @@ class Stream(models.Model): def make_timeline(self): if self.available and not self.source: extract.timeline(self.video.path, self.timeline_prefix) + self.cuts = tuple(extract.cuts(self.timeline_prefix)) + self.color = tuple(extract.average_color(self.timeline_prefix)) def save(self, *args, **kwargs): if self.video and not self.info: diff --git a/pandora/item/models.py b/pandora/item/models.py index a35413222..3cde9962c 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -850,8 +850,22 @@ class Item(models.Model): def update_timeline(self, force=False): streams = self.streams() self.make_timeline() - self.data['cuts'] = extract.cuts(self.timeline_prefix) - self.data['color'] = extract.average_color(self.timeline_prefix) + if streams.count() == 1: + self.data['color'] = streams[0].color + self.data['cuts'] = streams[0].cuts + else: + #self.data['color'] = extract.average_color(self.timeline_prefix) + #self.data['cuts'] = extract.cuts(self.timeline_prefix) + self.data['cuts'] = [] + offset = 0 + color = [0, 0, 0] + n = streams.count() + for s in streams: + for c in s.cuts: + self.data['cuts'].append(c+offset) + color = map(lambda a,b: (a+b)/n, color,ox.image.getRGB(s.color)) + offset += s.duration + self.data['color'] = ox.image.getHSL(color) #extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8]) self.select_frame() self.make_local_poster()