def parseHybrid(self, sds): xmltvCounter = 5000 for muxML in sds.getroot().findall("Multiplexer"): # create a mux if doesn't exist try: mux = DvbMux.objects.get(fec_hp = muxML.attrib['fec_hp'], fec_lp = muxML.attrib['fec_lp'], freq = int(muxML.attrib['freq']), modulation = muxML.attrib['modulation'], symbolRate = int(muxML.attrib['symbol_rate'])) except ObjectDoesNotExist: mux = DvbMux(fec_hp = muxML.attrib['fec_hp'], fec_lp = muxML.attrib['fec_lp'], freq = int(muxML.attrib['freq']), modulation = muxML.attrib['modulation'], symbolRate = int(muxML.attrib['symbol_rate'])) mux.save() # populate mux with channels for chML in muxML.findall("Service"): xmltvML = chML.find("XMLTV"); if xmltvML.attrib['id'] == '--': self.stderr.write("* Warn: auto-assign XMLTV ID %d to %s \n"% (xmltvCounter, chML.find('Name').attrib['value'])) xmltvID = xmltvCounter xmltvCounter += 1 else: xmltvID = int(xmltvML.attrib['id']); chML.remove(xmltvML) try: chan = Channel.objects.get(xmltvID=xmltvID) except ObjectDoesNotExist: chan = Channel() chan.xmltvID = xmltvID nameML = chML.find('Name'); chan.name = nameML.attrib['value']; chML.remove(nameML) lcnML = chML.find('LCN'); chan.lcn = int(lcnML.attrib['value']); chML.remove(lcnML) rateML = chML.find("Rating") if rateML != None: chan.mpaa = rateML.attrib['value'] chML.remove(rateML) else: chan.mpaa = u'G' chan.tune = ET.tostring(chML, encoding='utf-8') chan.mux = mux chan.mode = u'DVB' chan.chanType = chML.attrib['type'] try : chan.save() except Exception as e: self.stderr.write("Failed to save channel %s, reason %s\n" % (chan, e))