cleanup streams
This commit is contained in:
parent
d186ab42d8
commit
2a6a48f135
2 changed files with 30 additions and 30 deletions
|
@ -472,6 +472,8 @@ class Stream(models.Model):
|
|||
source = models.ForeignKey('Stream', related_name='derivatives', default=None, null=True)
|
||||
available = models.BooleanField(default=False)
|
||||
info = fields.DictField(default={})
|
||||
duration = models.FloatField(default=0)
|
||||
aspect_ratio = models.FloatField(default=0)
|
||||
|
||||
@property
|
||||
def timeline_prefix(self):
|
||||
|
@ -518,8 +520,24 @@ class Stream(models.Model):
|
|||
def save(self, *args, **kwargs):
|
||||
if self.video and not self.info:
|
||||
self.info = ox.avinfo(self.video.path)
|
||||
self.duration = self.info.get('duration', 0)
|
||||
if 'video' in self.info and self.info['video']:
|
||||
self.aspect_ratio = self.info['video'][0]['width'] / self.info['video'][0]['height']
|
||||
else:
|
||||
self.aspect_ratio = 128/80
|
||||
super(Stream, self).save(*args, **kwargs)
|
||||
|
||||
def json(self):
|
||||
if settings.XSENDFILE or settings.XACCELREDIRECT:
|
||||
base_url = '/%s' % self.itemId
|
||||
else:
|
||||
base_url = os.path.dirname(self.video.url)
|
||||
return {
|
||||
'duration': self.duration,
|
||||
'aspectRatio': self.aspect_ratio,
|
||||
'baseUrl': base_url
|
||||
}
|
||||
|
||||
def delete_stream(sender, **kwargs):
|
||||
f = kwargs['instance']
|
||||
if f.video:
|
||||
|
|
|
@ -295,7 +295,6 @@ class Item(models.Model):
|
|||
shutil.rmtree(path)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.streams.all().delete()
|
||||
self.delete_files()
|
||||
super(Item, self).delete(*args, **kwargs)
|
||||
|
||||
|
@ -391,21 +390,8 @@ class Item(models.Model):
|
|||
return frames
|
||||
|
||||
def get_stream(self):
|
||||
stream = {}
|
||||
videos = self.main_videos()
|
||||
for video in videos:
|
||||
s = video.streams.all()[0]
|
||||
if s.video and s.info:
|
||||
stream['duration'] = s.info['duration']
|
||||
if 'video' in s.info and s.info['video']:
|
||||
stream['aspectRatio'] = s.info['video'][0]['width'] / s.info['video'][0]['height']
|
||||
else:
|
||||
stream['aspectRatio'] = 128/80
|
||||
if settings.XSENDFILE or settings.XACCELREDIRECT:
|
||||
stream['baseUrl'] = '/%s' % self.itemId
|
||||
else:
|
||||
stream['baseUrl'] = os.path.dirname(s.video.url)
|
||||
return stream
|
||||
for s in self.streams():
|
||||
return s.json()
|
||||
|
||||
def get_layers(self, user=None):
|
||||
layers = {}
|
||||
|
@ -450,9 +436,8 @@ class Item(models.Model):
|
|||
if not keys or 'poster' in keys:
|
||||
i['poster'] = self.get_poster()
|
||||
|
||||
videos = self.main_videos()
|
||||
i['duration'] = sum([v.duration for v in videos])
|
||||
i['durations'] = [v.duration for v in videos]
|
||||
i['durations'] = [s.duration for s in self.streams()]
|
||||
i['duration'] = sum(i['durations'])
|
||||
i['apsectRatio'] = i.get('aspectratio')
|
||||
|
||||
#only needed by admins
|
||||
|
@ -704,18 +689,12 @@ class Item(models.Model):
|
|||
'''
|
||||
def frame(self, position, height=128):
|
||||
offset = 0
|
||||
videos = self.main_videos()
|
||||
for video in videos:
|
||||
if video.duration + offset < position:
|
||||
offset += video.duration
|
||||
streams = self.streams()
|
||||
for stream in streams:
|
||||
if stream.duration + offset < position:
|
||||
offset += stream.duration
|
||||
else:
|
||||
position = position - offset
|
||||
stream = video.streams.filter(resolution=settings.VIDEO_RESOLUTIONS[0],
|
||||
format=settings.VIDEO_FORMATS[0])
|
||||
if stream.count()>0:
|
||||
stream = stream[0]
|
||||
else:
|
||||
return None
|
||||
height = min(height, stream.resolution)
|
||||
path = os.path.join(settings.MEDIA_ROOT, stream.path(),
|
||||
'frames', "%dp"%height, "%s.jpg"%position)
|
||||
|
@ -812,6 +791,9 @@ class Item(models.Model):
|
|||
self.torrent.name = self.path('torrent/%s.torrent' % self.get('title'))
|
||||
self.save()
|
||||
|
||||
def streams(self):
|
||||
return [video.streams.filter(source=None)[0] for video in self.main_videos()]
|
||||
|
||||
def update_streams(self, force=False):
|
||||
files = {}
|
||||
for f in self.main_videos():
|
||||
|
|
Loading…
Reference in a new issue