diff --git a/pandora/item/models.py b/pandora/item/models.py index 158610f..55eab90 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 e94254a..95b987f 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 2560f07..ee21666 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')