This commit is contained in:
j 2011-01-04 13:02:32 +05:30
parent 5916e26203
commit 40d97b5f6b
4 changed files with 63 additions and 13 deletions

View file

@ -236,6 +236,9 @@ class Item(models.Model):
poster_height = models.IntegerField(default=0)
poster_width = models.IntegerField(default=0)
poster_frame = models.FloatField(default=-1)
icon = models.ImageField(default=None, blank=True, upload_to=lambda i, x: i.path("icon.jpg"))
#stream related fields
stream_aspect = models.FloatField(default=4/3)
@ -871,6 +874,30 @@ class Item(models.Model):
p.wait()
return posters.keys()
def make_icon(self):
#FIXME: should take middle or selected frame or som
frames = []
for f in self.main_videos():
for ff in f.frames.all():
frames.append(ff.frame.path)
if frames:
icon = self.path('icon.jpg')
self.icon.name = icon
frame = frames[int(len(frames)/2)]
timeline = self.path('timeline.64.png')
timeline = os.path.abspath(os.path.join(settings.MEDIA_ROOT, timeline))
if os.path.exists(timeline):
cmd = [settings.ITEM_ICON,
'-f', frame,
'-l', timeline,
'-i', self.icon.path
]
p = subprocess.Popen(cmd)
p.wait()
self.save()
return icon
return None
Item.facet_keys = []
Item.person_keys = []
for key in site_config['findKeys']:

View file

@ -11,5 +11,7 @@ urlpatterns = patterns("item.views",
(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\.jpg$', 'poster'),
(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].*)/timelines/(?P<timeline>.+)\.(?P<size>\d+)\.(?P<position>\d+)\.png$', 'timeline'),
)

View file

@ -57,6 +57,7 @@ def _order_query(qs, sort, prefix='sort__'):
qs = qs.order_by(*order_by)
return qs
def _parse_query(data, user):
query = {}
query['range'] = [0, 100]
@ -68,6 +69,7 @@ def _parse_query(data, user):
#group by only allows sorting by name or number of itmes
return query
def _get_positions(ids, get_ids):
positions = {}
for i in get_ids:
@ -77,6 +79,7 @@ def _get_positions(ids, get_ids):
pass
return positions
def find(request):
'''
param data {
@ -222,6 +225,7 @@ Positions
actions.register(find)
def autocomplete(request):
'''
param data
@ -265,6 +269,7 @@ def autocomplete(request):
return render_to_json_response(response)
actions.register(autocomplete)
def getItem(request):
'''
param data
@ -283,6 +288,7 @@ def getItem(request):
return render_to_json_response(response)
actions.register(getItem)
@login_required_json
def editItem(request):
'''
@ -434,21 +440,27 @@ def frame(request, id, position, size):
raise Http404
return HttpFileResponse(frame, content_type='image/jpeg')
def image_to_response(item, image, size=None):
if size:
size = int(size)
path = image.path.replace('.jpg', '.%d.jpg'%size)
if not os.path.exists(path):
image_size = max(image.width, image.height)
if size > image_size:
return redirect('/%s/icon.jpg' % item.itemId)
extract.resize_image(image.path, path, size=size)
else:
path = image.path
return HttpFileResponse(path, content_type='image/jpeg')
def poster(request, id, size=None):
item = get_object_or_404(models.Item, itemId=id)
if size == 'large':
size = None
if item.poster:
if size:
size = int(size)
poster_path = item.poster.path.replace('.jpg', '.%d.jpg'%size)
if not os.path.exists(poster_path):
poster_size = max(item.poster.width, item.poster.height)
if size > poster_size:
return redirect('/%s/poster.jpg' % item.itemId)
extract.resize_image(item.poster.path, poster_path, size=size)
else:
poster_path = item.poster.path
return image_to_response(item, item.poster, size)
else:
if not size:
size='large'
@ -456,6 +468,15 @@ def poster(request, id, size=None):
poster_path = os.path.join(settings.STATIC_ROOT, 'png/posterDark.48.png')
return HttpFileResponse(poster_path, content_type='image/jpeg')
def icon(request, id, size=None):
item = get_object_or_404(models.Item, itemId=id)
if item.icon:
return image_to_response(item, item.icon, size)
else:
raise Http404
def timeline(request, id, timeline, size, position):
item = get_object_or_404(models.Item, itemId=id)
if timeline == 'strip':
@ -464,6 +485,7 @@ def timeline(request, id, timeline, size, position):
timeline = '%s.%s.%04d.png' %(item.timeline_prefix, size, int(position))
return HttpFileResponse(timeline, content_type='image/png')
def video(request, id, profile):
item = get_object_or_404(models.Item, itemId=id)
stream = get_object_or_404(item.streams, profile=profile)
@ -497,4 +519,3 @@ def video(request, id, profile):
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
return response
return HttpFileResponse(path, content_type=content_type)

View file

@ -40,7 +40,7 @@ def render_icon(frame, timeline, icon):
timeline_image = Image.open(timeline)
timeline_image = timeline_image.resize((icon_width, 64), Image.ANTIALIAS)
icon_image.paste(timeline_image, (0, icon_height - 64))
mask_image = Image.open(ox.path.join(static_root, 'png', 'icon.mask.png'))
mask_image = Image.open(os.path.join(static_root, 'png', 'icon.mask.png'))
mask_image = mask_image.resize((icon_width, icon_height))
icon_image.putalpha(mask_image)
icon_image.save(icon)
@ -54,7 +54,7 @@ def main():
if options.icon == None:
parser.print_help()
sys.exit()
render_icon(opt.frame, opt.timeline, opt.icon)
render_icon(options.frame, options.timeline, options.icon)
if __name__ == "__main__":
main()