|
1 #! /usr/bin/env python |
|
2 |
|
3 from django.core.management import setup_environ |
|
4 from ldtplatform import settings |
|
5 |
|
6 setup_environ(settings) |
|
7 |
|
8 from django.db import connections |
|
9 import lxml.etree |
|
10 from ldt.ldt_utils.models import Media, Content |
|
11 |
|
12 cur = connections['migration_rs'].cursor() |
|
13 |
|
14 # Get all "regarssignes" contents |
|
15 cur.execute("SELECT * from ldt_content") |
|
16 rows = cur.fetchall() |
|
17 s = "Show me the databases:\n" |
|
18 for row in rows: |
|
19 s += "\n " + str(row) |
|
20 # (id-0, u'iri_id'-1, u'iri_url'-2, u'videopath'-3, datetime creation_date-4, datetime update_date-5, u'title'-6, description-7, eternal_id-8) |
|
21 # (1, u'laurentcantet_entrelesmurs', u'laurentcantet_entrelesmurs/laurentcantet_entrelesmurs.iri', u'rtmp://media.iri.centrepompidou.fr/ddc_player/video/regardssignes/', datetime.datetime(2010, 2, 17, 5, 24, 13, 69794, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)), datetime.datetime(2010, 2, 17, 5, 24, 13, 91656, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)), u'Entre Les Murs', None, None) |
|
22 # Get duration from the iri file |
|
23 prePath = settings.MEDIA_ROOT + u"ldt/" |
|
24 doc = lxml.etree.parse(prePath + row[2]) |
|
25 res = doc.xpath("/iri/body/medias/media[@id='video']/video") |
|
26 if len(res) > 0: |
|
27 try: |
|
28 dur = int(res[0].get(u'dur', 0) or 0) |
|
29 except: |
|
30 dur = 3600000 |
|
31 else: |
|
32 dur = 3600000 |
|
33 # Build platform media and platform content from "regarssignes" contents |
|
34 media = Media.objects.create(external_id=row[8], creation_date=row[4], update_date=row[5], videopath=row[3], duration=dur, |
|
35 description=row[7], title=row[6], src=(row[1] + u".flv"), mimetype_field="('video/x-flv', None)") |
|
36 media.save() |
|
37 |
|
38 content = Content.objects.create(iri_id=row[1], iriurl=row[2], creation_date=row[4], update_date=row[5], title=row[6], description=row[7], |
|
39 content_creation_date=row[4], duration=dur, media_obj=media) |
|
40 content.save() |
|
41 |