From ea13a9db8b037eabb8d96aaca1fecadf5d3d524a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 20 Aug 2011 12:06:18 +0200 Subject: [PATCH] reload subtitles --- pandora/0xdb.json | 1 + pandora/item/models.py | 44 +++++++++++++++++++++++++++++++++++++++++- pandora/item/tasks.py | 37 +---------------------------------- pandora/padma.json | 1 + 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/pandora/0xdb.json b/pandora/0xdb.json index f2cba729..d0e92466 100644 --- a/pandora/0xdb.json +++ b/pandora/0xdb.json @@ -558,6 +558,7 @@ }, "userLevels": ["guest", "member", "staff", "admin"], "video": { + "download": false, "formats": ["webm", "mp4"], "resolutions": [96] } diff --git a/pandora/item/models.py b/pandora/item/models.py index 2374d7f4..7635fbc9 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -13,7 +13,7 @@ import unicodedata from urllib import quote from django.db import models -from django.db.models import Sum, Count +from django.db.models import Count, Q, Sum from django.core.files.base import ContentFile from django.utils import simplejson as json from django.conf import settings @@ -795,14 +795,19 @@ class Item(models.Model): return [video.streams.filter(source=None)[0] for video in self.main_videos()] def update_timeline(self, force=False): + config = site_config() streams = self.streams() self.make_timeline() self.data['cuts'] = extract.cuts(self.timeline_prefix) self.data['color'] = extract.average_color(self.timeline_prefix) #extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8]) + self.select_frame() self.make_local_poster() self.make_poster() self.make_icon() + if config['video']['download']: + self.make_torrent() + self.load_subtitles() self.rendered = streams != [] self.save() @@ -963,6 +968,43 @@ class Item(models.Model): os.unlink(f) return icon + def load_subtitles(self): + layer = Layer.objects.get(name='subtitles') + Annotation.objects.filter(layer=layer,item=self).delete() + offset = 0 + language = '' + languages = [f.language for f in self.files.filter(is_main=True, is_subtitle=True, + available=True)] + if languages: + if 'en' in languages: + language = 'en' + elif '' in languages: + language = '' + else: + language = languages[0] + for f in self.files.filter(is_main=True, is_subtitle=True, + available=True, language=language).order_by('part'): + user = f.instances.all()[0].volume.user + for data in f.srt(offset): + annotation = Annotation( + item=f.item, + layer=layer, + start=data['in'], + end=data['out'], + value=data['value'], + user=user + ) + annotation.save() + duration = self.files.filter(Q(is_audio=True)|Q(is_video=True)) \ + .filter(is_main=True, available=True, part=f.part) + if duration: + duration = duration[0].duration + else: + Annotation.objects.filter(layer=layer,item=self).delete() + break + offset += duration + self.update_find() + def delete_item(sender, **kwargs): i = kwargs['instance'] i.delete_files() diff --git a/pandora/item/tasks.py b/pandora/item/tasks.py index 06a47d33..1d71eaac 100644 --- a/pandora/item/tasks.py +++ b/pandora/item/tasks.py @@ -3,7 +3,6 @@ from datetime import timedelta from celery.decorators import task, periodic_task -from django.db.models import Q import models @@ -32,39 +31,5 @@ def update_timeline(itemId): def load_subtitles(itemId): item = models.Item.objects.get(itemId=itemId) - layer = models.Layer.objects.get(name='subtitles') - models.Annotation.objects.filter(layer=layer,item=item).delete() - offset = 0 - language = '' - languages = [f.language for f in item.files.filter(is_main=True, is_subtitle=True, - available=True)] - if languages: - if 'en' in languages: - language = 'en' - elif '' in languages: - language = '' - else: - language = languages[0] - for f in item.files.filter(is_main=True, is_subtitle=True, - available=True, language=language).order_by('part'): - user = f.instances.all()[0].volume.user - for data in f.srt(offset): - annotation = models.Annotation( - item=f.item, - layer=layer, - start=data['in'], - end=data['out'], - value=data['value'], - user=user - ) - annotation.save() - duration = item.files.filter(Q(is_audio=True)|Q(is_video=True)) \ - .filter(is_main=True, available=True, part=f.part) - if duration: - duration = duration[0].duration - else: - models.Annotation.objects.filter(layer=layer,item=item).delete() - break - offset += duration - item.update_find() + item.load_subtitles() diff --git a/pandora/padma.json b/pandora/padma.json index 9c4993c7..d83fac99 100644 --- a/pandora/padma.json +++ b/pandora/padma.json @@ -446,6 +446,7 @@ }, "userLevels": ["guest", "member", "staff", "admin"], "video": { + "download": true, "formats": ["webm", "mp4"], "resolutions": [480, 240, 96] }