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