magicbadger / odr-radioepg-bridge

Creates a DAB EPG bitstream directly from the ODR multiplex configuration file, using RadioDNS to lookup SI and PI documents.
Apache License 2.0
1 stars 3 forks source link

Blank elements within a service throw errors #7

Open nickpiggott opened 5 years ago

nickpiggott commented 5 years ago

For example, if a <keyword> element is null (e.g. <keyword />) then the parser errors.

I changed the code at line from around 743 to check if elements have content... for example

# keywords 
  for child in service_element.findall("spi:keywords", namespaces):
    if len(child) > 0 : service.keywords.extend(parse_keywords(child))

It might be better to fix this in the relevant functions (parse_keywords, parse_descriptions etc.).

nickpiggott commented 5 years ago

Scrub that, I changed each of the relevant parse functions.

def parse_multimedia(mediaElement):          
    type = None    
    mime = None    
    width = None   
    height = None  
    url = None     
    if mediaElement.attrib.has_key('type'):  
        type_str = mediaElement.attrib['type']            
        if type_str == 'logo_colour_square': type = Multimedia.LOGO_COLOUR_SQUARE   
        if type_str == 'logo_colour_rectangle': type = Multimedia.LOGO_COLOUR_RECTANGLE          
        if type_str == 'logo_unrestricted':  
            type = Multimedia.LOGO_UNRESTRICTED           
            if not mediaElement.attrib.has_key('mimeValue') or not mediaElement.attrib.has_key('width') or not mediaElement.attrib.has_key('height'):
   raise ValueError('must specify mimeValue, width and height for unrestricted logo: %s', mediaElement)       
    if mediaElement.attrib.has_key('mimeValue'): mime = mediaElement.attrib['mimeValue']         
    if mediaElement.attrib.has_key('width'): width = int(mediaElement.attrib['width'])           
    if mediaElement.attrib.has_key('height'): height = int(mediaElement.attrib['height'])        
    if mediaElement.attrib.has_key('url'): url = mediaElement.attrib['url']         

    multimedia = Multimedia(url, type=type, content=mime, height=height, width=width)            
    return multimedia           

def parse_genre(genreElement):  
    if genreElement.text:       
        genre = Genre(genreElement.attrib['href'])        
        genre.name = genreElement.text       
    else:          
        genre = None            

    return genre   

def parse_link(linkElement):    
    if linkElement.attrib.has_key('uri'):    
        link = Link(linkElement.attrib['uri'])            
        if linkElement.attrib.has_key('description'):     
            link.description = linkElement.attrib['description']       
        if linkElement.attrib.has_key('mimeValue'):       
            link.content = linkElement.attrib['mimeValue']
        if linkElement.attrib.has_key('expiryTime'):      
            link.expiry = isodate.parse_datetime(linkElement.attrib['expiryTime'])  
    else:          
        link = None

    return link       

and so on...