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)
# Python (system) imports.
import sys
import os
import xml.dom.minidom
import urllib
from urlparse import urlparse

# Custom (this plugin) imports.
from Site import Site
from Feed import Feed
from SimplerXML import SimplerXML
from XBMCExtensions import XBMCExtensions

# Retrieve settings for the plugin.
plugin_id = 'plugin.video.whiskeymedia'
plugin_settings = XBMCExtensions.getSettings(plugin_id)
video_quality = plugin_settings.getSetting('video_quality')
wm_username = plugin_settings.getSetting('username')
wm_password = plugin_settings.getSetting('password')

# Get environmental settings.
_path = sys.argv[0]
_pwd = plugin_settings.getAddonInfo('path')
_handle = XBMCExtensions.getHandle()
_argv = XBMCExtensions.getPath()

# Store the list of sites and feeds inside them.
array_sites = []

# For the selected site and feed, create a list of menu items for the videos in the feed.
def displayVideoListing( name_site, name_feed ):