pandora/pandora/sequence/tasks.py

41 lines
1.6 KiB
Python
Raw Normal View History

2012-06-06 19:49:32 +00:00
# -*- coding: utf-8 -*-
2012-06-06 19:49:32 +00:00
from django.db import connection, transaction
from celery.task import task
2012-06-06 19:49:32 +00:00
2013-03-06 15:57:46 +00:00
import item.models
from . import extract
2012-06-06 19:49:32 +00:00
2012-06-15 21:53:40 +00:00
@task(ignore_results=True, queue='encoding')
2014-09-19 12:26:46 +00:00
def get_sequences(public_id):
from . import models
2014-09-19 12:26:46 +00:00
i = item.models.Item.objects.get(public_id=public_id)
2013-03-06 15:57:46 +00:00
models.Sequence.objects.filter(sort=i.sort).delete()
2012-06-15 21:53:40 +00:00
position = 0
for stream in i.streams():
if stream.file.is_video:
data = extract.get_cut_sequences(stream)
keys = None
values = []
for mode in data:
for s in data[mode]:
sequence = {
'sort_id': i.sort.pk,
'mode': models.Sequence.MODE[mode],
'start': position + float('%0.03f' % s['in']),
'end': position + float('%0.03f' % s['out']),
'hash': models.parse_hash(s['hash'])
}
sequence['duration'] = sequence['end'] - sequence['start']
if not keys:
keys = ', '.join(['"%s"'%k for k in sequence.keys()])
2020-05-29 10:17:18 +00:00
v = ', '.join([isinstance(v, str) and "'%s'"%v or str(v)
for v in sequence.values()])
values.append('(%s)'%v)
if values:
cursor = connection.cursor()
sql = "INSERT INTO sequence_sequence (%s) VALUES %s" % (keys, ', '.join(values));
cursor.execute(sql)
2016-02-19 19:06:25 +00:00
transaction.commit()
position += stream.duration