From: yomguy Date: Fri, 8 Feb 2013 00:53:08 +0000 (+0100) Subject: fix bad SQL query with postgresl X-Git-Tag: 1.4.5~45^2~1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=84650f53ccdaaaa336de1903d55d44c24525dc2e;p=telemeta.git fix bad SQL query with postgresl add relative marker offset to the kdenlive parsing --- diff --git a/telemeta/models/query.py b/telemeta/models/query.py index df6d1778..c5f1d991 100644 --- a/telemeta/models/query.py +++ b/telemeta/models/query.py @@ -157,7 +157,7 @@ class MediaItemQuerySet(CoreQuerySet): from telemeta.models import Location for f in args: if f == 'apparent_collector': - if not 'sqlite3' in engine: + if not 'sqlite3' in engine and not 'postgresql_psycopg2': related.append('collection') qs = qs.extra(select={f: 'IF(collector_from_collection, ' @@ -167,7 +167,7 @@ class MediaItemQuerySet(CoreQuerySet): 'media_items.collector)'}) elif f == 'country_or_continent': related.append('location') - if not 'sqlite3' in engine: + if not 'sqlite3' in engine and not 'postgresql_psycopg2': qs = qs.extra(select={f: 'IF(locations.type = ' + str(Location.COUNTRY) + ' ' 'OR locations.type = ' + str(Location.CONTINENT) + ',' diff --git a/telemeta/util/kdenlive/session.py b/telemeta/util/kdenlive/session.py index f76f9d1e..32fca7d4 100644 --- a/telemeta/util/kdenlive/session.py +++ b/telemeta/util/kdenlive/session.py @@ -109,28 +109,45 @@ class KDEnLiveSession(object): except: return text - def markers_relative(self, offset=0): + def markers_relative(self, offset=0, from_first_marker=False): + """ by default return a dict of markers with timecodes relative to an origin + + if from_first_marker=False: the origin is the first entry timecode + if from_first_marker=True: the origin is the first entry timecode before the first marker + + offset: general origin offset + """ + + abs_time = 0 markers = [] + i = 0 entries = self.entries_video_seconds() + for attr in self.session['children']: if 'kdenlivedoc' in attr['name']: + for att in attr['children']: if 'markers' in att['name'] and 'children' in att.keys(): + for at in att['children']: if 'marker' in at['name']: - rel_time = float(at['attributes']['time'].replace(',','.')) + + marker_time = float(at['attributes']['time'].replace(',','.')) id = at['attributes']['id'] - abs_time = 0 + rel_time = 0 for entry in entries: - if rel_time > entry['in'] and rel_time < entry['out'] and id == entry['id']: - abs_time = entry['t'] + (rel_time - entry['in']) + if marker_time >= entry['in'] and marker_time <= entry['out'] and id == entry['id']: + if i == 0 and from_first_marker: + abs_time = entry['t'] + rel_time = entry['t'] + (marker_time - entry['in']) - abs_time + offset break - at['attributes']['time'] = abs_time - at['attributes']['session_timecode'] = time.strftime('%H:%M:%S', time.gmtime(abs_time+offset)) + at['attributes']['time'] = rel_time + at['attributes']['session_timecode'] = time.strftime('%H:%M:%S', time.gmtime(rel_time)) at['attributes']['comment'] = self.fix_text(at['attributes']['comment']) markers.append(at['attributes']) + i += 1 return markers