| author | ymh <ymh.work@gmail.com> |
| Fri, 15 Oct 2010 11:58:18 +0200 | |
| changeset 89 | 30c6e597a7de |
| parent 88 | 7f2c2d9adf58 |
| child 95 | 9bae869b2146 |
| child 97 | 66f6aff5c382 |
| permissions | -rw-r--r-- |
| 49 | 1 |
import lxml.etree |
| 24 | 2 |
import uuid |
| 0 | 3 |
from datetime import datetime |
4 |
from ldt.ldt_utils.models import Content, Project |
|
5 |
||
6 |
DATE_FORMATS = ["%d/%m/%Y","%Y-%m-%d"] |
|
7 |
||
8 |
""" |
|
9 |
Serialize a project object to a cinelab compatible array |
|
10 |
""" |
|
11 |
class ProjectSerializer: |
|
12 |
||
| 88 | 13 |
def __init__(self, project, from_contents=True, from_display=True): |
| 0 | 14 |
self.project = project |
| 88 | 15 |
self.parsed = False |
| 0 | 16 |
self.ldt_doc = None |
17 |
self.medias = [] |
|
|
89
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
18 |
self.medias_by_id = {} |
| 0 | 19 |
self.annotations = [] |
|
89
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
20 |
self.annotations_by_annotation_type = {} |
| 0 | 21 |
self.tags = {} |
| 88 | 22 |
self.tags_by_id = {} |
| 0 | 23 |
self.annotation_types = [] |
|
89
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
24 |
self.annotation_types_by_id = {} |
| 0 | 25 |
self.views = [] |
26 |
self.lists = [] |
|
|
89
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
27 |
self.lists_by_id = {} |
| 88 | 28 |
self.serialize_contents = from_contents |
29 |
self.from_display = from_display |
|
| 0 | 30 |
|
31 |
||
32 |
def __parse_ensemble(self, ensemble_node, content): |
|
33 |
||
| 49 | 34 |
ensemble_id = ensemble_node.attrib[u"id"] |
35 |
ensemble_author = ensemble_node.attrib[u"author"] |
|
36 |
ensemble_title = ensemble_node.attrib[u"title"] |
|
37 |
ensemble_description = ensemble_node.attrib[u"abstract"] |
|
| 0 | 38 |
ensemble_created = datetime.utcnow().isoformat() |
39 |
ensemble_modified = ensemble_created |
|
40 |
||
41 |
list_items = [] |
|
42 |
new_list = { |
|
43 |
"id" : ensemble_id, |
|
44 |
"items" : list_items, |
|
45 |
"meta" : { |
|
46 |
"dc:creator":ensemble_author, |
|
47 |
"dc:created": ensemble_created, |
|
48 |
"dc:contributor":"undefined", |
|
49 |
"dc:modified": ensemble_modified, |
|
50 |
"dc:title":ensemble_title, |
|
51 |
"dc:description": ensemble_description, |
|
52 |
"id-ref":content.iri_id, |
|
53 |
"editable":"false" |
|
54 |
} |
|
55 |
} |
|
56 |
||
57 |
||
| 49 | 58 |
for decoupage_node in ensemble_node: |
59 |
if decoupage_node.tag != "decoupage" : |
|
| 0 | 60 |
continue |
61 |
||
| 49 | 62 |
decoupage_id = decoupage_node.attrib[ u"id"] |
63 |
decoupage_creator = decoupage_node.attrib[u"author"] |
|
| 0 | 64 |
if not decoupage_creator: |
65 |
decoupage_creator = "IRI" |
|
66 |
decoupage_contributor = decoupage_creator |
|
| 49 | 67 |
date_str = decoupage_node.get(u"date") |
| 0 | 68 |
decoupage_created = None |
69 |
if date_str : |
|
70 |
for date_format in DATE_FORMATS: |
|
71 |
try: |
|
72 |
decoupage_created = datetime.strptime(date_str,date_format).isoformat() |
|
73 |
break |
|
74 |
except Exception: |
|
75 |
decoupage_created = None |
|
76 |
if decoupage_created is None: |
|
77 |
decoupage_created = datetime.utcnow().isoformat() |
|
78 |
decoupage_modified = decoupage_created |
|
79 |
||
80 |
decoupage_title = "" |
|
| 49 | 81 |
for txtRes in decoupage_node.xpath("title/text()", smart_strings=False): |
82 |
decoupage_title += txtRes |
|
| 0 | 83 |
|
84 |
decoupage_description = "" |
|
| 49 | 85 |
for txtRes in decoupage_node.xpath("abstract/text()", smart_strings=False): |
86 |
decoupage_description += txtRes |
|
| 0 | 87 |
|
88 |
||
89 |
||
90 |
list_items.append({"id-ref":decoupage_id}) |
|
91 |
||
92 |
new_annotation_types = { |
|
93 |
"id":decoupage_id, |
|
94 |
"dc:creator":decoupage_creator, |
|
95 |
"dc:created":decoupage_created, |
|
96 |
"dc:contributor":decoupage_contributor, |
|
97 |
"dc:modified":decoupage_modified, |
|
98 |
"dc:title":decoupage_title, |
|
99 |
"dc:description":decoupage_description |
|
100 |
} |
|
101 |
||
|
89
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
102 |
self.annotation_types.append(new_annotation_types) |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
103 |
self.annotation_types_by_id[decoupage_id] = new_annotation_types |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
104 |
annotations_list = [] |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
105 |
|
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
106 |
self.annotations_by_annotation_type[decoupage_id] = annotations_list |
| 0 | 107 |
|
| 49 | 108 |
res = decoupage_node.xpath("elements/element") |
| 0 | 109 |
for element_node in res: |
110 |
||
| 49 | 111 |
element_id = element_node.attrib[u"id"] |
112 |
element_begin = element_node.attrib[u"begin"] |
|
113 |
element_duration = element_node.attrib[u"dur"] |
|
| 0 | 114 |
element_media = content.iri_id |
| 49 | 115 |
element_color = element_node.attrib[u"color"] |
| 0 | 116 |
|
117 |
element_title = "" |
|
| 49 | 118 |
for txtRes in element_node.xpath("title/text()", smart_strings=False): |
119 |
element_title += txtRes |
|
| 0 | 120 |
|
121 |
element_description = "" |
|
| 49 | 122 |
for txtRes in element_node.xpath("abstract/text()", smart_strings=False): |
123 |
element_description += txtRes |
|
| 0 | 124 |
|
125 |
element_audio_src = "" |
|
126 |
element_audio_href = "" |
|
| 49 | 127 |
res = element_node.xpath("audio") |
| 0 | 128 |
if len(res) > 0: |
| 49 | 129 |
element_audio_src = res[0].get(u"source",u"") |
130 |
element_audio_href = res[0].text |
|
| 0 | 131 |
|
132 |
element_tags = [] |
|
133 |
||
| 49 | 134 |
tags = element_node.get(u"tags",u"") |
| 0 | 135 |
|
136 |
tags_list = map(lambda s:s.strip(),tags.split(",")) |
|
137 |
||
138 |
#tags |
|
139 |
if tags is None or len(tags) == 0: |
|
140 |
tags_list = [] |
|
| 49 | 141 |
restagnode = element_node.xpath("tag/text()", smart_strings=False) |
| 0 | 142 |
for tagnode in restagnode: |
| 49 | 143 |
tags_list.append(tagnode) |
| 0 | 144 |
|
145 |
if tags_list is None or len(tags_list) == 0: |
|
146 |
tags_list = [] |
|
| 49 | 147 |
restagnode = element_node.xpath("tags/tag/text()", smart_strings=False) |
| 0 | 148 |
for tagnode in restagnode: |
| 49 | 149 |
tags_list.append(tagnode) |
| 0 | 150 |
|
151 |
tag_date = datetime.utcnow().isoformat() |
|
| 24 | 152 |
for tag_title in tags_list: |
153 |
if tag_title not in self.tags: |
|
| 26 | 154 |
tag_id = unicode(uuid.uuid1()) |
| 0 | 155 |
new_tag = { |
156 |
"id":tag_id, |
|
157 |
"meta" : { |
|
158 |
"dc:creator":"IRI", |
|
159 |
"dc:created": tag_date, |
|
160 |
"dc:contributor":"IRI", |
|
161 |
"dc:modified": tag_date, |
|
| 24 | 162 |
"dc:title":tag_title |
| 0 | 163 |
} |
164 |
} |
|
| 24 | 165 |
self.tags[tag_title] = new_tag |
| 88 | 166 |
self.tags_by_id[tag_id] = new_tag |
| 0 | 167 |
element_tags.append({"id-ref":tag_id}) |
168 |
||
169 |
if not element_tags: |
|
170 |
element_tags = None |
|
171 |
||
172 |
new_annotation = { |
|
173 |
"begin": element_begin, |
|
174 |
"end": int(element_begin) + int(element_duration), |
|
175 |
"id": element_id, |
|
176 |
"media": element_media, |
|
177 |
"content": { |
|
178 |
"mimetype": "application/x-ldt-structured", |
|
179 |
"title": element_title, |
|
180 |
"description": element_description, |
|
181 |
"color": element_color, |
|
182 |
"audio": { |
|
183 |
"src" : element_audio_src, |
|
184 |
"mimetype": "audio/mp3", |
|
185 |
"href": element_audio_href |
|
186 |
}, |
|
187 |
}, |
|
188 |
"tags": element_tags, |
|
189 |
"meta": { |
|
190 |
"id-ref": decoupage_id, |
|
191 |
"dc:creator": decoupage_creator, |
|
192 |
"dc:contributor": decoupage_contributor, |
|
193 |
"dc:created": decoupage_created, |
|
194 |
"dc:modified": decoupage_modified |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
self.annotations.append(new_annotation) |
|
|
89
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
199 |
annotations_list.append(new_annotation) |
| 0 | 200 |
|
201 |
if not list_items: |
|
202 |
new_list["items"] = None |
|
203 |
self.lists.append(new_list) |
|
|
89
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
204 |
self.lists_by_id[ensemble_id] = new_list |
| 0 | 205 |
|
206 |
||
207 |
def __parse_ldt(self): |
|
208 |
||
| 49 | 209 |
self.ldt_doc = lxml.etree.fromstring(self.project.ldt.encode("utf-8")) |
| 0 | 210 |
|
| 49 | 211 |
res = self.ldt_doc.xpath("/iri/medias/media") |
| 0 | 212 |
for mediaNode in res: |
| 49 | 213 |
iri_id = mediaNode.attrib[u"id"] |
| 0 | 214 |
content = Content.objects.get(iri_id=iri_id) |
215 |
self.__parse_content(content) |
|
216 |
||
| 88 | 217 |
res = self.ldt_doc.xpath("/iri/annotations/content") |
| 0 | 218 |
for content_node in res: |
| 49 | 219 |
content_id = content_node.attrib[u"id"] |
| 0 | 220 |
content = Content.objects.get(iri_id=content_id) |
| 49 | 221 |
for ensemble_node in content_node: |
222 |
if ensemble_node.tag != "ensemble" : |
|
| 0 | 223 |
continue |
| 49 | 224 |
self.__parse_ensemble(ensemble_node, content) |
|
89
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
225 |
|
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
226 |
if self.from_display : |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
227 |
annotations = [] |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
228 |
annotation_types = [] |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
229 |
ensembles = [] |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
230 |
medias = [] |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
231 |
tags = [] |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
232 |
xpath_str = "/iri/displays/display[position()=1]/content" |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
233 |
if isinstance(self.from_display, basestring): |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
234 |
xpath_str = "/iri/displays/display[id='%s']/content" % self.from_display |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
235 |
|
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
236 |
for content_node in self.ldt_doc.xpath(xpath_str): |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
237 |
content_id = content_node.get("id") |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
238 |
if content_id not in medias: |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
239 |
medias.append(content_id) |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
240 |
for node in content_node.xpath("decoupage"): |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
241 |
annotation_type_id = node.get('id') |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
242 |
ensemble_id = node.get('idens') |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
243 |
if annotation_type_id in self.annotations_by_annotation_type: |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
244 |
annot_list = self.annotations_by_annotation_type[annotation_type_id] |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
245 |
annotations.extend(annot_list) |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
246 |
for annot in annot_list: |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
247 |
if annot['tags']: |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
248 |
for tag in annot['tags']: |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
249 |
tag_id = tag['id-ref'] |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
250 |
if tag_id not in tags: |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
251 |
tags.append(tag_id) |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
252 |
if annotation_type_id not in annotation_types: |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
253 |
annotation_types.append(annotation_type_id) |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
254 |
if ensemble_id not in ensembles: |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
255 |
ensembles.append(ensemble_id) |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
256 |
|
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
257 |
self.annotations = annotations |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
258 |
self.annotation_types = map(lambda id: self.annotation_types_by_id[id], annotation_types) |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
259 |
self.lists = map(lambda id: self.lists_by_id[id], ensembles) |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
260 |
self.medias = map(lambda id: self.medias_by_id[id], medias) |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
261 |
self.tags = {} |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
262 |
for tag_id in tags: |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
263 |
tag_inst = self.tags_by_id[tag_id] |
|
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
264 |
self.tags[tag_inst['meta']['dc:title']] = tag_inst |
| 88 | 265 |
|
266 |
self.parsed = True |
|
| 0 | 267 |
|
268 |
def __parse_content(self, content): |
|
269 |
||
| 49 | 270 |
doc = lxml.etree.parse(content.iri_file_path()) |
| 0 | 271 |
|
272 |
authors = content.authors.all() |
|
273 |
||
274 |
if len(authors) > 0 : |
|
275 |
author = authors[0].handle |
|
276 |
else : |
|
277 |
author = "IRI" |
|
278 |
||
279 |
if len(authors) > 1 : |
|
280 |
contributor = authors[1].handle |
|
281 |
else : |
|
282 |
contributor = author |
|
283 |
||
284 |
content_author = "" |
|
285 |
||
| 49 | 286 |
res = doc.xpath("/iri/head/meta[@name='author']/@content") |
| 0 | 287 |
if len(res) > 0: |
| 49 | 288 |
content_author = res[0] |
| 0 | 289 |
|
290 |
||
291 |
content_date = "" |
|
292 |
||
| 49 | 293 |
res = doc.xpath("/iri/head/meta[@name='date']/@content") |
| 0 | 294 |
if len(res) > 0: |
| 49 | 295 |
content_date = res[0] |
| 0 | 296 |
|
297 |
||
298 |
new_media = { |
|
299 |
"http://advene.liris.cnrs.fr/ns/frame_of_reference/ms" : "o=0", |
|
300 |
"id" : content.iri_id, |
|
301 |
"href" : content.videopath.rstrip('/') + "/" + content.src, |
|
302 |
"unit" : "ms", |
|
303 |
"origin" : "0", |
|
304 |
"meta": { |
|
305 |
"dc:creator" : author, |
|
306 |
"dc:created" : content.creation_date.isoformat(), |
|
307 |
"dc:contributor" : contributor, |
|
308 |
"dc:modified" : content.update_date.isoformat(), |
|
309 |
"dc:creator.contents" : content_author, |
|
310 |
"dc:created.contents" : content_date, |
|
311 |
"dc:title" : content.title, |
|
312 |
"dc:description" : content.description, |
|
313 |
"dc:duration" : content.get_duration(), |
|
314 |
"item": { |
|
315 |
"name" : "streamer", |
|
316 |
"value": content.videopath.rstrip('/') + "/" |
|
317 |
}, |
|
318 |
} |
|
319 |
} |
|
320 |
||
321 |
self.medias.append(new_media) |
|
|
89
30c6e597a7de
correct project serializer and take into account the display + new version
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
322 |
self.medias_by_id[content.iri_id] = new_media |
| 0 | 323 |
|
| 85 | 324 |
if self.serialize_contents: |
325 |
res = doc.xpath("/iri/body/ensembles/ensemble") |
|
326 |
for ensemble_node in res: |
|
327 |
self.__parse_ensemble(ensemble_node, content) |
|
| 0 | 328 |
|
329 |
||
330 |
def serialize_to_cinelab(self): |
|
331 |
||
332 |
res = {} |
|
333 |
||
| 88 | 334 |
if not self.parsed: |
335 |
self.__parse_ldt() |
|
| 0 | 336 |
|
337 |
project_main_media = "" |
|
338 |
if len(self.medias) > 0: |
|
339 |
project_main_media = self.medias[0]["id"] |
|
340 |
||
341 |
res['meta'] = { |
|
342 |
'id': self.project.ldt_id, |
|
343 |
'dc:created':self.project.creation_date.isoformat(), |
|
344 |
'dc:modified':self.project.modification_date.isoformat(), |
|
345 |
'dc:contributor':self.project.changed_by, |
|
346 |
'dc:creator':self.project.created_by, |
|
347 |
'dc:title':self.project.title, |
|
348 |
'dc:description':self.project.get_description(self.ldt_doc), # get from doc, parse ldt |
|
349 |
'main_media': {"id-ref":project_main_media} |
|
350 |
} |
|
351 |
||
352 |
if not self.medias: |
|
353 |
self.medias = None |
|
354 |
||
355 |
if not self.annotation_types: |
|
356 |
self.annotation_types = None |
|
357 |
||
358 |
if len(self.tags) == 0: |
|
359 |
tags = None |
|
360 |
else: |
|
361 |
tags = self.tags.values() |
|
362 |
||
363 |
if not self.lists: |
|
364 |
self.lists = None |
|
365 |
||
366 |
if not self.views: |
|
367 |
self.views = None |
|
368 |
||
369 |
if not self.annotations: |
|
370 |
self.annotations = None |
|
371 |
||
372 |
res['medias'] = self.medias |
|
373 |
res['annotation-types'] = self.annotation_types |
|
374 |
res['annotations'] = self.annotations |
|
375 |
res['lists'] = self.lists |
|
376 |
res['tags'] = tags |
|
377 |
res['views'] = self.views # ignored for the moment |
|
378 |
||
379 |
return res |
|
| 88 | 380 |
|
381 |
def getAnnotations(self, first_cutting=True): |
|
| 0 | 382 |
|
| 88 | 383 |
if not self.parsed: |
384 |
self.__parse_ldt() |
|
385 |
||
386 |
annotations = [] |
|
387 |
||
388 |
current_cutting = None |
|
389 |
uri = None |
|
390 |
for annot in self.annotations: |
|
391 |
if first_cutting and current_cutting and current_cuttings != annot['meta']['id-ref'] : |
|
392 |
break |
|
393 |
current_cuttings = annot['meta']['id-ref'] |
|
394 |
content_id = annot['media'] |
|
395 |
content = Content.objects.get(iri_id=content_id) |
|
396 |
if annot['tags']: |
|
397 |
tags_list = map(lambda tag_entry: self.tags_by_id[tag_entry['id-ref']]['meta']['dc:title'],annot['tags']) |
|
398 |
else: |
|
399 |
tags_list = [] |
|
400 |
begin = int(annot['begin']) |
|
401 |
duration = int(annot['end'])-begin |
|
402 |
if content.media_obj and content.media_obj.external_publication_url: |
|
403 |
uri = "%s#t=%d" % (content.media_obj.external_publication_url, begin) |
|
404 |
||
405 |
||
406 |
annotations.append({ |
|
407 |
'begin': begin, |
|
408 |
'duration':duration, |
|
409 |
'title':annot['content']['title'], |
|
410 |
'desc':annot['content']['description'], |
|
411 |
'tags': tags_list, |
|
412 |
'id':annot['id'], |
|
413 |
'uri':uri |
|
414 |
}) |
|
415 |
||
416 |
return annotations |
|
417 |
||
418 |