new frame urls

This commit is contained in:
rlx 2011-08-06 18:17:22 +00:00
commit b78b73da8a
5 changed files with 13 additions and 9 deletions

View file

@ -676,16 +676,17 @@ class Item(models.Model):
Video related functions
'''
def frame(self, position, width=128):
def frame(self, position, height=128):
stream = self.streams.filter(profile=settings.VIDEO_PROFILE)
if stream.count()>0:
stream = stream[0]
else:
return None
height = min(height, stream.height())
path = os.path.join(settings.MEDIA_ROOT, self.path(),
'frames', "%d"%width, "%s.jpg"%position)
'frames', "%dp"%height, "%s.jpg"%position)
if not os.path.exists(path):
extract.frame(stream.video.path, path, position, width)
extract.frame(stream.video.path, path, position, height)
if not os.path.exists(path):
path = os.path.join(settings.STATIC_ROOT, 'png/frame.broken.png')
return path
@ -1091,6 +1092,9 @@ class Stream(models.Model):
def path(self):
return self.item.path(self.profile)
def height(self):
return int(self.profile.split('p')[0])
def extract_derivatives(self):
for profile in settings.VIDEO_DERIVATIVES:
derivative, created = Stream.objects.get_or_create(profile=profile, item=self.item)

View file

@ -6,7 +6,7 @@ from django.conf.urls.defaults import *
urlpatterns = patterns("item.views",
#frames
(r'^(?P<id>[A-Z0-9].+)/frame(?P<size>\d+)p(?P<position>[\d\.]+)\.jpg$', 'frame'),
(r'^(?P<id>[A-Z0-9].+)/(?P<size>\d+)p(?P<position>[\d\.]+)\.jpg$', 'frame'),
#timelines
(r'^(?P<id>[A-Z0-9].+)/timeline(?P<size>\d+)p(?P<position>\d+)\.png$', 'timeline'),