コード例 #1
0
ファイル: navixboxee.py プロジェクト: Mindman4/navi-x
def ParsePlaylist(URL='', mediaitem=CMediaItem(), reload=True, view=''):
    if reload == False:
        listcontrol = mc.GetWindow(14000).GetList(GetListView()).GetItems()
        stackitem = mc.GetWindow(14000).GetList(555).GetItem(0)
        view = stackitem.GetProperty("view")
        SetListView(view)
        mc.GetWindow(14000).GetList(GetListView()).SetFocus()
        mc.GetWindow(14000).GetList(GetListView()).SetItems(listcontrol)
        
        #pos = stackitem.GetProperty("focusseditem")
        #mc.GetWindow(14000).GetList(GetListView()).SetFocusedItem(pos) 
        return

    if URL != '':
        mediaitem=CMediaItem()
        mediaitem.URL = URL
        mediaitem.type = 'playlist'

    mc.ShowDialogWait()
    playlist = CPlayList()
                        
    type = mediaitem.GetType()
    ##mc.ShowDialogOk("Debug", "Parse mediaitem of type " + type)
    
    listcontrol = mc.GetWindow(14000).GetList(GetListView()).GetItems()
    del listcontrol[:]
    
    #load the playlist
    if type == 'rss_flickr_daily':
        result = playlist.load_rss_flickr_daily(URL, mediaitem)                
    elif type[0:3] == 'rss':
        result = playlist.load_rss_20(URL, mediaitem)
    elif type[0:4] == 'atom':
        result = playlist.load_atom_10(URL, mediaitem)
    elif type == 'opml':
        result = playlist.load_opml_10(URL, mediaitem)
    elif type == 'html_youtube':
        result = playlist.load_html_youtube(URL, mediaitem)
    elif type == 'xml_shoutcast':
        result = playlist.load_xml_shoutcast(URL, mediaitem)
    elif type == 'xml_applemovie':
        result = playlist.load_xml_applemovie(URL, mediaitem)
    elif type == 'directory':
        result = playlist.load_dir(URL, mediaitem)
    else: #assume playlist file
        result = playlist.load_plx(URL, mediaitem)
    
###    playlist.save(RootDir + 'source.plx')

    if result == -1: #error
        mc.ShowDialogOk("Error", "This playlist requires a newer Navi-X version")
    elif result == -2: #error
        mc.ShowDialogOk("Error", "Cannot open file.")
                
    if result != 0: #failure
        return -1
    
    #display the new URL on top of the screen
    if len(playlist.title) > 0:
        title = playlist.title # + ' - (' + playlist.URL + ')'
    else:
        title = playlist.URL

    #remove the [COLOR] tags from the title as Boxee doesn't seem to support them
    #todo: this still strips out >> and following from labels but it's better than nothing
    reg1 = "(\[.*?\])"
    title = re.sub(reg1, '', title)

    stackitem = mc.ListItem()
    stackitem.SetProperty("URL", mediaitem.URL)
    stackitem.SetProperty("listtitle", title)
    stackitem.SetProperty("view", playlist.view)
    #stackitem.SetProperty("focusseditem", mc.GetWindow(14000).GetList(GetListView()).GetFocusedItem())
    
    #set the background image
    m = playlist.background
    if (m == 'default') or (m == 'previous'): #default BG image
        stackitem.SetProperty("bgimage",imageDir + background_image1)
    else:
        stackitem.SetProperty("bgimage",playlist.background)
    
    stacklist = mc.ListItems()
    stacklist.append(stackitem)
    mc.GetWindow(14000).GetList(555).SetItems(stacklist)

    today=datetime.date.today()
    ## CPlayList -> mc.ListItems
    for i in range(0, playlist.size()):
        m = playlist.list[i]
        if int(m.version) <= int(plxVersion):

            icon, thumb = getPlEntryThumb(m, playlist)
            
            # set label2      
            label2=''
            if m.date != '':
                l=m.date.split('-')
                entry_date = datetime.date(int(l[0]), int(l[1]), int(l[2]))
                days_past = (today-entry_date).days
                if days_past <= 10:
                    if days_past <= 0:
                        label2 = 'NEW today'
                    elif days_past == 1:
                        label2 = 'NEW yesterday'
                    else:
                        label2 = 'NEW ('+ str(days_past) + ' days ago)'
                    
            if m.description != '':
                label2 = label2 + ' >'

            item = mc.ListItem()          
            item.SetLabel(m.name)
            if m.URL != "":
                item.SetPath(m.URL + " : " + m.processor )
            item.SetProperty('label2', label2)
            item.SetProperty('description', m.description)
            item.SetProperty('background', m.background)
            item.SetProperty('processor', m.processor )
            item.SetProperty('thumb', m.thumb)
            item.SetProperty('url', m.URL )
            item.SetProperty('rating', imageDir + "rating" + m.rating + ".png" )
                        
            item.SetProperty('media_type', m.type)
            
            if (m.thumb != 'default'):
                item.SetThumbnail(m.thumb)
            elif  playlist.logo != 'none':
                item.SetThumbnail(playlist.logo)
            else:
                item.SetThumbnail(thumb)
            
            item.SetProperty('icon', icon)
            ##mc.ShowDialogOk("item", "Label = " + item.GetLabel() + "Icon = " + item.GetIcon() + "Thumb = " + item.GetThumbnail() )
            listcontrol.append(item)

    if view != '':
        playlist.view = view

    newview = SetListView(playlist.view, passive=True)
    mc.GetWindow(14000).GetList(newview).SetItems(listcontrol)        #set displayed list
    SetListView(playlist.view, passive=False)
    mc.GetWindow(14000).GetList(newview).SetFocus()    
    mc.HideDialogWait()
        
    return 0           
