forked from 0x2620/pandora
more .path
This commit is contained in:
parent
26c654615f
commit
6d3f1b9c40
2 changed files with 15 additions and 14 deletions
|
@ -138,8 +138,8 @@ class File(models.Model):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
#upload and data handling
|
#upload and data handling
|
||||||
video = models.FileField(null=True, blank=True, upload_to=lambda f, x: f.path(name='%s.webm'%settings.VIDEO_PROFILE))
|
video = models.FileField(null=True, blank=True, upload_to=lambda f, x: f.path('%s.webm'%settings.VIDEO_PROFILE))
|
||||||
data = models.FileField(null=True, blank=True, upload_to=lambda f, x: f.path(name='data.bin'))
|
data = models.FileField(null=True, blank=True, upload_to=lambda f, x: f.path('data.bin'))
|
||||||
|
|
||||||
def path(self, name):
|
def path(self, name):
|
||||||
h = self.oshash
|
h = self.oshash
|
||||||
|
|
|
@ -232,7 +232,7 @@ class Item(models.Model):
|
||||||
external_data = fields.DictField(default={}, editable=False)
|
external_data = fields.DictField(default={}, editable=False)
|
||||||
data = fields.DictField(default={}, editable=False)
|
data = fields.DictField(default={}, editable=False)
|
||||||
json = fields.DictField(default={}, editable=False)
|
json = fields.DictField(default={}, editable=False)
|
||||||
poster = models.ImageField(default=None, blank=True, upload_to=lambda m, x: os.path.join(itemid_path(m.itemId), "poster.jpg"))
|
poster = models.ImageField(default=None, blank=True, upload_to=lambda m, x: m.path("poster.jpg"))
|
||||||
poster_url = models.TextField(blank=True)
|
poster_url = models.TextField(blank=True)
|
||||||
poster_height = models.IntegerField(default=0)
|
poster_height = models.IntegerField(default=0)
|
||||||
poster_width = models.IntegerField(default=0)
|
poster_width = models.IntegerField(default=0)
|
||||||
|
@ -592,19 +592,23 @@ class Item(models.Model):
|
||||||
else:
|
else:
|
||||||
Facet.objects.filter(item=self, key='year').delete()
|
Facet.objects.filter(item=self, key='year').delete()
|
||||||
|
|
||||||
|
def path(self, name=''):
|
||||||
|
return os.path.join('items', h[:2], h[2:4], h[4:6], h[6:])
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Video related functions
|
Video related functions
|
||||||
'''
|
'''
|
||||||
def frame(self, position, width=128):
|
def frame(self, position, width=128):
|
||||||
stream = self.streams.filter(profile=settings.VIDEO_PROFILE+'.webm')[0]
|
stream = self.streams.filter(profile=settings.VIDEO_PROFILE+'.webm')[0]
|
||||||
path = os.path.join(settings.MEDIA_ROOT, itemid_path(self.itemId), 'frames', "%d"%width, "%s.jpg"%position)
|
path = os.path.join(settings.MEDIA_ROOT, self.path(), 'frames', "%d"%width, "%s.jpg"%position)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
extract.frame(stream.video.path, path, position, width)
|
extract.frame(stream.video.path, path, position, width)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timeline_prefix(self):
|
def timeline_prefix(self):
|
||||||
return os.path.join(settings.MEDIA_ROOT, itemid_path(self.itemId), 'timeline')
|
return os.path.join(settings.MEDIA_ROOT, self.path(), 'timeline')
|
||||||
|
|
||||||
def main_videos(self):
|
def main_videos(self):
|
||||||
#FIXME: needs to check if more than one user has main files and only take from "higher" user
|
#FIXME: needs to check if more than one user has main files and only take from "higher" user
|
||||||
|
@ -720,7 +724,7 @@ class Item(models.Model):
|
||||||
posters = {}
|
posters = {}
|
||||||
for f in self.main_videos():
|
for f in self.main_videos():
|
||||||
for frame in f.frames.all():
|
for frame in f.frames.all():
|
||||||
path = os.path.join(itemid_path(self.itemId), 'poster.pandora.%s.%s.jpg'%(part, frame.position))
|
path = self.path('poster.pandora.%s.%s.jpg'%(part, frame.position))
|
||||||
path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path))
|
path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, path))
|
||||||
posters[path] = frame.frame.path
|
posters[path] = frame.frame.path
|
||||||
part += 1
|
part += 1
|
||||||
|
@ -730,7 +734,7 @@ class Item(models.Model):
|
||||||
posters = self.local_posters()
|
posters = self.local_posters()
|
||||||
for poster in posters:
|
for poster in posters:
|
||||||
frame = posters[poster]
|
frame = posters[poster]
|
||||||
timeline = os.path.join(itemid_path(self.itemId), '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))
|
||||||
cmd = [settings.ITEM_POSTER,
|
cmd = [settings.ITEM_POSTER,
|
||||||
'-t', self.get('title'),
|
'-t', self.get('title'),
|
||||||
|
@ -858,19 +862,13 @@ class Collection(models.Model):
|
||||||
def editable(self, user):
|
def editable(self, user):
|
||||||
return self.users.filter(id=user.id).count() > 0
|
return self.users.filter(id=user.id).count() > 0
|
||||||
|
|
||||||
def itemid_path(h):
|
|
||||||
return os.path.join('items', h[:2], h[2:4], h[4:6], h[6:])
|
|
||||||
|
|
||||||
def stream_path(stream):
|
|
||||||
return os.path.join(itemid_path(stream.item.itemId), stream.profile)
|
|
||||||
|
|
||||||
class Stream(models.Model):
|
class Stream(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("item", "profile")
|
unique_together = ("item", "profile")
|
||||||
|
|
||||||
item = models.ForeignKey(Item, related_name='streams')
|
item = models.ForeignKey(Item, related_name='streams')
|
||||||
profile = models.CharField(max_length=255, default='96p.webm')
|
profile = models.CharField(max_length=255, default='96p.webm')
|
||||||
video = models.FileField(default=None, blank=True, upload_to=lambda f, x: stream_path(f))
|
video = models.FileField(default=None, blank=True, upload_to=lambda f, x: f.path())
|
||||||
source = models.ForeignKey('Stream', related_name='derivatives', default=None, null=True)
|
source = models.ForeignKey('Stream', related_name='derivatives', default=None, null=True)
|
||||||
available = models.BooleanField(default=False)
|
available = models.BooleanField(default=False)
|
||||||
info = fields.DictField(default={})
|
info = fields.DictField(default={})
|
||||||
|
@ -878,6 +876,9 @@ class Stream(models.Model):
|
||||||
#def __unicode__(self):
|
#def __unicode__(self):
|
||||||
# return self.video
|
# return self.video
|
||||||
|
|
||||||
|
def path(self):
|
||||||
|
return self.item.(self.profile)
|
||||||
|
|
||||||
def extract_derivatives(self):
|
def extract_derivatives(self):
|
||||||
if settings.VIDEO_H264:
|
if settings.VIDEO_H264:
|
||||||
profile = self.profile.replace('.webm', '.mp4')
|
profile = self.profile.replace('.webm', '.mp4')
|
||||||
|
|
Loading…
Reference in a new issue