| author | ymh <ymh.work@gmail.com> |
| Thu, 19 May 2011 14:35:29 +0200 | |
| changeset 114 | 279f1782c184 |
| parent 113 | cf3bdb2a4216 |
| child 115 | d2cbc4c647dc |
| permissions | -rw-r--r-- |
| 114 | 1 |
from copy import deepcopy |
| 19 | 2 |
from django.conf import settings |
| 95 | 3 |
from ldt.indexation import get_searcher, get_query_parser |
| 19 | 4 |
import datetime |
| 0 | 5 |
import django.core.urlresolvers |
| 19 | 6 |
import lxml.etree |
| 0 | 7 |
import urllib |
| 19 | 8 |
import uuid |
| 0 | 9 |
|
10 |
__BOOLEAN_DICT = { |
|
11 |
'false':False, |
|
12 |
'true':True, |
|
13 |
'0':False, |
|
14 |
'1':True, |
|
15 |
't': True, |
|
16 |
'f':False |
|
17 |
} |
|
18 |
||
| 19 | 19 |
def reduce_text_node(element_node, xpath_str=None): |
20 |
node_list = [] |
|
21 |
if xpath_str is not None: |
|
22 |
node_list = element_node.xpath(xpath_str, smart_strings=False) |
|
23 |
else: |
|
24 |
node_list = [element_node.text] |
|
| 63 | 25 |
return reduce(lambda t, s: t + s, node_list , "") |
| 0 | 26 |
|
27 |
def boolean_convert(bool): |
|
28 |
if bool is None: |
|
29 |
return False |
|
30 |
if bool is True or bool is False: |
|
31 |
return bool |
|
32 |
key = str(bool).lower() |
|
33 |
return __BOOLEAN_DICT.get(key, False) |
|
34 |
||
35 |
def generate_uuid(): |
|
36 |
return unicode(uuid.uuid1()) |
|
37 |
||
38 |
class LdtSearch(object): |
|
39 |
||
40 |
def query(self, field, query): |
|
| 95 | 41 |
indexSearcher = get_searcher() |
|
97
10f69a5bd9e1
correct propagation of project id on indexation
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
42 |
queryParser = get_query_parser(field) |
| 0 | 43 |
queryObj = queryParser.parse(query) |
44 |
hits = indexSearcher.search(queryObj, settings.LDT_MAX_SEARCH_NUMBER) |
|
45 |
||
46 |
res = [] |
|
47 |
for hit in hits.scoreDocs: |
|
48 |
doc = indexSearcher.doc(hit.doc) |
|
|
97
10f69a5bd9e1
correct propagation of project id on indexation
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
49 |
res.append({"iri_id":doc.get("iri_id"), "ensemble_id":doc.get("ensemble_id"), "decoupage_id":doc.get("decoupage_id"), "element_id":doc.get("element_id"), "project_id":doc.get("project_id")}) |
| 0 | 50 |
indexSearcher.close() |
51 |
return res |
|
52 |
||
53 |
def queryAll(self, query): |
|
54 |
return self.query("all", query) |
|
55 |
||
56 |
class LdtUtils(object): |
|
57 |
||
|
113
cf3bdb2a4216
improve ldt generation for merging projects
ymh <ymh.work@gmail.com>
parents:
112
diff
changeset
|
58 |
def generateLdt(self, contentList, title=u"", author=u"IRI Web", web_url=u"", startSegment=None, projects=None): |
| 0 | 59 |
|
60 |
iri = lxml.etree.Element(u'iri') |
|
61 |
doc = lxml.etree.ElementTree(iri) |
|
62 |
||
63 |
project = lxml.etree.SubElement(iri, u'project') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
64 |
project.set(u"id", unicode(str(uuid.uuid1()))) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
65 |
project.set(u"title", unicode(title)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
66 |
project.set(u"user", author) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
67 |
project.set(u"abstract", u"") |
| 0 | 68 |
|
69 |
medias = lxml.etree.SubElement(iri, u"medias") |
|
70 |
for content in contentList: |
|
71 |
videopath = unicode(settings.STREAM_URL) |
|
72 |
if content.videopath : |
|
73 |
videopath = unicode(content.videopath) |
|
74 |
media = lxml.etree.SubElement(medias, "media") |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
75 |
media.set(u"id", content.iri_id) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
76 |
media.set(u"src", content.iri_url(web_url)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
77 |
media.set(u"video", videopath) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
78 |
media.set(u"pict", u"") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
79 |
media.set(u"extra", u"") |
| 0 | 80 |
|
| 114 | 81 |
if projects is None: |
82 |
projects = [] |
|
83 |
annotations_nodes = {} |
|
84 |
for project in project: |
|
85 |
ldtdoc = lxml.etree.fromstring(project.ldt.encode("utf-8")) |
|
86 |
res = ldtdoc.xpath("/iri/annotations/content") |
|
87 |
||
88 |
for content in res: |
|
89 |
contentid = content.get("id") |
|
90 |
if annotations_nodes.has_key(contentid): |
|
91 |
contentnode = annotations_nodes[contentid] |
|
92 |
else: |
|
93 |
contentnode = {"id":contentid, "ensembles":[]} |
|
94 |
annotations_nodes[contentid] = contentnode |
|
95 |
for ens in content: |
|
96 |
if ens.tag.endswith("ensemble"): |
|
97 |
contentnode["ensembles"].append(deepcopy(ens)) |
|
98 |
||
99 |
annotations = lxml.etree.SubElement(iri, "annotations") |
|
100 |
if len(annotations_nodes) > 0: |
|
101 |
for content in contentList: |
|
102 |
if content.iri_id in annotations_nodes: |
|
103 |
contentnode = annotations_nodes[content.content_base.iri_id] |
|
104 |
if contentnode is not None: |
|
105 |
if len(contentnode["ensembles"]) > 0: |
|
106 |
content_node = lxml.etree.SubElement(annotations, "content") |
|
107 |
content_node.set("id", contentnode["id"]) |
|
108 |
content_node.text = u"" |
|
109 |
for ens in contentnode["ensembles"]: |
|
110 |
content_node.append(ens) |
|
111 |
else: |
|
112 |
content_node = lxml.etree.SubElement(annotations, "content") |
|
113 |
content_node.set("id", contentnode["id"]) |
|
| 0 | 114 |
|
115 |
||
116 |
displays = lxml.etree.SubElement(iri, "displays") |
|
117 |
if len(contentList) > 0: |
|
118 |
display = lxml.etree.SubElement(displays, "display") |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
119 |
display.set(u"id", u"0") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
120 |
display.set(u"title", u"generated") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
121 |
display.set(u"idsel", contentList[0].iri_id) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
122 |
display.set(u"tc", u"0") |
| 0 | 123 |
for content in contentList: |
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
124 |
contentd = lxml.etree.SubElement(display, "content") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
125 |
contentd.set(u"id", content.iri_id) |
| 0 | 126 |
filepath = urllib.urlopen(content.iri_url()) |
127 |
||
128 |
udoc = lxml.etree.parse(filepath) |
|
129 |
res = udoc.xpath("/iri/body/ensembles/ensemble/decoupage") |
|
130 |
for decoupagenode in res: |
|
131 |
decoupage_id = decoupagenode.get(u"id") |
|
132 |
ensemble_id = decoupagenode.getparent().get(u"id") |
|
133 |
decoupage_id = decoupagenode.get(u"id") |
|
134 |
ensemble_id = decoupagenode.getparent().get(u"id") |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
135 |
decoupage = lxml.etree.SubElement(contentd, "decoupage") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
136 |
decoupage.set(u"id", decoupage_id) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
137 |
decoupage.set(u"idens", ensemble_id) |
| 0 | 138 |
if startSegment is not None: |
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
139 |
activeSegment = lxml.etree.SubElement(display, "activeSegment") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
140 |
idas = lxml.etree.SubElement(activeSegment, "id") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
141 |
idas.set(u"idctt", startSegment["idcontent"]) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
142 |
idas.set(u"idens" , startSegment["idgroup"]) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
143 |
idas.set(u"idcut", startSegment["idcutting"]) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
144 |
idas.set(u"idseg", startSegment["idsegment"]) |
| 0 | 145 |
|
| 19 | 146 |
lxml.etree.SubElement(iri, "edits") |
|
112
9886ab183b09
add permalink + corrcetion config with static and media path. update urls
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
147 |
return doc |
| 0 | 148 |
|
149 |
||
150 |
def generateInit(self, url, method, search=None): |
|
151 |
||
152 |
iri = lxml.etree.Element('iri') |
|
153 |
||
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
154 |
elementFiles = lxml.etree.SubElement(iri, 'files') |
| 0 | 155 |
elementInit = lxml.etree.SubElement(elementFiles, 'init') |
156 |
elementfile = lxml.etree.SubElement(elementInit, 'file') |
|
157 |
||
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
158 |
elementfile.set('src', settings.WEB_URL + django.core.urlresolvers.reverse(method, args=url)) |
| 0 | 159 |
if(search): |
|
69
784ebba76424
enhance new media/content creation with url : external stream, local stream using STREAM_URL or youtube http.
cavaliet
parents:
63
diff
changeset
|
160 |
elementfile.set("segsel", settings.WEB_URL + django.core.urlresolvers.reverse(search, args=url)) |
| 0 | 161 |
|
| 19 | 162 |
lxml.etree.SubElement(elementFiles, 'recent') |
163 |
lxml.etree.SubElement(elementFiles, 'library') |
|
| 0 | 164 |
|
165 |
return iri |
|
166 |
||
167 |
||
168 |
||
169 |
def create_ldt(project, user): |
|
170 |
"""create xml""" |
|
171 |
||
172 |
||
173 |
contentList = project.contents.all() |
|
174 |
||
175 |
# create a dom |
|
176 |
iri = lxml.etree.Element('iri') |
|
177 |
doc = lxml.etree.ElementTree(iri) |
|
178 |
||
179 |
#node project |
|
180 |
elementProject = lxml.etree.SubElement(iri, 'project') |
|
181 |
||
182 |
elementProject.set('abstract', "") |
|
183 |
elementProject.set('title', project.title) |
|
184 |
elementProject.set('user', user.username) |
|
185 |
elementProject.set('id', project.ldt_id) |
|
186 |
||
187 |
#node medias |
|
188 |
elementMedias = lxml.etree.SubElement(iri, 'medias') |
|
189 |
||
190 |
idsel = None |
|
191 |
for content in contentList: |
|
192 |
if not idsel: |
|
193 |
idsel = content.iri_id |
|
194 |
elementMedia = lxml.etree.SubElement(elementMedias, 'media') |
|
195 |
elementMedia.set('id', content.iri_id) |
|
196 |
elementMedia.set('src', content.iri_url()) |
|
|
69
784ebba76424
enhance new media/content creation with url : external stream, local stream using STREAM_URL or youtube http.
cavaliet
parents:
63
diff
changeset
|
197 |
|
|
784ebba76424
enhance new media/content creation with url : external stream, local stream using STREAM_URL or youtube http.
cavaliet
parents:
63
diff
changeset
|
198 |
if content.videopath != None : |
| 0 | 199 |
elementMedia.set('video', content.videopath) |
200 |
else: |
|
201 |
elementMedia.set('video', settings.STREAM_URL) |
|
202 |
elementMedia.set('pict', "") |
|
203 |
elementMedia.set('extra', "") |
|
204 |
||
205 |
if not idsel: |
|
206 |
idsel = "" |
|
207 |
||
208 |
#node annotations |
|
| 19 | 209 |
lxml.etree.SubElement(iri, 'annotations') |
| 0 | 210 |
|
211 |
#node displays |
|
212 |
elementDisplays = lxml.etree.SubElement(iri, 'displays') |
|
213 |
elementDisplay = lxml.etree.SubElement(elementDisplays, 'display') |
|
214 |
elementDisplay.set('id', '0') |
|
215 |
elementDisplay.set('title', 'Init view') |
|
216 |
elementDisplay.set('idsel', idsel) |
|
217 |
elementDisplay.set('tc', '0') |
|
218 |
elementDisplay.set('zoom', '0') |
|
219 |
elementDisplay.set('scroll', '0') |
|
220 |
elementDisplay.set('infoBAB', '') |
|
221 |
||
222 |
||
223 |
#node content |
|
224 |
for content in contentList: |
|
225 |
elementContent = lxml.etree.SubElement(elementDisplay, 'content') |
|
226 |
elementContent.set('id', content.iri_id) |
|
227 |
||
228 |
if not 'http' in content.iriurl: |
|
229 |
#eg: "iiiielizabethrosse/ENMI08-III_elizabethrosse.iri" |
|
230 |
url = content.iri_url() |
|
231 |
else: |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
232 |
url = content.iriurl |
| 0 | 233 |
file = urllib.urlopen(url) |
234 |
doc = lxml.etree.parse(file) |
|
235 |
res = doc.xpath("/iri/body/ensembles/ensemble/decoupage") |
|
236 |
||
237 |
#node decoupage |
|
238 |
for decoupagenode in res: |
|
239 |
decoupage_id = decoupagenode.get(u"id") |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
240 |
parent = decoupagenode.getparent() |
| 0 | 241 |
ensemble_id = parent.get(u"id") |
242 |
elementDecoupage = lxml.etree.SubElement(elementContent, 'decoupage') |
|
243 |
elementDecoupage.set('idens', ensemble_id) |
|
244 |
elementDecoupage.set('id', decoupage_id) |
|
245 |
||
246 |
#node edits |
|
| 19 | 247 |
lxml.etree.SubElement(iri, 'edits') |
| 0 | 248 |
|
249 |
#write dom in Project.ldt |
|
250 |
project.ldt = lxml.etree.tostring(iri, pretty_print=True) |
|
251 |
||
252 |
#save Project |
|
253 |
project.save() |
|
254 |
return project |
|
255 |
||
256 |
||
257 |
def copy_ldt(project, new_project, user): |
|
258 |
new_project.ldt_id = str(uuid.uuid1()) |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
259 |
new_project.created_by = user.username |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
260 |
new_project.changed_by = user.username |
| 0 | 261 |
new_project.state = 1 |
262 |
|
|
263 |
|
|
264 |
"""create xml""" |
|
265 |
||
266 |
ldt = lxml.etree.fromstring(project.ldt.encode("utf-8")) |
|
267 |
res = ldt.xpath("/iri/project") |
|
268 |
for elementProject in res: |
|
269 |
elementProject.set('abstract', "") |
|
270 |
elementProject.set('title', new_project.title) |
|
271 |
elementProject.set('user', user.username) |
|
272 |
elementProject.set('id', new_project.ldt_id) |
|
273 |
||
274 |
new_project.ldt = lxml.etree.tostring(ldt, pretty_print=True) |
|
275 |
||
276 |
#save Project |
|
277 |
new_project.save() |
|
278 |
return new_project |
|
279 |
||
280 |
def create_empty_iri(file, content, username): |
|
281 |
||
282 |
iri = lxml.etree.Element('iri') |
|
283 |
doc = lxml.etree.ElementTree(iri) |
|
284 |
||
285 |
head = lxml.etree.SubElement(iri, 'head') |
|
286 |
meta_id = lxml.etree.SubElement(head, 'meta') |
|
287 |
meta_id.set(u'name', u'id') |
|
288 |
meta_id.set(u'content', unicode(content.iri_id)) |
|
289 |
meta_title = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
290 |
meta_title.set(u'name', u'title') |
| 0 | 291 |
meta_title.set(u'content', unicode(content.title)) |
292 |
meta_abstract = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
293 |
meta_abstract.set(u'name', u'abstract') |
| 0 | 294 |
meta_abstract.set(u'content', unicode(content.description)) |
295 |
meta_author = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
296 |
meta_author.set(u'name', u'author') |
| 0 | 297 |
meta_author.set(u'content', unicode(username)) |
298 |
meta_contributor = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
299 |
meta_contributor.set(u'name', u'contributor') |
| 0 | 300 |
meta_contributor.set(u'content', unicode(username)) |
301 |
meta_date = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
302 |
meta_date.set(u'name', u'date') |
| 0 | 303 |
meta_date.set(u'content', unicode(datetime.date.today().isoformat())) |
304 |
meta_copyright = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
305 |
meta_copyright.set(u'name', u'copyright') |
| 0 | 306 |
meta_copyright.set(u'content', u'IRI') |
307 |
meta_type = lxml.etree.SubElement(head, 'meta') |
|
308 |
meta_type.set(u'name', u'type') |
|
309 |
meta_type.set(u'content', u'video') |
|
310 |
||
311 |
body = lxml.etree.SubElement(iri, 'body') |
|
| 19 | 312 |
lxml.etree.SubElement(body, 'ensembles') |
313 |
lxml.etree.SubElement(body, 'links') |
|
| 0 | 314 |
|
315 |
medias = lxml.etree.SubElement(body, 'medias') |
|
316 |
||
317 |
media_video = lxml.etree.SubElement(medias, 'media') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
318 |
media_video.set(u'id', u'video') |
| 0 | 319 |
video = lxml.etree.SubElement(media_video, 'video') |
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
320 |
video.set(u'src', unicode(content.stream_src)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
321 |
video.set(u'id', unicode(content.iri_id)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
322 |
video.set(u'dur', unicode(content.duration)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
323 |
video.set(u'begin', u'0') |
| 0 | 324 |
|
325 |
media_tool = lxml.etree.SubElement(medias, 'media') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
326 |
media_tool.set(u'id', u'tool') |
| 19 | 327 |
lxml.etree.SubElement(media_tool, 'tool') |
| 0 | 328 |
|
| 19 | 329 |
lxml.etree.SubElement(body, 'display') |
| 0 | 330 |
|
331 |
doc.write(file, pretty_print=True) |
|
332 |
||
333 |
||
334 |
def update_iri(filepath, content, username): |
|
335 |
||
336 |
# open xml |
|
337 |
doc = lxml.etree.parse(filepath) |
|
338 |
||
339 |
res = doc.xpath("/iri/head/meta") |
|
340 |
# update meta |
|
341 |
||
342 |
for meta_node in res: |
|
343 |
meta_name = meta_node.get("name") |
|
344 |
content_attr = None |
|
345 |
if meta_name == u'id': |
|
346 |
content_attr = unicode(content.iri_id) |
|
347 |
elif meta_name == u'title': |
|
348 |
content_attr = unicode(content.title) |
|
349 |
elif meta_name == u'abstract': |
|
350 |
content_attr = unicode(content.description) |
|
351 |
elif meta_name == u'contributor': |
|
352 |
content_attr = unicode(username) |
|
353 |
elif meta_name == u"date": |
|
354 |
content_attr = unicode(datetime.date.today().isoformat()) |
|
355 |
if content_attr is not None: |
|
356 |
meta_node.set(u"content", content_attr) |
|
357 |
||
358 |
res = doc.xpath("/iri/body/medias/media[@id='video']/video") |
|
359 |
||
360 |
if len(res) > 0: |
|
361 |
video_node = res[0] |
|
362 |
video_node.set(u'src', unicode(content.stream_src)) |
|
363 |
video_node.set(u'dur', unicode(content.duration)) |
|
364 |
video_node.set(u'id', unicode(content.iri_id)) |
|
365 |
# update video |
|
366 |
||
367 |
f = open(filepath, "w") |
|
368 |
try: |
|
369 |
doc.write(f, encoding="UTF-8", pretty_print=True, xml_declaration=True) |
|
370 |
finally: |
|
371 |
f.close() |