예제 #1
0
def WebTVMostViewedMenu(sender, days=7):
    """
    Show a most viewed web tv menu.
    """
    dir = MediaContainer(viewGroup='Details', title2=sender.itemTitle)
    
    # Fetch most viewed clips
    url = '%s/ml/topp12.aspx?dager=%s' % (BASE_URL_WEBTV, days)
    Log('Fetching %s' % url)
    
    page = XML.ElementFromURL(url, isHTML=True, cacheTime=0 , encoding='utf-8')
    program_elements = page.xpath('//ul')[0]
    
    # Display error message if there's no content
    if not program_elements:
        return (MessageContainer(header=L('title'), message=L('webtv_error_nocontent'), title1=L('title')))
    
    for program_element in program_elements:
        Log(program_element)
        # Program title and description
        
        img = program_element.xpath('./div/a/img')[0].get('src')
        title = fix_chars(program_element.xpath('./div/h3/a')[0].text)
        
        # Program image and clip URL
        html_link = program_element.xpath('./div/a')[0].get('href')
        desc = fix_chars(program_element.xpath('./div/div[@class="summary"]/p')[0].text)
        
        # Append the item to the list
        dir.Append(WindowsMediaVideoItem(_get_wmv_link(html_link), title=title, summary=desc, thumb=img, width=768, height=432))
    
    return dir
예제 #2
0
def WebTVProgramMenu(sender, projectId=None, categoryId=None, programImage=None):
    """
    Shows the elements of a program project or category.
    """
    dir = MediaContainer(viewGroup='Details', title2=sender.itemTitle)
    
    # Fetch program content 
    if projectId:
        url = '%s/prosjekt/%s/' % (BASE_URL_WEBTV, projectId)
        page = XML.ElementFromURL(url, isHTML=True, cacheTime=CACHE_HTML_INTERVAL, encoding='utf-8')
        elements = page.xpath('//div[@class="nettv-list"]/ul')[0]
        
    elif categoryId:
        url = '%s/menyfragment.aspx?type=category&id=%s' % (BASE_URL_WEBTV, categoryId)
        Log('Fetching %s' % url)
        elements = XML.ElementFromURL(url, isHTML=True, cacheTime=CACHE_HTML_INTERVAL) # , encoding='utf-8'
    
    # Display error message if there's no content
    if not elements:
        return (MessageContainer(header=L('title'), message=L('webtv_error_nocontent'), title1=L('title')))
    
    for element in elements:
        
        try:
            elem_a = element.xpath('./a')[0]
        except IndexError:
            elem_a = element
            if not elem_a.get('href'):
                break
        
        # Link is a clip
        if elem_a.get('href').find('klipp') != -1:
            
            # Title
            raw_title = fix_chars(elem_a.get('title'))
            Log('Raw clip title: %s' % raw_title)
            
            # Split title and add as a description
            title = raw_title
            desc = None
            
            if raw_title.find(' - ') != -1:
                split_title = raw_title.split(' - ')
                title = split_title[0]
                desc = ' - '.join(split_title[1:])
            
            # Link and MMS URL
            html_link = elem_a.get('href')
            clip_mms_url = _get_wmv_link(html_link)
            
            # TODO Does not support URLs with unicode characters
            try:
                dir.Append(WindowsMediaVideoItem(clip_mms_url, title=title, summary=desc, thumb=programImage, width=768, height=432))
            except:
                Log('Could not add %s to menu, illegal characters in URL' % title)
        
        
        # Link is a category
        elif elem_a.get('href').find('kategori') != -1:
            
            # Title
            raw_title = fix_chars(elem_a.get('title'))
            Log('Raw category title: %s' % raw_title)
            
            # Split title and add as a description
            title = raw_title
            desc = None
            
            if raw_title.find(' - ') != -1:
                split_title = raw_title.split(' - ')
                title = split_title[0]
                desc = ' - '.join(split_title[1:])
            
            category_id = elem_a.get('href').split('/')[-1]
            
            Log('Added category: %s' % title)
            
            dir.Append(Function(DirectoryItem(WebTVProgramMenu, title=title, summary=desc, thumb=programImage), categoryId=category_id, programImage=programImage))
    
    return dir