forked from 0x2620/pandora
new api get({id, keys}, one poster per service
This commit is contained in:
parent
2bfd73b214
commit
68c66b7276
2 changed files with 51 additions and 18 deletions
|
@ -308,17 +308,27 @@ class Item(models.Model):
|
||||||
return poster
|
return poster
|
||||||
|
|
||||||
def get_posters(self):
|
def get_posters(self):
|
||||||
posters = {
|
url = self.prefered_poster_url()
|
||||||
'local': [{
|
posters = [
|
||||||
|
{
|
||||||
'url': '/%s/poster.pandora.jpg' % self.itemId,
|
'url': '/%s/poster.pandora.jpg' % self.itemId,
|
||||||
'width': 640,
|
'width': 640,
|
||||||
'height': 1024,
|
'height': 1024,
|
||||||
}]
|
'service': settings.URL,
|
||||||
|
'selected': url == None
|
||||||
}
|
}
|
||||||
for p in self.poster_urls.all():
|
]
|
||||||
if p.service not in posters:
|
got = {}
|
||||||
posters[p.service] = []
|
for p in self.poster_urls.all().order_by('-height'):
|
||||||
posters[p.service].append({'url': p.url, 'width': p.width, 'height': p.height})
|
if p.service not in got:
|
||||||
|
got[p.service] = 1
|
||||||
|
posters.append({
|
||||||
|
'url': p.url,
|
||||||
|
'width': p.width,
|
||||||
|
'height': p.height,
|
||||||
|
'service': p.service,
|
||||||
|
'selected': p.url == url
|
||||||
|
})
|
||||||
return posters
|
return posters
|
||||||
|
|
||||||
def get_stream(self):
|
def get_stream(self):
|
||||||
|
@ -369,9 +379,12 @@ class Item(models.Model):
|
||||||
if value:
|
if value:
|
||||||
i[key] = value
|
i[key] = value
|
||||||
|
|
||||||
|
if not fields or 'poster' in fields:
|
||||||
i['poster'] = self.get_poster()
|
i['poster'] = self.get_poster()
|
||||||
|
if not fields or 'posters' in fields:
|
||||||
i['posters'] = self.get_posters()
|
i['posters'] = self.get_posters()
|
||||||
i['posterFrames'] = ['/%s/frame/poster/%d.jpg' %(self.itemId, p)
|
if not fields or 'frames' in fields:
|
||||||
|
i['frames'] = ['/%s/frame/poster/%d.jpg' %(self.itemId, p)
|
||||||
for p in range(0, len(self.poster_frames()))]
|
for p in range(0, len(self.poster_frames()))]
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
|
@ -326,6 +326,31 @@ def autocomplete(request):
|
||||||
actions.register(autocomplete)
|
actions.register(autocomplete)
|
||||||
|
|
||||||
|
|
||||||
|
def get(request):
|
||||||
|
'''
|
||||||
|
param data {
|
||||||
|
id: string
|
||||||
|
keys: array
|
||||||
|
}
|
||||||
|
return item array
|
||||||
|
'''
|
||||||
|
response = json_response({})
|
||||||
|
data = json.loads(request.POST['data'])
|
||||||
|
item = get_object_or_404_json(models.Item, itemId=data['id'])
|
||||||
|
if item.access(request.user):
|
||||||
|
info = item.get_json(data['keys'])
|
||||||
|
if 'stream' in data['keys']:
|
||||||
|
info['stream'] = item.get_stream()
|
||||||
|
if 'layers' in data['keys']:
|
||||||
|
info['layers'] = item.get_layers(request.user)
|
||||||
|
response['data'] = {}
|
||||||
|
for key in data['keys']:
|
||||||
|
response['data'][key] = info[key]
|
||||||
|
else:
|
||||||
|
response = json_response(status=403, text='permission denied')
|
||||||
|
return render_to_json_response(response)
|
||||||
|
actions.register(get)
|
||||||
|
|
||||||
def getItem(request):
|
def getItem(request):
|
||||||
'''
|
'''
|
||||||
param data
|
param data
|
||||||
|
@ -450,7 +475,7 @@ def setPoster(request): #parse path and return info
|
||||||
item = get_object_or_404_json(models.Item, itemId=data['id'])
|
item = get_object_or_404_json(models.Item, itemId=data['id'])
|
||||||
response = json_response()
|
response = json_response()
|
||||||
if item.editable(request.user):
|
if item.editable(request.user):
|
||||||
valid_urls = [p.url for p in item.poster_urls.all()]
|
valid_urls = [p['url'] for p in item.get_posters()]
|
||||||
if data['url'] in valid_urls:
|
if data['url'] in valid_urls:
|
||||||
item.poster_url = data['url']
|
item.poster_url = data['url']
|
||||||
if item.poster:
|
if item.poster:
|
||||||
|
@ -459,11 +484,6 @@ def setPoster(request): #parse path and return info
|
||||||
tasks.update_poster.delay(item.itemId)
|
tasks.update_poster.delay(item.itemId)
|
||||||
response = json_response()
|
response = json_response()
|
||||||
response['data']['poster'] = item.get_poster()
|
response['data']['poster'] = item.get_poster()
|
||||||
elif data['url'].endswith('/poster.pandora.jpg'):
|
|
||||||
item.poster_url = ''
|
|
||||||
item.save()
|
|
||||||
tasks.update_poster.delay(item.itemId)
|
|
||||||
response['data']['poster'] = item.get_poster()
|
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='invalid poster url')
|
response = json_response(status=403, text='invalid poster url')
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue