--- a/web/ldt/ldt_utils/models.py Tue Oct 12 03:23:33 2010 +0200
+++ b/web/ldt/ldt_utils/models.py Tue Oct 12 16:11:15 2010 +0200
@@ -297,6 +297,57 @@
return True
else:
return False
+
+ def getAnnotations(self, first_cutting=True):
+ doc = lxml.etree.fromstring(self.ldt)
+
+ annotations = []
+
+ for contentnode in doc.xpath("/iri/annotations/content"):
+ iri_id = contentnode.get("id")
+ content = Content.objects.get(iri_id=iri_id)
+
+ for cuttingnode in contentnode.xpath("ensemble/decoupage"):
+
+ for annotationnode in cuttingnode.xpath("elements/element"):
+ tags = annotationnode.get('tags')
+ tags_list = []
+ tags_list.extend(annotationnode.xpath("tags/tag/text()"))
+ if tags:
+ tags_list.append(tags)
+
+ def accumulate(a, b):
+ a.extend(b)
+ return a
+
+ tags_list = reduce(lambda a, s:accumulate(a,s.split(',')), tags_list, [])
+
+ begin = annotationnode.get('begin')
+ if begin is None:
+ begin = 0
+ else:
+ begin = int(begin)
+
+ uri = None
+ if content.media_obj.external_publication_url:
+ uri = "%s#t=%d" % (content.media_obj.external_publication_url, begin)
+
+ annotations.append({
+ 'begin': begin,
+ 'duration':annotationnode.get('dur'),
+ 'title':u"".join(annotationnode.xpath("title/text()")),
+ 'desc':u"".join(annotationnode.xpath("abstract/text()")),
+ 'tags': tags_list,
+ 'id':u"".join(annotationnode.get('id')),
+ 'uri':uri
+ })
+ if first_cutting and len(annotations) > 0 :
+ break
+ if first_cutting and len(annotations) > 0 :
+ break
+
+ return annotations
+
class Segment(models.Model):