From f5cd0cf2cada6b8e2b40285a9711937e1ae1bf0c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 12 Mar 2013 09:36:00 +0000 Subject: [PATCH] load subtitles in sync with creating timeline, use stream duration for files --- pandora/archive/models.py | 6 ++++-- pandora/archive/views.py | 3 ++- pandora/item/models.py | 13 +++++++++---- pandora/item/tasks.py | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 7e322bfc..f7321d0a 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -203,9 +203,11 @@ class File(models.Model): if self.type not in ('audio', 'video'): self.duration = None - elif self.duration <= 0: - self.duration = sum([s.info.get('duration',0) + else: + duration = sum([s.info.get('duration', 0) for s in self.streams.filter(source=None)]) + if duration: + self.duration = duration if self.is_subtitle: self.available = self.data and True or False diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 626c2647..f6103839 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -170,7 +170,8 @@ def addFile(request): ''' takes { id: oshash - title: + filename: string, + item: string info: {} } returns { diff --git a/pandora/item/models.py b/pandora/item/models.py index 64f00b9a..6ff33a9c 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1000,7 +1000,8 @@ class Item(models.Model): update = True if update: self.rendered = False - self.update_timeline() + self.save() + tasks.update_timeline.delay(self.itemId) break def get_torrent(self, request): @@ -1074,7 +1075,7 @@ class Item(models.Model): Q(file__is_audio=True)|Q(file__is_video=True) ).order_by('file__part', 'file__sort_path') - def update_timeline(self, force=False): + def update_timeline(self, force=False, async=True): streams = self.streams() self.make_timeline() if streams.count() == 1: @@ -1104,8 +1105,12 @@ class Item(models.Model): self.make_torrent() self.rendered = streams.count() > 0 self.save() - tasks.load_subtitles.delay(self.itemId) - get_sequences.delay(self.itemId) + if async: + tasks.load_subtitles.delay(self.itemId) + get_sequences.delay(self.itemId) + else: + tasks.load_subtitles(self.itemId) + get_sequences(self.itemId) def save_poster(self, data): self.poster.name = self.path('poster.jpg') diff --git a/pandora/item/tasks.py b/pandora/item/tasks.py index 14dff5d7..9e4cf2e2 100644 --- a/pandora/item/tasks.py +++ b/pandora/item/tasks.py @@ -68,10 +68,10 @@ def update_external(itemId): item = models.Item.objects.get(itemId=itemId) item.update_external() -@task(queue="default") +@task(queue="encoding") def update_timeline(itemId): item = models.Item.objects.get(itemId=itemId) - item.update_timeline() + item.update_timeline(async=False) @task(queue="encoding") def rebuild_timeline(itemId):