From 23398c4307c18709463ea72063ee4e81411fdc15 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 23 May 2015 14:22:44 +0530 Subject: [PATCH] get resolution from videos while uploading and dont return sort value --- pandora/item/models.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index a31d780ea..299a4698a 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -612,14 +612,23 @@ class Item(models.Model): i['audioTracks'] = self.audio_tracks() if not i['audioTracks']: del i['audioTracks'] - if not streams: - i['duration'] = self.files.filter( - Q(selected=True)|Q(wanted=True) - ).aggregate(Sum('duration'))['duration__sum'] i['parts'] = len(i['durations']) if i['parts']: i['videoRatio'] = streams[0].aspect_ratio i['resolution'] = (streams[0].file.width, streams[0].file.height) + else: + i['duration'] = self.files.filter( + Q(selected=True)|Q(wanted=True) + ).aggregate(Sum('duration'))['duration__sum'] + videos = self.files.filter(selected=True, is_video=True) + if i['duration'] and videos.count(): + i['resolution'] = (videos[0].width, streams[0].height) + if i['resolution'][1] != 0: + i['videoRatio'] = i['resolution'][0] / i['resolution'][1] + else: + for k in ('resolution', 'videoRatio'): + if k in i: + del i[k] #only needed by admins if keys and 'posters' in keys: @@ -1426,7 +1435,7 @@ class Item(models.Model): }) offset += f.duration else: - if 'videoRatio' in self.json and self.sort.duration: + if 'videoRatio' in self.json and self.sort.duration and self.streams(): width, height = self.json['resolution'] if width and height: pos = self.sort.duration / 2