local poster
This commit is contained in:
parent
a8ca5a1ef8
commit
6abbaa57cc
3 changed files with 72 additions and 68 deletions
|
@ -308,20 +308,17 @@ class Item(models.Model):
|
||||||
return poster
|
return poster
|
||||||
|
|
||||||
def get_posters(self):
|
def get_posters(self):
|
||||||
posters = {}
|
posters = {
|
||||||
|
'local': [{
|
||||||
|
'url': '/%s/poster.pandora.jpg' % self.itemId,
|
||||||
|
'width': 640,
|
||||||
|
'height': 1024,
|
||||||
|
}]
|
||||||
|
}
|
||||||
for p in self.poster_urls.all():
|
for p in self.poster_urls.all():
|
||||||
if p.service not in posters:
|
if p.service not in posters:
|
||||||
posters[p.service] = []
|
posters[p.service] = []
|
||||||
posters[p.service].append({'url': p.url, 'width': p.width, 'height': p.height})
|
posters[p.service].append({'url': p.url, 'width': p.width, 'height': p.height})
|
||||||
local_posters = self.local_posters().keys()
|
|
||||||
if local_posters:
|
|
||||||
posters['local'] = []
|
|
||||||
for p in local_posters:
|
|
||||||
#FIXME: media_url is no longer public
|
|
||||||
url = p.replace(settings.MEDIA_ROOT, settings.MEDIA_URL)
|
|
||||||
width = 640
|
|
||||||
height = 1024
|
|
||||||
posters['local'].append({'url': url, 'width': width, 'height': height})
|
|
||||||
return posters
|
return posters
|
||||||
|
|
||||||
def get_stream(self):
|
def get_stream(self):
|
||||||
|
@ -374,6 +371,8 @@ class Item(models.Model):
|
||||||
|
|
||||||
i['poster'] = self.get_poster()
|
i['poster'] = self.get_poster()
|
||||||
i['posters'] = self.get_posters()
|
i['posters'] = self.get_posters()
|
||||||
|
i['posterFrames'] = ['/%s/frame/poster/%d.jpg' %(self.itemId, p)
|
||||||
|
for p in range(0, len(self.poster_frames()))]
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
@ -730,7 +729,7 @@ class Item(models.Model):
|
||||||
#extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8])
|
#extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8])
|
||||||
|
|
||||||
stream.extract_derivatives()
|
stream.extract_derivatives()
|
||||||
self.make_local_posters()
|
self.make_local_poster()
|
||||||
self.make_poster()
|
self.make_poster()
|
||||||
self.make_icon()
|
self.make_icon()
|
||||||
self.rendered = files != {}
|
self.rendered = files != {}
|
||||||
|
@ -790,45 +789,22 @@ class Item(models.Model):
|
||||||
else:
|
else:
|
||||||
if force:
|
if force:
|
||||||
self.delete_poster()
|
self.delete_poster()
|
||||||
local_posters = self.make_local_posters()
|
poster = self.make_local_poster()
|
||||||
if local_posters:
|
with open(poster) as f:
|
||||||
with open(local_posters[0]) as f:
|
|
||||||
self.poster.save('poster.jpg', ContentFile(f.read()))
|
self.poster.save('poster.jpg', ContentFile(f.read()))
|
||||||
|
|
||||||
def local_posters(self):
|
def make_local_poster(self):
|
||||||
part = 1
|
poster = self.path('poster.local.jpg')
|
||||||
posters = {}
|
poster = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster))
|
||||||
timeline = self.path('timeline.64.png')
|
|
||||||
timeline = os.path.abspath(os.path.join(settings.MEDIA_ROOT, timeline))
|
|
||||||
if not os.path.exists(timeline):
|
|
||||||
path = self.path('poster.pandora.jpg')
|
|
||||||
path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path))
|
|
||||||
posters[path] = False
|
|
||||||
return posters
|
|
||||||
if self.poster_frame >= 0:
|
|
||||||
frame = self.get_poster_frame_path()
|
|
||||||
path = self.path('poster.pandora.%s.%s.jpg'%(part, self.poster_frame))
|
|
||||||
path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path))
|
|
||||||
posters[path] = frame
|
|
||||||
else:
|
|
||||||
for f in self.main_videos():
|
|
||||||
for frame in f.frames.all():
|
|
||||||
path = self.path('poster.pandora.%s.%s.jpg'%(part, frame.position))
|
|
||||||
path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path))
|
|
||||||
posters[path] = frame.frame.path
|
|
||||||
part += 1
|
|
||||||
return posters
|
|
||||||
|
|
||||||
def make_local_posters(self):
|
frame = self.get_poster_frame_path()
|
||||||
posters = self.local_posters()
|
|
||||||
timeline = self.path('timeline.64.png')
|
timeline = self.path('timeline.64.png')
|
||||||
timeline = os.path.abspath(os.path.join(settings.MEDIA_ROOT, timeline))
|
timeline = os.path.abspath(os.path.join(settings.MEDIA_ROOT, timeline))
|
||||||
ox.makedirs(os.path.join(settings.MEDIA_ROOT,self.path()))
|
|
||||||
for poster in posters:
|
director = u', '.join(self.get('director', ['Unknown Director']))
|
||||||
frame = posters[poster]
|
|
||||||
cmd = [settings.ITEM_POSTER,
|
cmd = [settings.ITEM_POSTER,
|
||||||
'-t', self.get('title').encode('utf-8'),
|
'-t', self.get('title').encode('utf-8'),
|
||||||
'-d', u', '.join(self.get('director', ['Unknown Director'])).encode('utf-8'),
|
'-d', director.encode('utf-8'),
|
||||||
'-y', str(self.get('year', '')),
|
'-y', str(self.get('year', '')),
|
||||||
'-p', poster
|
'-p', poster
|
||||||
]
|
]
|
||||||
|
@ -843,19 +819,24 @@ class Item(models.Model):
|
||||||
cmd += ['-o', self.oxdbId]
|
cmd += ['-o', self.oxdbId]
|
||||||
else:
|
else:
|
||||||
cmd += ['-i', self.itemId]
|
cmd += ['-i', self.itemId]
|
||||||
|
ox.makedirs(os.path.join(settings.MEDIA_ROOT,self.path()))
|
||||||
p = subprocess.Popen(cmd)
|
p = subprocess.Popen(cmd)
|
||||||
p.wait()
|
p.wait()
|
||||||
return posters.keys()
|
return poster
|
||||||
|
|
||||||
|
def poster_frames(self):
|
||||||
|
frames = []
|
||||||
|
for f in self.main_videos():
|
||||||
|
for ff in f.frames.all():
|
||||||
|
frames.append(ff.frame.path)
|
||||||
|
return frames
|
||||||
|
|
||||||
def get_poster_frame_path(self):
|
def get_poster_frame_path(self):
|
||||||
if self.poster_frame >= 0:
|
if self.poster_frame >= 0:
|
||||||
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)
|
||||||
|
|
||||||
frames = []
|
frames = self.poster_frames()
|
||||||
for f in self.main_videos():
|
|
||||||
for ff in f.frames.all():
|
|
||||||
frames.append(ff.frame.path)
|
|
||||||
if frames:
|
if frames:
|
||||||
return frames[int(len(frames)/2)]
|
return frames[int(len(frames)/2)]
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,13 @@ from django.conf.urls.defaults import *
|
||||||
|
|
||||||
urlpatterns = patterns("item.views",
|
urlpatterns = patterns("item.views",
|
||||||
(r'^(?P<id>[A-Z0-9].*)/frame/(?P<size>\d+)/(?P<position>[0-9\.,]+).jpg$', 'frame'),
|
(r'^(?P<id>[A-Z0-9].*)/frame/(?P<size>\d+)/(?P<position>[0-9\.,]+).jpg$', 'frame'),
|
||||||
|
(r'^(?P<id>[A-Z0-9].*)/frame/poster/(?P<position>\d+).jpg$', 'poster_frame'),
|
||||||
(r'^(?P<id>[A-Z0-9].*)/(?P<oshash>[a-f0-9]+)/(?P<profile>.*\.(?P<format>webm|ogv|mp4))$', 'video'),
|
(r'^(?P<id>[A-Z0-9].*)/(?P<oshash>[a-f0-9]+)/(?P<profile>.*\.(?P<format>webm|ogv|mp4))$', 'video'),
|
||||||
(r'^(?P<id>[A-Z0-9][A-Za-z0-9]+)/torrent/(?P<filename>.*?)$', 'torrent'),
|
(r'^(?P<id>[A-Z0-9][A-Za-z0-9]+)/torrent/(?P<filename>.*?)$', 'torrent'),
|
||||||
(r'^(?P<id>[A-Z0-9].*)/(?P<profile>.*\.(?P<format>webm|ogv|mp4))$', 'video'),
|
(r'^(?P<id>[A-Z0-9].*)/(?P<profile>.*\.(?P<format>webm|ogv|mp4))$', 'video'),
|
||||||
(r'^(?P<id>[A-Z0-9].*)/poster\.(?P<size>\d+)\.jpg$', 'poster'),
|
(r'^(?P<id>[A-Z0-9].*)/poster\.(?P<size>\d+)\.jpg$', 'poster'),
|
||||||
(r'^(?P<id>[A-Z0-9].*)/poster\.(?P<size>large)\.jpg$', 'poster'),
|
(r'^(?P<id>[A-Z0-9].*)/poster\.(?P<size>large)\.jpg$', 'poster'),
|
||||||
|
(r'^(?P<id>[A-Z0-9].*)/poster\.pandora\.jpg$', 'poster_local'),
|
||||||
(r'^(?P<id>[A-Z0-9].*)/poster\.jpg$', 'poster'),
|
(r'^(?P<id>[A-Z0-9].*)/poster\.jpg$', 'poster'),
|
||||||
(r'^(?P<id>[A-Z0-9].*)/icon\.(?P<size>\d+)\.jpg$', 'icon'),
|
(r'^(?P<id>[A-Z0-9].*)/icon\.(?P<size>\d+)\.jpg$', 'icon'),
|
||||||
(r'^(?P<id>[A-Z0-9].*)/icon\.jpg$', 'icon'),
|
(r'^(?P<id>[A-Z0-9].*)/icon\.jpg$', 'icon'),
|
||||||
|
|
|
@ -448,6 +448,7 @@ def setPoster(request): #parse path and return info
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
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()
|
||||||
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.poster_urls.all()]
|
||||||
if data['url'] in valid_urls:
|
if data['url'] in valid_urls:
|
||||||
|
@ -458,6 +459,11 @@ 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:
|
||||||
|
@ -529,6 +535,16 @@ def frame(request, id, position, size):
|
||||||
raise Http404
|
raise Http404
|
||||||
return HttpFileResponse(frame, content_type='image/jpeg')
|
return HttpFileResponse(frame, content_type='image/jpeg')
|
||||||
|
|
||||||
|
def poster_frame(request, id, position):
|
||||||
|
item = get_object_or_404(models.Item, itemId=id)
|
||||||
|
position = int(position)
|
||||||
|
frames = item.poster_frames()
|
||||||
|
print frames, position
|
||||||
|
if frames and len(frames) > position:
|
||||||
|
frame = frames[position]
|
||||||
|
return HttpFileResponse(frame, content_type='image/jpeg')
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
|
||||||
def image_to_response(item, image, size=None):
|
def image_to_response(item, image, size=None):
|
||||||
if size:
|
if size:
|
||||||
|
@ -543,6 +559,11 @@ def image_to_response(item, image, size=None):
|
||||||
path = image.path
|
path = image.path
|
||||||
return HttpFileResponse(path, content_type='image/jpeg')
|
return HttpFileResponse(path, content_type='image/jpeg')
|
||||||
|
|
||||||
|
def poster_local(request, id):
|
||||||
|
item = get_object_or_404(models.Item, itemId=id)
|
||||||
|
poster = item.path('poster.local.jpg')
|
||||||
|
poster = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster))
|
||||||
|
return HttpFileResponse(poster, content_type='image/jpeg')
|
||||||
|
|
||||||
def poster(request, id, size=None):
|
def poster(request, id, size=None):
|
||||||
item = get_object_or_404(models.Item, itemId=id)
|
item = get_object_or_404(models.Item, itemId=id)
|
||||||
|
|
Loading…
Reference in a new issue