forked from 0x2620/pandora
poster api fixes
This commit is contained in:
parent
d532558dfc
commit
b93d1b1190
3 changed files with 30 additions and 26 deletions
|
@ -408,8 +408,7 @@
|
||||||
{"id": "player", "title": "Player"},
|
{"id": "player", "title": "Player"},
|
||||||
{"id": "timeline", "title": "Timeline"},
|
{"id": "timeline", "title": "Timeline"},
|
||||||
{"id": "map", "title": "Map"},
|
{"id": "map", "title": "Map"},
|
||||||
{"id": "calendar", "title": "Calendar"},
|
{"id": "calendar", "title": "Calendar"}
|
||||||
{"id": "files", "title": "Files", "admin": true}
|
|
||||||
],
|
],
|
||||||
"layers": [
|
"layers": [
|
||||||
{
|
{
|
||||||
|
@ -448,6 +447,10 @@
|
||||||
{"id": "map", "title": "on Map"},
|
{"id": "map", "title": "on Map"},
|
||||||
{"id": "calendar", "title": "on Calendar"}
|
{"id": "calendar", "title": "on Calendar"}
|
||||||
],
|
],
|
||||||
|
"media": {
|
||||||
|
"importMoviePosters": true,
|
||||||
|
"importPosterFrames": true
|
||||||
|
},
|
||||||
"site": {
|
"site": {
|
||||||
"id": "{{settings.SITEID}}",
|
"id": "{{settings.SITEID}}",
|
||||||
"name": "{{settings.SITENAME}}",
|
"name": "{{settings.SITENAME}}",
|
||||||
|
|
|
@ -161,6 +161,8 @@ class Item(models.Model):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def editable(self, user):
|
def editable(self, user):
|
||||||
|
if user.is_anonymous():
|
||||||
|
return False
|
||||||
if user.is_staff or \
|
if user.is_staff or \
|
||||||
self.user == user or \
|
self.user == user or \
|
||||||
self.groups.filter(id__in=user.groups.all()).count() > 0:
|
self.groups.filter(id__in=user.groups.all()).count() > 0:
|
||||||
|
@ -303,18 +305,18 @@ class Item(models.Model):
|
||||||
|
|
||||||
def get_posters(self):
|
def get_posters(self):
|
||||||
url = self.prefered_poster_url()
|
url = self.prefered_poster_url()
|
||||||
precedence = []
|
index = []
|
||||||
services = [p['service']
|
services = [p['service']
|
||||||
for p in self.poster_urls.values("service")
|
for p in self.poster_urls.values("service")
|
||||||
.annotate(Count("id")).order_by()]
|
.annotate(Count("id")).order_by()]
|
||||||
for service in settings.POSTER_PRECEDENCE:
|
for service in settings.POSTER_PRECEDENCE:
|
||||||
if service in services:
|
if service in services:
|
||||||
precedence.append(service)
|
index.append(service)
|
||||||
for service in services:
|
for service in services:
|
||||||
if service not in precedence:
|
if service not in index:
|
||||||
precedence.append(service)
|
index.append(service)
|
||||||
if settings.URL not in precedence:
|
if settings.URL not in index:
|
||||||
precedence.append(settings.URL)
|
index.append(settings.URL)
|
||||||
|
|
||||||
posters = [
|
posters = [
|
||||||
{
|
{
|
||||||
|
@ -323,7 +325,7 @@ class Item(models.Model):
|
||||||
'height': 1024,
|
'height': 1024,
|
||||||
'source': settings.URL,
|
'source': settings.URL,
|
||||||
'selected': url == None,
|
'selected': url == None,
|
||||||
'precedence': precedence.index(settings.URL)
|
'index': index.index(settings.URL)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
got = {}
|
got = {}
|
||||||
|
@ -336,9 +338,9 @@ class Item(models.Model):
|
||||||
'height': p.height,
|
'height': p.height,
|
||||||
'source': p.service,
|
'source': p.service,
|
||||||
'selected': p.url == url,
|
'selected': p.url == url,
|
||||||
'precedence': precedence.index(p.service)
|
'index': index.index(p.service)
|
||||||
})
|
})
|
||||||
posters.sort(key=lambda a: a['precedence'])
|
posters.sort(key=lambda a: a['index'])
|
||||||
return posters
|
return posters
|
||||||
|
|
||||||
def get_stream(self):
|
def get_stream(self):
|
||||||
|
@ -404,7 +406,7 @@ class Item(models.Model):
|
||||||
p = 0
|
p = 0
|
||||||
for f in frames:
|
for f in frames:
|
||||||
i['frames'].append({
|
i['frames'].append({
|
||||||
'id': p,
|
'index': p,
|
||||||
'position': f['position'],
|
'position': f['position'],
|
||||||
'selected': p == pos,
|
'selected': p == pos,
|
||||||
'url': '/%s/frame/poster/%d.jpg' %(self.itemId, p),
|
'url': '/%s/frame/poster/%d.jpg' %(self.itemId, p),
|
||||||
|
@ -810,7 +812,11 @@ class Item(models.Model):
|
||||||
if self.poster:
|
if self.poster:
|
||||||
path = self.poster.path
|
path = self.poster.path
|
||||||
self.poster.delete()
|
self.poster.delete()
|
||||||
for f in glob(path.replace('.jpg', '*.jpg')):
|
else:
|
||||||
|
poster= self.path('poster.jpg')
|
||||||
|
path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster))
|
||||||
|
posters = glob(path.replace('.jpg', '*.jpg'))
|
||||||
|
for f in filter(lambda p: not p.endswith('poster.local.jpg'), posters):
|
||||||
os.unlink(f)
|
os.unlink(f)
|
||||||
|
|
||||||
def prefered_poster_url(self):
|
def prefered_poster_url(self):
|
||||||
|
@ -826,20 +832,14 @@ class Item(models.Model):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def make_poster(self, force=False):
|
def make_poster(self, force=False):
|
||||||
posters = glob(os.path.abspath(os.path.join(settings.MEDIA_ROOT,
|
|
||||||
self.path('poster.*.jpg'))))
|
|
||||||
for f in filter(lambda p: not p.endswith('poster.local.jpg'), posters):
|
|
||||||
os.unlink(f)
|
|
||||||
if not self.poster or force:
|
if not self.poster or force:
|
||||||
url = self.prefered_poster_url()
|
url = self.prefered_poster_url()
|
||||||
if url:
|
if url:
|
||||||
data = ox.net.readUrl(url)
|
data = ox.net.readUrl(url)
|
||||||
if force:
|
|
||||||
self.delete_poster()
|
self.delete_poster()
|
||||||
self.poster.save('poster.jpg', ContentFile(data))
|
self.poster.save('poster.jpg', ContentFile(data))
|
||||||
self.save()
|
self.save()
|
||||||
else:
|
else:
|
||||||
if force:
|
|
||||||
self.delete_poster()
|
self.delete_poster()
|
||||||
poster = self.make_local_poster()
|
poster = self.make_local_poster()
|
||||||
with open(poster) as f:
|
with open(poster) as f:
|
||||||
|
@ -896,8 +896,9 @@ class Item(models.Model):
|
||||||
def get_poster_frame_path(self):
|
def get_poster_frame_path(self):
|
||||||
frames = self.poster_frames()
|
frames = self.poster_frames()
|
||||||
if self.poster_frame >= 0:
|
if self.poster_frame >= 0:
|
||||||
if frames:
|
if frames and len(frames) > int(self.poster_frame):
|
||||||
return frames[int(self.poster_frame)]['path']
|
return frames[int(self.poster_frame)]['path']
|
||||||
|
else:
|
||||||
size = int(settings.VIDEO_PROFILE.split('.')[0][:-1])
|
size = int(settings.VIDEO_PROFILE.split('.')[0][:-1])
|
||||||
return self.frame(self.poster_frame, size)
|
return self.frame(self.poster_frame, size)
|
||||||
|
|
||||||
|
|
|
@ -452,7 +452,7 @@ def setPosterFrame(request): #parse path and return info
|
||||||
#FIXME: some things need to be updated after changing this
|
#FIXME: some things need to be updated after changing this
|
||||||
item.poster_frame = data['position']
|
item.poster_frame = data['position']
|
||||||
item.save()
|
item.save()
|
||||||
tasks.update_poster.delay(item.itemId)
|
tasks.update_poster(item.itemId)
|
||||||
response = json_response()
|
response = json_response()
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='permissino denied')
|
response = json_response(status=403, text='permissino denied')
|
||||||
|
|
Loading…
Reference in a new issue