pandora/pandora/sequence/tasks.py

39 lines
1.4 KiB
Python
Raw Normal View History

2012-06-06 19:49:32 +00:00
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.db import connection, transaction
from celery.task import task
2012-06-06 19:49:32 +00:00
import models
import extract
2012-06-15 21:53:40 +00:00
@task(ignore_results=True, queue='encoding')
2012-06-06 19:49:32 +00:00
def get_sequences(itemId):
i = models.Item.objects.get(itemId=itemId)
models.Sequence.objects.filter(item=i).delete()
2012-06-15 21:53:40 +00:00
position = 0
for stream in i.streams():
data, position = extract.get_sequences(stream.timeline_prefix, position)
2012-06-17 14:23:54 +00:00
keys = None
values = []
for mode in data:
for s in data[mode]:
sequence = {
'sort_id': i.sort.pk,
'mode': mode,
'start': float('%0.03f' % s['in']),
'end': float('%0.03f' % s['out']),
'hash': models.parse_hash(s['hash'])
2012-06-17 14:23:54 +00:00
}
sequence['duration'] = sequence['end'] - sequence['start']
if not keys:
keys = ', '.join(['"%s"'%k for k in sequence.keys()])
v = ', '.join([isinstance(v, basestring) and "'%s'"%v or str(v)
for v in sequence.values()])
values.append('(%s)'%v)
2012-06-17 14:32:28 +00:00
if values:
cursor = connection.cursor()
sql = "INSERT INTO sequence_sequence (%s) VALUES %s" % (keys, ', '.join(values));
cursor.execute(sql)
transaction.commit_unless_managed()
2012-06-15 21:53:40 +00:00