From d7e8d18e35ea4c40c5470e5e1b27435f1c12b5ff Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 23 Feb 2011 12:51:32 +0100 Subject: [PATCH] audio only --- pandora/archive/models.py | 3 +++ pandora/archive/views.py | 1 + pandora/item/models.py | 21 +++++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 26ee8f0f..862ce935 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -101,6 +101,9 @@ class File(models.Model): self.is_video = False else: self.is_video = False + self.display_aspect_ratio = "4:3" + self.width = '320' + self.height = '240' if 'audio' in self.info and self.info['audio']: audio = self.info['audio'][0] self.audio_codec = audio['codec'] diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 751fa1c8..ef3b6fac 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -98,6 +98,7 @@ def update(request): response['data']['info'] = [f.file.oshash for f in files.filter(file__info='{}')] #needs some flag to find those that are actually used main is to generic response['data']['data'] = [f.file.oshash for f in files.filter(file__is_video=True, file__is_main=True)] + response['data']['data'] += [f.file.oshash for f in files.filter(file__is_audio=True, file__is_main=True)] response['data']['file'] = [f.file.oshash for f in files.filter(file__is_subtitle=True)] return render_to_json_response(response) diff --git a/pandora/item/models.py b/pandora/item/models.py index 32504753..e243945c 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -96,7 +96,7 @@ class Item(models.Model): published = models.DateTimeField(default=datetime.now, editable=False) user = models.ForeignKey(User, null=True, related_name='items') - groups = models.ManyToManyField(Group, related_name='items') + groups = models.ManyToManyField(Group, blank=True, related_name='items') #only items that have data from files are available, #this is indicated by setting available to True @@ -627,6 +627,18 @@ class Item(models.Model): return True return False videos = filter(check, videos) + else: + audio = self.files.filter(is_main=True, is_audio=True, available=True) + if audio.count()>0: + first = audio[0] + user = first.instances.all()[0].volume.user + #only take videos from same user and with same width/height + def check(v): + if v.instances.filter(volume__user=user).count()>0: + return True + return False + videos = filter(check, audio) + return videos def update_streams(self): @@ -658,9 +670,9 @@ class Item(models.Model): os.symlink(files.values()[0], stream.video.path) stream.save() - if 'video' in stream.info: + extract.timeline(stream.video.path, self.timeline_prefix) + if 'video' in stream.info and stream.info['video']: v = stream.info['video'][0] - extract.timeline(stream.video.path, self.timeline_prefix) self.stream_aspect = v['width']/v['height'] self.data['cuts'] = extract.cuts(self.timeline_prefix) self.data['color'] = extract.average_color(self.timeline_prefix) @@ -787,7 +799,8 @@ class Item(models.Model): for f in self.main_videos(): for ff in f.frames.all(): frames.append(ff.frame.path) - return frames[int(len(frames)/2)] + if frames: + return frames[int(len(frames)/2)] def make_icon(self): frame = self.get_poster_frame_path()