From 4dca348b6e1cdf60ac3a2ce76d83964680aadcee Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 11 Apr 2014 12:05:57 +0000 Subject: [PATCH] only get sequences for audio. fix offset calculation --- pandora/sequence/extract.py | 4 +-- pandora/sequence/tasks.py | 50 ++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pandora/sequence/extract.py b/pandora/sequence/extract.py index 761f1297c..a8ce5c564 100644 --- a/pandora/sequence/extract.py +++ b/pandora/sequence/extract.py @@ -99,7 +99,7 @@ class DataTimeline(): x = frame * 8 - tile * self.timeline_width return self.timeline_image.crop((x, 0, x + 8, 8)) -def get_cut_sequences(stream, position=0): +def get_cut_sequences(stream): timeline = DataTimeline(stream.timeline_prefix) cuts = list(stream.cuts) + [stream.duration] modes = ['color', 'shape'] @@ -120,4 +120,4 @@ def get_cut_sequences(stream, position=0): 'out': cut, }) position = cut - return sequences, position + return sequences diff --git a/pandora/sequence/tasks.py b/pandora/sequence/tasks.py index 0353f7d77..08a2d929e 100644 --- a/pandora/sequence/tasks.py +++ b/pandora/sequence/tasks.py @@ -13,28 +13,28 @@ def get_sequences(itemId): models.Sequence.objects.filter(sort=i.sort).delete() position = 0 for stream in i.streams(): - #data, position = extract.get_sequences(stream.timeline_prefix, position) - data, position = extract.get_cut_sequences(stream, position) - keys = None - values = [] - for mode in data: - for s in data[mode]: - sequence = { - 'sort_id': i.sort.pk, - 'mode': models.Sequence.MODE[mode], - 'start': float('%0.03f' % s['in']), - 'end': 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()]) - v = ', '.join([isinstance(v, basestring) 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) - transaction.commit_unless_managed() - + 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()]) + v = ', '.join([isinstance(v, basestring) 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) + transaction.commit_unless_managed() + position += stream.duration