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
|
2013-02-21 13:28:36 +00:00
|
|
|
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']),
|
2013-03-06 08:40:52 +00:00
|
|
|
'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
|
|
|
|