web/blinkster/ldt/models.py
changeset 29 cc9b7e14412b
parent 16 146d86480e85
child 35 8b65c9054eac
--- a/web/blinkster/ldt/models.py	Wed May 19 17:43:59 2010 +0200
+++ b/web/blinkster/ldt/models.py	Tue May 25 02:43:45 2010 +0200
@@ -1,4 +1,6 @@
 import os
+import xml
+import Ft.Xml
 
 from django.db import models
 from django.contrib import admin
@@ -30,6 +32,17 @@
     description = models.TextField(null=True)
     external_id = models.CharField(max_length=1024, null=True, blank=True)
     authors = models.ManyToManyField(Author)
+    duration = models.IntegerField(null=True, blank=True)
+
+    def get_duration(self):
+        if self.duration is None:
+            doc = xml.dom.minidom.parse(self.iri_file_path())
+            doc = Ft.Xml.Domlette.ConvertDocument(doc)        
+            con = xml.xpath.Context.Context(doc, 1, 1, None)
+            res = xml.xpath.Evaluate("/iri/body/medias/media[@id='video']/video", context=con)
+            self.duration = int(res[0].getAttributeNS(None, 'dur'))
+            self.save()
+        return self.duration
     
     def delete(self):
         super(Content, self).delete()