2010-06-26 14:32:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
from datetime import timedelta
|
|
|
|
|
|
|
|
from celery.decorators import task, periodic_task
|
2011-06-01 16:40:39 +00:00
|
|
|
from django.db.models import Q
|
2010-06-26 14:32:08 +00:00
|
|
|
|
|
|
|
import models
|
|
|
|
|
|
|
|
|
|
|
|
@periodic_task(run_every=timedelta(days=1))
|
|
|
|
def cronjob(**kwargs):
|
|
|
|
print "do some cleanup stuff once a day"
|
|
|
|
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2010-09-10 15:12:22 +00:00
|
|
|
@task(ignore_resulsts=True, queue='default')
|
2010-11-27 12:12:53 +00:00
|
|
|
def update_poster(itemId):
|
2010-09-23 16:01:48 +00:00
|
|
|
item = models.Item.objects.get(itemId=itemId)
|
2010-12-01 00:00:33 +00:00
|
|
|
item.make_poster(True)
|
2011-01-21 10:49:24 +00:00
|
|
|
item.make_icon()
|
2010-09-10 15:12:22 +00:00
|
|
|
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2010-07-12 14:56:14 +00:00
|
|
|
@task(ignore_resulsts=True, queue='default')
|
2011-01-16 13:28:57 +00:00
|
|
|
def update_external(itemId):
|
2010-12-25 13:45:19 +00:00
|
|
|
item = models.Item.objects.get(itemId=itemId)
|
2011-01-16 13:28:57 +00:00
|
|
|
item.update_external()
|
2010-06-26 14:32:08 +00:00
|
|
|
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2010-12-22 07:45:37 +00:00
|
|
|
@task(queue="encoding")
|
2010-11-27 12:12:53 +00:00
|
|
|
def update_streams(itemId):
|
2010-06-26 14:32:08 +00:00
|
|
|
'''
|
2010-10-16 11:49:45 +00:00
|
|
|
create stream, extract timeline and create derivatives
|
2010-06-26 14:32:08 +00:00
|
|
|
'''
|
2010-10-16 11:49:45 +00:00
|
|
|
item = models.Item.objects.get(itemId=itemId)
|
2010-11-15 19:15:52 +00:00
|
|
|
if item.files.filter(is_main=True, is_video=True, available=False).count() == 0:
|
2010-11-27 12:12:53 +00:00
|
|
|
item.update_streams()
|
2010-12-22 07:45:37 +00:00
|
|
|
return True
|
2011-06-01 16:40:39 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
for f in item.files.filter(is_main=True, is_subtitle=True, available=True).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)[0].duration
|
|
|
|
offset += duration
|