diff --git a/pandora/archive/models.py b/pandora/archive/models.py index ace88ad2..1e4ee859 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -386,6 +386,7 @@ class Stream(models.Model): video = models.FileField(default=None, blank=True, upload_to=lambda f, x: f.path(x)) source = models.ForeignKey('Stream', related_name='derivatives', default=None, null=True) available = models.BooleanField(default=False) + oshash = models.CharField(max_length=16, null=True, db_index=True) info = fields.DictField(default={}) duration = models.FloatField(default=0) aspect_ratio = models.FloatField(default=0) @@ -442,6 +443,7 @@ class Stream(models.Model): def save(self, *args, **kwargs): if self.video and not self.info: self.info = ox.avinfo(self.video.path) + self.oshash = self.info.get('oshash') self.duration = self.info.get('duration', 0) if 'video' in self.info and self.info['video']: self.aspect_ratio = self.info['video'][0]['width'] / self.info['video'][0]['height'] diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 93131438..45ec64ea 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -558,3 +558,36 @@ def parsePath(request): #parse path and return info response = json_response(ox.parse_movie_path(path)) return render_to_json_response(response) actions.register(parsePath) + +def getFileInfo(request): + ''' + param data { + id: oshash of stream file + } + return { + status: {'code': int, 'text': string}, + data: { + item: itemId, + file: oshash of source file + } + } + ''' + data = json.loads(request.POST['data']) + f = None + qs = models.Stream.objects.filter(oshash=data['id']) + if qs.count() > 0: + s = qs[0] + f = s.file + else: + qs = models.File.objects.filter(oshash=data['id']) + if qs.count() > 0: + f = qs[0] + response = json_response() + if f: + response['data'] = { + 'file': f.oshash, + 'item': f.item.itemId + } + return render_to_json_response(response) +actions.register(getFileInfo) +