def displayFeedListing( name_site ):
    for site in array_sites:
        if site.name == urllib.unquote_plus(name_site):
            for feed in site.feeds:
                path = _path + '?action=2&site=' + urllib.quote_plus(site.name) + '&feed=' + urllib.quote_plus(feed.name)
                XBMCExtensions.addDirectoryItem(feed.name, _handle, path, '', True)
            XBMCExtensions.endOfDirectory(_handle)
def displaySiteListing():    
    for site in array_sites:
        path =  _path + '?action=1&site=' + urllib.quote_plus(site.name)
        XBMCExtensions.addDirectoryItem(site.name, _handle, path, _pwd + '/' + site.image, True)
    path =  _path + '?action=3'
    XBMCExtensions.addDirectoryItem('Change Settings', _handle, path, '', False)
    XBMCExtensions.endOfDirectory(_handle)
def displayVideoListing( name_site, name_feed ):
    # Turn the ENUM value for video quality into a named string.
    if video_quality == '1':
        vq = 'hd'
    elif video_quality == '2':
        vq = 'low'
    elif video_quality == '3':
        vq = 'mobile'
    else:
        vq = 'high'
    
    # Get the URL from the site's definition.
    url = ''
    for site in array_sites:
        if site.name == urllib.unquote_plus(name_site):
            for feed in site.feeds:
                if feed.name == urllib.unquote_plus(name_feed):
                    # If it's a video feed, use the user-selected video quality.
                    # Else for audio, always use "high".
                    if feed.type == 'video':
                        url = feed.urls[vq]
                    else:
                        url = feed.urls['high']                    
                    # Swap the username and password into the URL.                    
                    url = url.replace('${USERNAME}', wm_username)
                    url = url.replace('${PASSWORD}', wm_password)
    
    try:
        doc = xml.dom.minidom.parseString(urllib.urlopen(url).read())
    except:
        XBMCExtensions.showDialog('Error', 'Could not retrieve list of videos.', 'Please ensure your username/password is valid.')
        return 0
    
    # Iterate through the list of items in the feed.
    for node_item in doc.getElementsByTagName('item'):
        for node_title in node_item.getElementsByTagName('title'):
            title = SimplerXML.getText(node_title, 'title')
        for node_link in node_item.getElementsByTagName('link'):
            link = SimplerXML.getText(node_link, 'link')
        XBMCExtensions.addDirectoryItem(title, _handle, link, '', False)
        
    XBMCExtensions.endOfDirectory(_handle)