forked from 0x2620/pandora
getFileInfo
This commit is contained in:
parent
9adae80d3d
commit
7d17f387b5
2 changed files with 35 additions and 0 deletions
|
@ -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']
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue