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