コード例 #1
0
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)
コード例 #2
0
def getSitesAndFeeds():
    doc = xml.dom.minidom.parse(_pwd + '/sites.xml')
    
    # Iterate through the list of sites in the XML feed.
    for node_site in doc.getElementsByTagName('site'):
        # Instantiate a Site object and assign its name.
        site = Site()
        site.name = node_site.getAttribute('name')
        site.image = node_site.getAttribute('image')
    
        # Retrieve the name of each feed to build the top-level menu.
        for node_feed in node_site.getElementsByTagName('feed'):
            feed = Feed()
            feed.name = node_feed.getAttribute('name')
            feed.type = node_feed.getAttribute('type')
            for node_url in node_feed.getElementsByTagName('url'):
                url_quality = node_url.getAttribute('quality')
                feed.urls[url_quality] = SimplerXML.getText(node_url, 'url')
            site.feeds.append(feed)
    
        array_sites.append(site)