load subtitles in sync with creating timeline, use stream duration for files

This commit is contained in:
j 2013-03-12 09:36:00 +00:00
parent 6ab2ae3c54
commit f5cd0cf2ca
4 changed files with 17 additions and 9 deletions

View file

@ -203,9 +203,11 @@ class File(models.Model):
if self.type not in ('audio', 'video'): if self.type not in ('audio', 'video'):
self.duration = None self.duration = None
elif self.duration <= 0: else:
self.duration = sum([s.info.get('duration',0) duration = sum([s.info.get('duration', 0)
for s in self.streams.filter(source=None)]) for s in self.streams.filter(source=None)])
if duration:
self.duration = duration
if self.is_subtitle: if self.is_subtitle:
self.available = self.data and True or False self.available = self.data and True or False

View file

@ -170,7 +170,8 @@ def addFile(request):
''' '''
takes { takes {
id: oshash id: oshash
title: filename: string,
item: string
info: {} info: {}
} }
returns { returns {

View file

@ -1000,7 +1000,8 @@ class Item(models.Model):
update = True update = True
if update: if update:
self.rendered = False self.rendered = False
self.update_timeline() self.save()
tasks.update_timeline.delay(self.itemId)
break break
def get_torrent(self, request): def get_torrent(self, request):
@ -1074,7 +1075,7 @@ class Item(models.Model):
Q(file__is_audio=True)|Q(file__is_video=True) Q(file__is_audio=True)|Q(file__is_video=True)
).order_by('file__part', 'file__sort_path') ).order_by('file__part', 'file__sort_path')
def update_timeline(self, force=False): def update_timeline(self, force=False, async=True):
streams = self.streams() streams = self.streams()
self.make_timeline() self.make_timeline()
if streams.count() == 1: if streams.count() == 1:
@ -1104,8 +1105,12 @@ class Item(models.Model):
self.make_torrent() self.make_torrent()
self.rendered = streams.count() > 0 self.rendered = streams.count() > 0
self.save() self.save()
if async:
tasks.load_subtitles.delay(self.itemId) tasks.load_subtitles.delay(self.itemId)
get_sequences.delay(self.itemId) get_sequences.delay(self.itemId)
else:
tasks.load_subtitles(self.itemId)
get_sequences(self.itemId)
def save_poster(self, data): def save_poster(self, data):
self.poster.name = self.path('poster.jpg') self.poster.name = self.path('poster.jpg')

View file

@ -68,10 +68,10 @@ def update_external(itemId):
item = models.Item.objects.get(itemId=itemId) item = models.Item.objects.get(itemId=itemId)
item.update_external() item.update_external()
@task(queue="default") @task(queue="encoding")
def update_timeline(itemId): def update_timeline(itemId):
item = models.Item.objects.get(itemId=itemId) item = models.Item.objects.get(itemId=itemId)
item.update_timeline() item.update_timeline(async=False)
@task(queue="encoding") @task(queue="encoding")
def rebuild_timeline(itemId): def rebuild_timeline(itemId):