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,16 +1186,28 @@ class Item(models.Model):
|
||||||
|
|
||||||
def poster_frames(self):
|
def poster_frames(self):
|
||||||
frames = []
|
frames = []
|
||||||
offset = 0
|
if settings.CONFIG['media']['importFrames']:
|
||||||
for f in self.files.filter(selected=True, is_video=True).order_by('sort_path'):
|
offset = 0
|
||||||
for ff in f.frames.all().order_by('position'):
|
for f in self.files.filter(selected=True, is_video=True).order_by('sort_path'):
|
||||||
frames.append({
|
for ff in f.frames.all().order_by('position'):
|
||||||
'position': offset + ff.position,
|
frames.append({
|
||||||
'path': ff.frame.path,
|
'position': offset + ff.position,
|
||||||
'width': ff.frame.width,
|
'path': ff.frame.path,
|
||||||
'height': ff.frame.height
|
'width': ff.frame.width,
|
||||||
})
|
'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 frames and len(frames) > int(self.poster_frame):
|
if settings.CONFIG['media']['importFrames']:
|
||||||
return frames[int(self.poster_frame)]['path']
|
frames = self.poster_frames()
|
||||||
else:
|
if frames and len(frames) > int(self.poster_frame):
|
||||||
size = settings.CONFIG['video']['resolutions'][0]
|
path = frames[int(self.poster_frame)]['path']
|
||||||
return self.frame(self.poster_frame, size)
|
elif frames:
|
||||||
|
path = frames[int(len(frames)/2)]['path']
|
||||||
if frames:
|
else:
|
||||||
return frames[int(len(frames)/2)]['path']
|
size = settings.CONFIG['video']['resolutions'][0]
|
||||||
|
path = self.frame(self.poster_frame, size)
|
||||||
|
else:
|
||||||
|
size = settings.CONFIG['video']['resolutions'][0]
|
||||||
|
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