web/ldt/ldt_utils/fileimport.py
changeset 54 24397932219d
parent 10 84e31387a741
child 57 3a3c15c462f8
equal deleted inserted replaced
53:1fcf0bd88ba3 54:24397932219d
    48     def processIri(self):
    48     def processIri(self):
    49         # for just import a file ldt and get the title for every media
    49         # for just import a file ldt and get the title for every media
    50         if 'http' in self.src:
    50         if 'http' in self.src:
    51             url = urllib.urlopen(self.src)
    51             url = urllib.urlopen(self.src)
    52             doc = xml.dom.minidom.parse(url)
    52             doc = xml.dom.minidom.parse(url)
    53             doc = Ft.Xml.Domlette.ConvertDocument(doc)             
       
    54             con = xml.xpath.Context.Context(doc, 1, 1, None)
       
    55             #open .iri and get the title
       
    56             res = xml.xpath.Evaluate("/iri/head/meta[@name='title']/@content", context=con)
       
    57             self.title = res[0].value
       
    58             
       
    59         #for import a zip, get title and copy file .iri in the media directory
    53         #for import a zip, get title and copy file .iri in the media directory
    60         else:
    54         else:
    61             path = os.path.join(self.basepath, self.src)
    55             path = os.path.join(self.basepath, self.src)
    62             doc = xml.dom.minidom.parse(path)
    56             doc = xml.dom.minidom.parse(path)
    63             
    57         
    64             con = xml.xpath.Context.Context(doc, 1, 1, None)
    58         
    65             
    59         doc = Ft.Xml.Domlette.ConvertDocument(doc) 
    66             res = xml.xpath.Evaluate("/iri/head/meta[@name='title']/@content", context=con)
    60         con = xml.xpath.Context.Context(doc, 1, 1, None)
    67             self.title = res[0].value
    61         
       
    62         res = xml.xpath.Evaluate("/iri/head/meta[@name='title']/@content", context=con)
       
    63         self.title = res[0].value
       
    64 
    68             
    65             
    69         res = xml.xpath.Evaluate("/iri/body/ensembles",context=con)
    66         res = xml.xpath.Evaluate("/iri/body/ensembles",context=con)
    70         ensemblesnode = res[0]
    67         ensemblesnode = res[0]
    71 
    68 
    72         ensembleids = []
    69         ensembleids = []
   103                     ensembleids.append(ensembleid)
   100                     ensembleids.append(ensembleid)
   104                     ensemblesnode.appendChild(cloneNode)
   101                     ensemblesnode.appendChild(cloneNode)
   105 
   102 
   106         res = xml.xpath.Evaluate("/iri/body/medias/media[@id='video']/video", context=con)
   103         res = xml.xpath.Evaluate("/iri/body/medias/media[@id='video']/video", context=con)
   107         if self.flatten:
   104         if self.flatten:
   108             src_video = res[0].getAttribute('src')
   105             src_video = res[0].getAttributeNS(None,'src')
   109             self.videourl = os.path.basename(src_video)
   106             self.videourl = os.path.basename(src_video)
   110             res[0].setAttributeNS(None,'src', self.videourl)
   107             res[0].setAttributeNS(None,'src', self.videourl)
   111         self.duration = res[0].getAttributeNS(None, u'dur')
   108         self.duration = res[0].getAttributeNS(None, u'dur')
   112             
   109             
   113         f = open(path, "w")
   110         f = open(path, "w")