From 8e694113731af4845e3179bf1f68ab1ca60f2265 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 21 Jan 2011 16:19:24 +0530 Subject: [PATCH] use item.poster_frame if set --- pandora/item/models.py | 31 ++++++++++++++++++++++--------- pandora/item/tasks.py | 1 + pandora/item/views.py | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 158610f74..55eab90d4 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -736,12 +736,18 @@ class Item(models.Model): def local_posters(self): part = 1 posters = {} - for f in self.main_videos(): - for frame in f.frames.all(): - path = self.path('poster.pandora.%s.%s.jpg'%(part, frame.position)) - path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path)) - posters[path] = frame.frame.path - part += 1 + self.poster_frame >= 0: + frame = self.get_poster_frame_path() + path = self.path('poster.pandora.%s.%s.jpg'%(part, self.poster_frame)) + path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path)) + posters[path] = frame + else: + for f in self.main_videos(): + for frame in f.frames.all(): + path = self.path('poster.pandora.%s.%s.jpg'%(part, frame.position)) + path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path)) + posters[path] = frame.frame.path + part += 1 return posters def make_local_posters(self): @@ -766,13 +772,20 @@ class Item(models.Model): p.wait() return posters.keys() - def make_icon(self): - #FIXME: should take middle or selected frame or som + def get_poster_frame_path(self): + if self.poster_frame >= 0: + size = int(settings.VIDEO_PROFILE[:-1]) + return self.frame(self.poster_frame, size) + frames = [] for f in self.main_videos(): for ff in f.frames.all(): frames.append(ff.frame.path) - if frames: + return frames[int(len(frames)/2)] + + def make_icon(self): + frame = self.get_poster_frame_path() + if frame: icon = self.path('icon.jpg') self.icon.name = icon frame = frames[int(len(frames)/2)] diff --git a/pandora/item/tasks.py b/pandora/item/tasks.py index e94254a2a..95b987f55 100644 --- a/pandora/item/tasks.py +++ b/pandora/item/tasks.py @@ -16,6 +16,7 @@ def cronjob(**kwargs): def update_poster(itemId): item = models.Item.objects.get(itemId=itemId) item.make_poster(True) + item.make_icon() @task(ignore_resulsts=True, queue='default') diff --git a/pandora/item/views.py b/pandora/item/views.py index 2560f079b..ee216666f 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -373,6 +373,7 @@ def setPosterFrame(request): #parse path and return info #FIXME: some things need to be updated after changing this item.poster_frame = data['position'] item.save() + tasks.update_poster.delay(item.itemId) response = json_response() else: response = json_response(status=403, text='permissino denied')