forked from 0x2620/pandora
also select poster frame based on heat if not using importFrames
This commit is contained in:
parent
a6078fa905
commit
819af3734e
1 changed files with 39 additions and 27 deletions
|
@ -375,14 +375,6 @@ class Item(models.Model):
|
||||||
else:
|
else:
|
||||||
self.poster_height = 128
|
self.poster_height = 128
|
||||||
self.poster_width = 80
|
self.poster_width = 80
|
||||||
if not settings.USE_IMDB:
|
|
||||||
if self.poster_frame == -1:
|
|
||||||
try:
|
|
||||||
if self.sort.duration:
|
|
||||||
self.poster_frame = self.sort.duration/2
|
|
||||||
update_poster = True
|
|
||||||
except ItemSort.DoesNotExist:
|
|
||||||
pass
|
|
||||||
self.json = self.get_json()
|
self.json = self.get_json()
|
||||||
self.json['modified'] = datetime.now()
|
self.json['modified'] = datetime.now()
|
||||||
super(Item, self).save(*args, **kwargs)
|
super(Item, self).save(*args, **kwargs)
|
||||||
|
@ -1194,6 +1186,7 @@ class Item(models.Model):
|
||||||
|
|
||||||
def poster_frames(self):
|
def poster_frames(self):
|
||||||
frames = []
|
frames = []
|
||||||
|
if settings.CONFIG['media']['importFrames']:
|
||||||
offset = 0
|
offset = 0
|
||||||
for f in self.files.filter(selected=True, is_video=True).order_by('sort_path'):
|
for f in self.files.filter(selected=True, is_video=True).order_by('sort_path'):
|
||||||
for ff in f.frames.all().order_by('position'):
|
for ff in f.frames.all().order_by('position'):
|
||||||
|
@ -1204,6 +1197,17 @@ class Item(models.Model):
|
||||||
'height': ff.frame.height
|
'height': ff.frame.height
|
||||||
})
|
})
|
||||||
offset += f.duration
|
offset += f.duration
|
||||||
|
else:
|
||||||
|
if 'videoRatio' in self.json:
|
||||||
|
width, height = self.json['resolution']
|
||||||
|
pos = self.sort.duration / 2
|
||||||
|
for p in map(int, [pos/2, pos, pos+pos/2]):
|
||||||
|
frames.append({
|
||||||
|
'position': p,
|
||||||
|
'path': self.frame(p, height),
|
||||||
|
'width': width,
|
||||||
|
'height': height,
|
||||||
|
})
|
||||||
return frames
|
return frames
|
||||||
|
|
||||||
def select_frame(self):
|
def select_frame(self):
|
||||||
|
@ -1211,18 +1215,26 @@ class Item(models.Model):
|
||||||
if frames:
|
if frames:
|
||||||
heat = [ox.image.getImageHeat(f['path']) for f in frames]
|
heat = [ox.image.getImageHeat(f['path']) for f in frames]
|
||||||
self.poster_frame = heat.index(max(heat))
|
self.poster_frame = heat.index(max(heat))
|
||||||
|
if not settings.CONFIG['media']['importFrames']:
|
||||||
|
self.poster_frame = frames[self.poster_frame]['position']
|
||||||
|
|
||||||
def get_poster_frame_path(self):
|
def get_poster_frame_path(self):
|
||||||
frames = self.poster_frames()
|
frames = []
|
||||||
|
path = None
|
||||||
if self.poster_frame >= 0:
|
if self.poster_frame >= 0:
|
||||||
|
if settings.CONFIG['media']['importFrames']:
|
||||||
|
frames = self.poster_frames()
|
||||||
if frames and len(frames) > int(self.poster_frame):
|
if frames and len(frames) > int(self.poster_frame):
|
||||||
return frames[int(self.poster_frame)]['path']
|
path = frames[int(self.poster_frame)]['path']
|
||||||
|
elif frames:
|
||||||
|
path = frames[int(len(frames)/2)]['path']
|
||||||
else:
|
else:
|
||||||
size = settings.CONFIG['video']['resolutions'][0]
|
size = settings.CONFIG['video']['resolutions'][0]
|
||||||
return self.frame(self.poster_frame, size)
|
path = self.frame(self.poster_frame, size)
|
||||||
|
else:
|
||||||
if frames:
|
size = settings.CONFIG['video']['resolutions'][0]
|
||||||
return frames[int(len(frames)/2)]['path']
|
path = self.frame(self.poster_frame, size)
|
||||||
|
return path
|
||||||
|
|
||||||
def make_icon(self):
|
def make_icon(self):
|
||||||
frame = self.get_poster_frame_path()
|
frame = self.get_poster_frame_path()
|
||||||
|
|
Loading…
Reference in a new issue