|
0
|
1 |
#!/usr/bin/env python |
|
|
2 |
|
|
|
3 |
import requests |
|
|
4 |
from lxml import etree |
|
|
5 |
import sys |
|
|
6 |
import zipfile |
|
|
7 |
import re |
|
|
8 |
import slugify |
|
|
9 |
|
|
|
10 |
|
|
|
11 |
project_id = sys.argv[1] |
|
|
12 |
|
|
|
13 |
dlurl = "http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/space/ldt/project/" + project_id |
|
|
14 |
|
|
|
15 |
r = requests.get(dlurl) |
|
|
16 |
|
|
|
17 |
ldt_root = etree.fromstring(r.content) |
|
|
18 |
|
|
|
19 |
project_title = ldt_root.find("project").get("title") |
|
|
20 |
|
|
|
21 |
#create zipfile |
|
|
22 |
if project_title: |
|
|
23 |
basename = slugify.slugify(project_title) |
|
|
24 |
else: |
|
|
25 |
basename = project_id |
|
|
26 |
zf = zipfile.ZipFile(basename+".zip", "w") |
|
|
27 |
try: |
|
|
28 |
for i,media_node in enumerate(ldt_root.iterfind("medias/media")): |
|
|
29 |
iri_url = media_node.get("src") |
|
|
30 |
r_iri = requests.get(iri_url) |
|
|
31 |
iriname = "iri/%s_%d.iri" % (basename, i) |
|
|
32 |
zf.writestr(basename+"/"+iriname, r_iri.content) |
|
|
33 |
media_node.set("src", iriname) |
|
|
34 |
media_node.set("video", "") |
|
|
35 |
zf.writestr(basename+'/'+basename+".ldt", etree.tostring(ldt_root, xml_declaration=True, encoding='utf-8')) |
|
|
36 |
finally: |
|
|
37 |
zf.close() |