コード例 #2
0
ファイル: navixboxee.py プロジェクト: wolfenbit/navi-x
def ParsePlaylist(URL='', mediaitem=CMediaItem(), reload=True, view=''):
    if reload == False:
        listcontrol = mc.GetWindow(14000).GetList(GetListView()).GetItems()
        stackitem = mc.GetWindow(14000).GetList(555).GetItem(0)
        view = stackitem.GetProperty("view")
        SetListView(view)
        mc.GetWindow(14000).GetList(GetListView()).SetFocus()
        mc.GetWindow(14000).GetList(GetListView()).SetItems(listcontrol)

        #pos = stackitem.GetProperty("focusseditem")
        #mc.GetWindow(14000).GetList(GetListView()).SetFocusedItem(pos)
        return

    if URL != '':
        mediaitem = CMediaItem()
        mediaitem.URL = URL
        mediaitem.type = 'playlist'

    mc.ShowDialogWait()
    playlist = CPlayList()

    type = mediaitem.GetType()
    ##mc.ShowDialogOk("Debug", "Parse mediaitem of type " + type)

    listcontrol = mc.GetWindow(14000).GetList(GetListView()).GetItems()
    del listcontrol[:]

    #load the playlist
    if type == 'rss_flickr_daily':
        result = playlist.load_rss_flickr_daily(URL, mediaitem)
    elif type[0:3] == 'rss':
        result = playlist.load_rss_20(URL, mediaitem)
    elif type[0:4] == 'atom':
        result = playlist.load_atom_10(URL, mediaitem)
    elif type == 'opml':
        result = playlist.load_opml_10(URL, mediaitem)
    elif type == 'html_youtube':
        result = playlist.load_html_youtube(URL, mediaitem)
    elif type == 'xml_shoutcast':
        result = playlist.load_xml_shoutcast(URL, mediaitem)
    elif type == 'xml_applemovie':
        result = playlist.load_xml_applemovie(URL, mediaitem)
    elif type == 'directory':
        result = playlist.load_dir(URL, mediaitem)
    else:  #assume playlist file
        result = playlist.load_plx(URL, mediaitem)

###    playlist.save(RootDir + 'source.plx')

    if result == -1:  #error
        mc.ShowDialogOk("Error",
                        "This playlist requires a newer Navi-X version")
    elif result == -2:  #error
        mc.ShowDialogOk("Error", "Cannot open file.")

    if result != 0:  #failure
        return -1

    #display the new URL on top of the screen
    if len(playlist.title) > 0:
        title = playlist.title  # + ' - (' + playlist.URL + ')'
    else:
        title = playlist.URL

    #remove the [COLOR] tags from the title as Boxee doesn't seem to support them
    #todo: this still strips out >> and following from labels but it's better than nothing
    reg1 = "(\[.*?\])"
    title = re.sub(reg1, '', title)

    stackitem = mc.ListItem()
    stackitem.SetProperty("URL", mediaitem.URL)
    stackitem.SetProperty("listtitle", title)
    stackitem.SetProperty("view", playlist.view)
    #stackitem.SetProperty("focusseditem", mc.GetWindow(14000).GetList(GetListView()).GetFocusedItem())

    #set the background image
    m = playlist.background
    if (m == 'default') or (m == 'previous'):  #default BG image
        stackitem.SetProperty("bgimage", imageDir + background_image1)
    else:
        stackitem.SetProperty("bgimage", playlist.background)

    stacklist = mc.ListItems()
    stacklist.append(stackitem)
    mc.GetWindow(14000).GetList(555).SetItems(stacklist)

    today = datetime.date.today()
    ## CPlayList -> mc.ListItems
    for i in range(0, playlist.size()):
        m = playlist.list[i]
        if int(m.version) <= int(plxVersion):

            icon, thumb = getPlEntryThumb(m, playlist)

            # set label2
            label2 = ''
            if m.date != '':
                l = m.date.split('-')
                entry_date = datetime.date(int(l[0]), int(l[1]), int(l[2]))
                days_past = (today - entry_date).days
                if days_past <= 10:
                    if days_past <= 0:
                        label2 = 'NEW today'
                    elif days_past == 1:
                        label2 = 'NEW yesterday'
                    else:
                        label2 = 'NEW (' + str(days_past) + ' days ago)'

            if m.description != '':
                label2 = label2 + ' >'

            item = mc.ListItem()
            item.SetLabel(m.name)
            if m.URL != "":
                item.SetPath(m.URL + " : " + m.processor)
            item.SetProperty('label2', label2)
            item.SetProperty('description', m.description)
            item.SetProperty('background', m.background)
            item.SetProperty('processor', m.processor)
            item.SetProperty('thumb', m.thumb)
            item.SetProperty('url', m.URL)
            item.SetProperty('rating', imageDir + "rating" + m.rating + ".png")

            item.SetProperty('media_type', m.type)

            if (m.thumb != 'default'):
                item.SetThumbnail(m.thumb)
            elif playlist.logo != 'none':
                item.SetThumbnail(playlist.logo)
            else:
                item.SetThumbnail(thumb)

            item.SetProperty('icon', icon)
            ##mc.ShowDialogOk("item", "Label = " + item.GetLabel() + "Icon = " + item.GetIcon() + "Thumb = " + item.GetThumbnail() )
            listcontrol.append(item)

    if view != '':
        playlist.view = view

    newview = SetListView(playlist.view, passive=True)
    mc.GetWindow(14000).GetList(newview).SetItems(
        listcontrol)  #set displayed list
    SetListView(playlist.view, passive=False)
    mc.GetWindow(14000).GetList(newview).SetFocus()
    mc.HideDialogWait()

    return 0