diff -r 2f978b081c4c -r 9927a619d2b5 web/ldt/ldt_utils/projectserializer.py --- a/web/ldt/ldt_utils/projectserializer.py Thu Oct 14 12:17:31 2010 +0200 +++ b/web/ldt/ldt_utils/projectserializer.py Fri Oct 15 12:36:43 2010 +0200 @@ -10,15 +10,19 @@ """ class ProjectSerializer: - def __init__(self, project): + def __init__(self, project, from_contents=True, from_display=True): self.project = project + self.parsed = False self.ldt_doc = None self.medias = [] self.annotations = [] self.tags = {} + self.tags_by_id = {} self.annotation_types = [] self.views = [] self.lists = [] + self.serialize_contents = from_contents + self.from_display = from_display def __parse_ensemble(self, ensemble_node, content): @@ -151,6 +155,7 @@ } } self.tags[tag_title] = new_tag + self.tags_by_id[tag_id] = new_tag element_tags.append({"id-ref":tag_id}) if not element_tags: @@ -199,8 +204,7 @@ content = Content.objects.get(iri_id=iri_id) self.__parse_content(content) - res = self.ldt_doc.xpath("/iri/annotations/content") - + res = self.ldt_doc.xpath("/iri/annotations/content") for content_node in res: content_id = content_node.attrib[u"id"] content = Content.objects.get(iri_id=content_id) @@ -209,6 +213,11 @@ continue self.__parse_ensemble(ensemble_node, content) +# res = self.ldt_doc.xpath("/iri/displays/display") +# for display_node in res: +# pass + + self.parsed = True def __parse_content(self, content): @@ -239,11 +248,16 @@ if len(res) > 0: content_date = res[0] - + href = "" + meta_item_value = "" + if content.videopath: + href = content.videopath.rstrip('/') + "/" + content.src + meta_item_value = content.videopath.rstrip('/') + "/" + new_media = { "http://advene.liris.cnrs.fr/ns/frame_of_reference/ms" : "o=0", "id" : content.iri_id, - "href" : content.videopath.rstrip('/') + "/" + content.src, + "href" : href, "unit" : "ms", "origin" : "0", "meta": { @@ -258,25 +272,25 @@ "dc:duration" : content.get_duration(), "item": { "name" : "streamer", - "value": content.videopath.rstrip('/') + "/" + "value": meta_item_value, }, } } self.medias.append(new_media) - - res = doc.xpath("/iri/body/ensembles/ensemble") - - for ensemble_node in res: - self.__parse_ensemble(ensemble_node, content) + if self.serialize_contents: + res = doc.xpath("/iri/body/ensembles/ensemble") + for ensemble_node in res: + self.__parse_ensemble(ensemble_node, content) def serialize_to_cinelab(self): res = {} - self.__parse_ldt() + if not self.parsed: + self.__parse_ldt() project_main_media = "" if len(self.medias) > 0: @@ -321,4 +335,42 @@ res['views'] = self.views # ignored for the moment return res + + def getAnnotations(self, first_cutting=True): + if not self.parsed: + self.__parse_ldt() + + annotations = [] + + current_cutting = None + uri = None + for annot in self.annotations: + if first_cutting and current_cutting and current_cuttings != annot['meta']['id-ref'] : + break + current_cuttings = annot['meta']['id-ref'] + content_id = annot['media'] + content = Content.objects.get(iri_id=content_id) + if annot['tags']: + tags_list = map(lambda tag_entry: self.tags_by_id[tag_entry['id-ref']]['meta']['dc:title'],annot['tags']) + else: + tags_list = [] + begin = int(annot['begin']) + duration = int(annot['end'])-begin + if content.media_obj and content.media_obj.external_publication_url: + uri = "%s#t=%d" % (content.media_obj.external_publication_url, begin) + + + annotations.append({ + 'begin': begin, + 'duration':duration, + 'title':annot['content']['title'], + 'desc':annot['content']['description'], + 'tags': tags_list, + 'id':annot['id'], + 'uri':uri + }) + + return annotations + +