use item.poster_frame if set

This commit is contained in:
j 2011-01-21 16:19:24 +05:30
parent cad35ebc46
commit 8e69411373
3 changed files with 24 additions and 9 deletions

View file

@ -736,12 +736,18 @@ class Item(models.Model):
def local_posters(self): def local_posters(self):
part = 1 part = 1
posters = {} posters = {}
for f in self.main_videos(): self.poster_frame >= 0:
for frame in f.frames.all(): frame = self.get_poster_frame_path()
path = self.path('poster.pandora.%s.%s.jpg'%(part, frame.position)) path = self.path('poster.pandora.%s.%s.jpg'%(part, self.poster_frame))
path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path)) path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path))
posters[path] = frame.frame.path posters[path] = frame
part += 1 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 return posters
def make_local_posters(self): def make_local_posters(self):
@ -766,13 +772,20 @@ class Item(models.Model):
p.wait() p.wait()
return posters.keys() return posters.keys()
def make_icon(self): def get_poster_frame_path(self):
#FIXME: should take middle or selected frame or som if self.poster_frame >= 0:
size = int(settings.VIDEO_PROFILE[:-1])
return self.frame(self.poster_frame, size)
frames = [] frames = []
for f in self.main_videos(): for f in self.main_videos():
for ff in f.frames.all(): for ff in f.frames.all():
frames.append(ff.frame.path) 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') icon = self.path('icon.jpg')
self.icon.name = icon self.icon.name = icon
frame = frames[int(len(frames)/2)] frame = frames[int(len(frames)/2)]

View file

@ -16,6 +16,7 @@ def cronjob(**kwargs):
def update_poster(itemId): def update_poster(itemId):
item = models.Item.objects.get(itemId=itemId) item = models.Item.objects.get(itemId=itemId)
item.make_poster(True) item.make_poster(True)
item.make_icon()
@task(ignore_resulsts=True, queue='default') @task(ignore_resulsts=True, queue='default')

View file

@ -373,6 +373,7 @@ def setPosterFrame(request): #parse path and return info
#FIXME: some things need to be updated after changing this #FIXME: some things need to be updated after changing this
item.poster_frame = data['position'] item.poster_frame = data['position']
item.save() item.save()
tasks.update_poster.delay(item.itemId)
response = json_response() response = json_response()
else: else:
response = json_response(status=403, text='permissino denied') response = json_response(status=403, text='permissino denied')