reload subtitles

This commit is contained in:
j 2011-08-20 12:06:18 +02:00
parent 244dff6217
commit ea13a9db8b
4 changed files with 46 additions and 37 deletions

View file

@ -558,6 +558,7 @@
},
"userLevels": ["guest", "member", "staff", "admin"],
"video": {
"download": false,
"formats": ["webm", "mp4"],
"resolutions": [96]
}

View file

@ -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()

View file

@ -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()

View file

@ -446,6 +446,7 @@
},
"userLevels": ["guest", "member", "staff", "admin"],
"video": {
"download": true,
"formats": ["webm", "mp4"],
"resolutions": [480, 240, 96]
}