Example #1
0
def do_xml_user_response(context, provider, xml):
    result = []
    root = ET.fromstring(xml)
    do_xml_error(context, provider, root)

    contacts = root.find('contacts')
    if contacts is not None:
        for contact in contacts:
            user_id = contact.get('id')
            username = contact.get('username')
            display_name = contact.get('display_name')

            contact_item = DirectoryItem(display_name, context.create_uri(['user', user_id]))

            # portraits
            portraits = contact.find('portraits')
            if portraits is not None:
                for portrait in portraits:
                    height = int(portrait.get('height'))
                    if height >= 256:
                        contact_item.set_image(portrait.text)
                        break
                    pass
                pass

            contact_item.set_fanart(provider.get_fanart(context))
            result.append(contact_item)
            pass

        # add next page
        _do_next_page(result, contacts, context, provider)
        pass

    return result
Example #2
0
def do_xml_featured_response(context, provider, xml):
    root = ET.fromstring(xml)
    if not do_xml_error(context, provider, root):
        return []

    result = []
    for item in root:
        item_type = item.find('type').text
        if item_type == 'channel':
            channel_id = item.find('id').text
            channel_name = item.find('title').text
            channel_image = item.find('header_url').text

            channel_item = DirectoryItem(channel_name, context.create_uri(['channel', channel_id]),
                                         image=channel_image)
            channel_item.set_fanart(provider.get_fanart(context))
            result.append(channel_item)
            pass
        else:
            raise kodion.KodionException('Unknown type "%s" for featured' % item_type)
        pass
    return result