Exemple #1
0
    def browse(self, pluginparams):
        '''main action, load correct function'''
        offset = int(pluginparams.get("offset", 0))
        result = self.roonserver.browse(pluginparams["item_key"],
                                        pluginparams["item_path"], offset)
        if result:
            details = self.parse_folder_details(result["list"], pluginparams)
            xbmcplugin.setContent(ADDON_HANDLE, details["mediatype"])
            xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                                   details["title"])
            for item in result["items"]:
                self.create_listitem(item, details)
            xbmcplugin.addSortMethod(ADDON_HANDLE,
                                     xbmcplugin.SORT_METHOD_UNSORTED)
            # add next page button if needed
            if details["count"] > (len(result["items"]) + offset):
                label = "Next page..."
                offset += len(result["items"])
                url = "%s?action=browse&item_key=%s&offset=%s&item_path=%s" % (
                    PLUGIN_BASE, pluginparams["item_key"], offset,
                    pluginparams["item_path"])
                listitem = xbmcgui.ListItem(label)
                listitem.setProperty("isPlayable", "false")
                xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE,
                                            url=url,
                                            listitem=listitem,
                                            isFolder=True)

        xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def musicfolder(self):
     '''explore musicfolder on the server'''
     xbmcplugin.setContent(ADDON_HANDLE, "files")
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(744))
     params = self.params.get("params")
     request_str = "musicfolder 0 100000 tags:%s" % TAGS_FULL
     if params:
         request_str += " %s" % params
     result = self.lmsserver.send_request(request_str)
     if result:
         for item in result.get("folder_loop"):
             thumb = self.lmsserver.get_thumb(item)
             if item["type"] == "track":
                 item = self.get_songinfo(item["url"])
                 self.create_track_listitem(item)
             elif item["type"] == "playlist":
                 cmd = "command&params=playlist play %s" % item["url"]
                 self.create_generic_listitem("%s" % item["filename"],
                                              thumb, cmd, False)
             else:
                 cmd = "musicfolder&params=folder_id:%s" % item["id"]
                 self.create_generic_listitem("%s" % item["filename"],
                                              thumb, cmd)
     xbmcplugin.addSortMethod(ADDON_HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def favorites(self):
     '''get favorites from server'''
     xbmcplugin.setContent(ADDON_HANDLE, "files")
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(1036))
     request_str = "favorites items 0 100000 want_url:1 tags:%s" % TAGS_FULL
     params = self.params.get("params")
     if params:
         request_str += " %s" % params
     result = self.lmsserver.send_request(request_str)
     if result:
         for item in result.get("loop_loop"):
             thumb = self.lmsserver.get_thumb(item)
             if item.get("isaudio") and "title" in item:
                 track_details = self.lmsserver.trackdetails(item)
                 self.create_track_listitem(track_details)
             elif item["isaudio"] and "url" in item:
                 result = self.lmsserver.send_request(
                     "songinfo 0 100 tags:%s url:%s" %
                     (TAGS_FULL, item["url"]))
                 cmd = "command&params=" + quote_plus(
                     "favorites playlist play item_id:%s" % item["id"])
                 self.create_generic_listitem(item["name"], thumb, cmd,
                                              False)
             else:
                 cmd = "favorites&params=item_id:%s" % item["id"]
                 self.create_generic_listitem(item["name"], thumb, cmd)
     xbmcplugin.addSortMethod(ADDON_HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def genres(self):
     '''get genres from server'''
     xbmcplugin.setContent(ADDON_HANDLE, "files")
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(135))
     params = self.params.get("params")
     request_str = "genres 0 100000 tags:%s" % TAGS_FULL
     if params:
         request_str += " %s" % params
     result = self.lmsserver.send_request(request_str)
     if result:
         for item in result.get("genres_loop"):
             cmd = "tracks&params=genre_id:%s" % item["id"]
             thumb = self.lmsserver.get_thumb(item)
             contextmenu = []
             params = quote_plus("playlist loadalbum %s * *" %
                                 item["genre"])
             contextmenu.append((self.addon.getLocalizedString(32203),
                                 "RunPlugin(%s?action=command&params=%s)" %
                                 (PLUGIN_BASE, params)))
             params = quote_plus("playlist insertalbum %s * *" %
                                 item["genre"])
             contextmenu.append((self.addon.getLocalizedString(32204),
                                 "RunPlugin(%s?action=command&params=%s)" %
                                 (PLUGIN_BASE, params)))
             params = quote_plus("playlist addalbum %s * *" % item["genre"])
             contextmenu.append((self.addon.getLocalizedString(32205),
                                 "RunPlugin(%s?action=command&params=%s)" %
                                 (PLUGIN_BASE, params)))
             self.create_generic_listitem(item["genre"], thumb, cmd, True,
                                          contextmenu)
     xbmcplugin.addSortMethod(ADDON_HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
    def __init__( self ):
        listitems = getFullMovieSetsDetails( ADDON.getSetting( "allsets" ) == "true" )
        ok = self._add_directory_items( listitems )

        xbmcplugin.setProperty( int( sys.argv[ 1 ] ), "Content", "MovieSets" )
        xbmcplugin.setProperty( int( sys.argv[ 1 ] ), "TotalSets", str( len( listitems ) ) )
        #xbmcplugin.setProperty( int( sys.argv[ 1 ] ), "FolderName", ADDON_NAME )

        #xbmcplugin.setPluginCategory( int( sys.argv[ 1 ] ), ADDON_NAME )

        self._set_content( ok )
 def set_params_to_container(self, **kwargs):
     for k, v in viewitems(kwargs):
         if not k or not v:
             continue
         try:
             xbmcplugin.setProperty(
                 self.handle, u'Param.{}'.format(k),
                 u'{}'.format(v))  # Set params to container properties
         except Exception as exc:
             kodi_log(
                 u'Error: {}\nUnable to set Param.{} to {}'.format(
                     exc, k, v), 1)
 def set_params_to_container(self, **kwargs):
     params = {}
     for k, v in kwargs.items():
         if not k or not v:
             continue
         try:
             k = u'Param.{}'.format(k)
             v = u'{}'.format(v)
             params[k] = v
             xbmcplugin.setProperty(self.handle, k, v)  # Set params to container properties
         except Exception as exc:
             kodi_log(u'Error: {}\nUnable to set param {} to {}'.format(exc, k, v), 1)
     return params
Exemple #8
0
    def __init__(self):
        listitems = getFullMovieSetsDetails(
            ADDON.getSetting("allsets") == "true")
        ok = self._add_directory_items(listitems)

        xbmcplugin.setProperty(int(sys.argv[1]), "Content", "MovieSets")
        xbmcplugin.setProperty(int(sys.argv[1]), "TotalSets",
                               str(len(listitems)))
        #xbmcplugin.setProperty( int( sys.argv[ 1 ] ), "FolderName", ADDON_NAME )

        #xbmcplugin.setPluginCategory( int( sys.argv[ 1 ] ), ADDON_NAME )

        self._set_content(ok)
 def artists(self):
     '''get artists from server'''
     params = self.params.get("params")
     xbmcplugin.setContent(ADDON_HANDLE, "artists")
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(133))
     request_str = "artists 0 100000 tags:%s" % TAGS_FULL
     if params:
         request_str += " %s" % params
     result = self.lmsserver.send_request(request_str)
     if result:
         for item in result.get("artists_loop"):
             self.create_artist_listitem(item)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def tracks(self):
     '''get tracks from server'''
     params = self.params.get("params", "")
     xbmcplugin.setContent(ADDON_HANDLE, "songs")
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(134))
     request_str = "tracks 0 100000 tags:%s" % TAGS_BASIC
     if params:
         request_str += " %s" % params
     result = self.lmsserver.send_request(request_str)
     listitems = []
     if result:
         result = self.lmsserver.process_trackdetails(result["titles_loop"])
         result = [self.create_track_listitem(item) for item in result]
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def years(self):
     '''get years from server'''
     xbmcplugin.setContent(ADDON_HANDLE, "files")
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(652))
     params = self.params.get("params")
     request_str = "years 0 100000 tags:%s" % TAGS_FULL
     if params:
         request_str += " %s" % params
     result = self.lmsserver.send_request(request_str)
     if result:
         for item in result.get("years_loop"):
             cmd = "albums&params=year:%s" % item["year"]
             thumb = self.lmsserver.get_thumb(item)
             self.create_generic_listitem("%s" % item["year"], thumb, cmd)
     xbmcplugin.addSortMethod(ADDON_HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def playlists(self):
     '''get playlists from server'''
     xbmcplugin.setContent(ADDON_HANDLE, "files")
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(136))
     params = self.params.get("params")
     request_str = "playlists 0 100000 tags:%s" % TAGS_FULL
     if params:
         request_str += " %s" % params
     result = self.lmsserver.send_request(request_str)
     if result:
         for item in result.get("playlists_loop"):
             cmd = "playlisttracks&playlistid=%s" % item["id"]
             self.create_generic_listitem(item["playlist"],
                                          "DefaultMusicPlaylists.png", cmd)
     xbmcplugin.addSortMethod(ADDON_HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def globalsearch(self):
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(19140))
     xbmcplugin.setContent(ADDON_HANDLE, "files")
     kb = xbmc.Keyboard('', xbmc.getLocalizedString(16017))
     kb.doModal()
     if kb.isConfirmed():
         searchterm = kb.getText().replace(" ", "[SP]")
         result = self.lmsserver.send_request(
             "globalsearch items 0 10 search:%s" % searchterm)
         for item in result["loop_loop"]:
             params = "globalsearch items 0 100 item_id:%s" % item["id"]
             cmd = "browse&params=%s" % quote_plus(params)
             self.create_generic_listitem(item["name"],
                                          "DefaultMusicSearch.png", cmd)
     xbmcplugin.addSortMethod(ADDON_HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def albums(self):
     '''get albums from server'''
     params = self.params.get("params")
     xbmcplugin.setContent(ADDON_HANDLE, "albums")
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(132))
     request_str = "albums 0 100000 tags:%s" % TAGS_ALBUM
     if params:
         request_str += " %s" % params
         if "artist_id" in params:  # add All tracks entry
             self.create_generic_listitem("All Tracks",
                                          "DefaultMusicSongs.png",
                                          "tracks&params=%s" % params)
     result = self.lmsserver.send_request(request_str)
     if result:
         for item in result.get("albums_loop"):
             self.create_album_listitem(item)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def radios(self):
     '''get radio items'''
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(19183))
     xbmcplugin.setContent(ADDON_HANDLE, "files")
     request_str = "radios 0 100000 tags:%s" % TAGS_FULL
     result = self.lmsserver.send_request(request_str)
     if result:
         for item in result.get("radioss_loop"):
             if item["cmd"] == "search":
                 params = "%s items 0 100000 search:__TAGGEDINPUT__" % item[
                     "cmd"]
             else:
                 params = params = "%s items 0 100000" % item["cmd"]
             cmd = "browse&params=%s" % quote_plus(params)
             thumb = self.lmsserver.get_thumb(item)
             self.create_generic_listitem(item["name"], thumb, cmd)
     xbmcplugin.addSortMethod(ADDON_HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
Exemple #16
0
 def input_prompt(self, pluginparams):
     ''' ask input before browsing (used for search) '''
     dialog = xbmcgui.Dialog()
     input = dialog.input("Enter text").decode("utf-8")
     del dialog
     browse_params = {
         "hierarchy": "browse",
         "item_key": pluginparams["item_key"],
         "input": input
     }
     result = self.roonserver.send_request("browseload", browse_params)
     if result:
         details = self.parse_folder_details(result["list"], pluginparams)
         xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                                details["title"])
         for item in result["items"]:
             self.create_listitem(item, details)
         xbmcplugin.addSortMethod(ADDON_HANDLE,
                                  xbmcplugin.SORT_METHOD_UNSORTED)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
 def search(self):
     xbmcplugin.setProperty(ADDON_HANDLE, 'FolderName',
                            xbmc.getLocalizedString(19140))
     xbmcplugin.setContent(ADDON_HANDLE, "files")
     kb = xbmc.Keyboard('', xbmc.getLocalizedString(16017))
     kb.doModal()
     if kb.isConfirmed():
         searchterm = kb.getText().replace(" ", "[SP]")
         result = self.lmsserver.send_request("search 0 1 term:%s" %
                                              searchterm)
         if result:
             if result.get("artists_count"):  # artist items
                 label = "Artists (%s)" % result["artists_count"]
                 cmd = "artists&params=search:%s" % searchterm
                 self.create_generic_listitem(label,
                                              "DefaultMusicArtists.png",
                                              cmd)
             elif result.get("contributors_count"):  # artist items alt
                 label = "Artists (%s)" % result["contributors_count"]
                 cmd = "artists&params=search:%s" % searchterm
                 self.create_generic_listitem(label,
                                              "DefaultMusicArtists.png",
                                              cmd)
             if result.get("albums_count"):  # album items
                 label = "Albums (%s)" % result["albums_count"]
                 cmd = "albums&params=search:%s" % searchterm
                 self.create_generic_listitem(label,
                                              "DefaultMusicAlbums.png", cmd)
             if result.get("tracks_count"):  # track items
                 label = "Songs (%s)" % result["tracks_count"]
                 cmd = "tracks&params=search:%s" % searchterm
                 self.create_generic_listitem(label,
                                              "DefaultMusicSongs.png", cmd)
             if result.get("genres_count"):  # genre items
                 label = "Genres (%s)" % result["genres_count"]
                 cmd = "genres&params=search:%s" % searchterm
                 self.create_generic_listitem(label,
                                              "DefaultMusicGenres.png", cmd)
     xbmcplugin.addSortMethod(ADDON_HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
     xbmcplugin.endOfDirectory(handle=ADDON_HANDLE)
def setProperty( *args, **kwargs):
    """Sets a container property for this plugin.

    handle: integer - handle the plugin was started with.
    key: string - property name.
    value: string or unicode - value of property.

    Note:
        Key is NOT case sensitive.

    Example:
        xbmcplugin.setProperty(int(sys.argv[1]), 'Emulator', 'M.A.M.E.')
    """
    return mundane_xbmcplugin.setProperty(*args, **kwargs)
Exemple #19
0
    if len(rep) == 0:
        rep2 = re.compile('<h2><b>(.+?)</b>').findall(http)
        rep3 = re.compile('<a href="/(.+?)/details/">').findall(http)
        if (len(rep2) > 0 and len(rep3) > 0):
            listitem = xbmcgui.ListItem(rep2[0], rep3[0])
            xbmcplugin.addDirectoryItem(handle, url, listitem, False)
    xbmcplugin.endOfDirectory(handle)
elif (url.endswith('/getweather')):
    ## sample options: ?area=UPXX0016
    params = dict([part.split('=') for part in options.lstrip('?').split('&')])
    http = getHttp(SITE_URL + urllib2.quote(
        '/%s/' % (params['area'].decode(XBMC_ENCODING).encode(SITE_ENCODING))))

    rep = re.compile('<h2><b>(.+?)</b>').findall(http)
    if len(rep) > 0:
        xbmcplugin.setProperty(handle, 'Location', rep[0])

    rep = re.compile('<span>Ветер: (.+?)</span>').findall(http)
    if len(rep) > 0:
        rep2 = re.compile(', (.+?) м/с').findall(rep[0])
        if len(rep2) > 0:
            currentWind = int(rep2[0])
        xbmcplugin.setProperty(handle, 'Current.Wind', rep[0])

    rep = re.compile('<span>Влажность: (.+?)%</span>').findall(http)
    if len(rep) > 0:
        humidity = rep[0]
        xbmcplugin.setProperty(handle, 'Current.Humidity', rep[0] + '%')

    rep = re.compile('<div>(.+?)</div>(\s+?)<span>Ветер:').findall(http)
    if len(rep) > 0:
Exemple #20
0
import os
import sys
from traceback import print_exc

import xbmc
import xbmcgui
import xbmcplugin
from xbmcaddon import Addon

# addon constants
__settings__  = Addon( "repository.xbmc.builds" ) # get Addon object
__addonName__ = __settings__.getAddonInfo( "name" ) # get Addon Name
__addonId__   = __settings__.getAddonInfo( "id" ) # get Addon Name


xbmcplugin.setProperty( int( sys.argv[ 1 ] ), "AddonName", __addonName__ )

CONDITION = "[stringcompare(container.property(AddonName),%s)]" % __addonName__


class addonWindow( xbmcgui.Window ):
    def __init__( self, windowId, skin="confluence", **kwargs ):
        self.windowId = windowId
        if skin in xbmc.getSkinDir().lower():
            try:    
                xbmcgui.lock()
                xbmcgui.Window.__init__( self, self.windowId )
                self.controlsId = kwargs.get( "controlsId" )
                self.AddonCategory = xbmc.getInfoLabel( "ListItem.Property(Addon.Name)" )
                if __addonName__ == self.AddonCategory: self.AddonCategory = ""
Exemple #21
0
def mainWalk(ex_link='', json_file='', fname='', select=''):
    items = []
    folders = []
    contextmenu = []
    pagination = (False, False)
    contextO, contextI = ['F_ADD'], []
    if fname == 'Wybrane':
        contextO = ['F_REM', 'F_DEL']
    if ex_link == '' or ex_link.startswith('/'):
        data = cda.ReadJsonFile(json_file) if json_file else get_Root()
        itype = fragdict(json_file).get('info-type')
        if itype:
            xbmcplugin.setContent(addon_handle, itype)
        items, folders = cda.jsconWalk(data, ex_link)
    username = my_addon.getSetting('username')
    ure = re.escape(username) if username else r'[^/]+'
    if re.match(
            r'^.*?://[^/]+/[^/]+(?:/folder-glowny|/ulubione.*|/folder/.+)?(?:vfilm)?(?:/\d+)?(?:[?#].*)?$',
            ex_link):
        recursive = (my_addon.getSetting('UserFolder.content.paginatoin') !=
                     'true')
        items, folders, pagination, tree = cda.get_UserFolder_content(
            urlF=ex_link, recursive=recursive, filtr_items={})
        if tree:
            xbmcplugin.setProperty(addon_handle, 'FolderName', tree[-1].name)
            contextO += ['F_USER']
            if ex_link != tree[-1].url:
                contextO += ['F_USER', 'F_FOLDER']
            if len(tree) > 1:
                contextO += ['F_USER', 'F_FOLDER_UP']
        elif re.match(
                '^.*?://.*/[^/]+/?$',
                ex_link):  # user view (last added and link to root folder)
            contextI += ['F_FOLDER']
    # elif 'obserwowani' in ex_link:
    #     items, folders = cda.get_UserFolder_obserwowani(ex_link)
    # elif '/historia' in ex_link or '/obejrzyj-pozniej' in ex_link:
    elif re.match(
            r'^.*?://[^/]+/%s(?:/historia|/obejrzyj-pozniej)?(?:vfilm)?(?:/\d+)?(?:[?#].*)?$'
            % ure, ex_link):
        items, folders, pagination = cda.get_UserFolder_historia(ex_link)
    if pagination[0]:
        addDir(u'[COLOR gold]<< Poprzednia strona <<[/COLOR]',
               ex_link=pagination[0],
               mode='walk',
               iconImage=media('prev.png'),
               properties={'SpecialSort': 'top'})
    N_folders = len(items)
    N_items = len(items)
    for f in folders:
        tmp_json_file = f.get('jsonfile', json_file)
        title = f.get('title') + f.get('count', '')
        f['plot'] = '%s\n%s' % (f.get('plot', ''), f.get('update', ''))
        contextmenu = []
        if f.get('lib'):
            contextmenu.append(
                (u'[COLOR lightblue]Dodaj zawartość do Biblioteki[/COLOR]',
                 'RunPlugin(plugin://%s?mode=AddRootFolder&json_file=%s)' %
                 (my_addon_id, urllib.quote_plus(tmp_json_file))))
        if f.get('url'):
            contextmenu.extend(GetContextMenuFoldersXX(f, contextO))
        li = addDir(title,
                    ex_link=f.get('url'),
                    json_file=tmp_json_file,
                    mode='walk',
                    iconImage=f.get('img', ''),
                    infoLabels=f,
                    fanart=f.get('fanart', ''),
                    contextmenu=contextmenu,
                    totalItems=N_folders + N_items)
        if select and select == title:
            li.select(True)
            select = ''
    list_of_items = []
    for item in items:
        aitem = add_Item(name=item.get('title').encode('utf-8'),
                         url=item.get('url'),
                         mode='decodeVideo',
                         contextO=contextO + contextI,
                         iconImage=item.get('img'),
                         infoLabels=item,
                         IsPlayable=True,
                         fanart=item.get('img'))
        if select and select == item.get('title'):
            aitem.item.select(True)
            select = ''
        list_of_items.append(aitem)
    xbmcplugin.addDirectoryItems(handle=addon_handle,
                                 items=list_of_items,
                                 totalItems=N_folders + N_items)
    if pagination[1]:
        addDir(u'[COLOR gold]>> Następna strona >>[/COLOR]',
               ex_link=pagination[1],
               mode='walk',
               iconImage=media('next.png'),
               properties={'SpecialSort': 'bottom'})
    xbmcplugin.addSortMethod(addon_handle,
                             sortMethod=xbmcplugin.SORT_METHOD_UNSORTED,
                             label2Mask='%D, %P, %R')
    SelSort()
    return 1
    def render(self, **kwargs):
        """
        kwargs:
            title=str|unicode
            content="files, songs, artists, albums, movies, tvshows, episodes, musicvideos"
            sort=str
            mode="list, biglist, info, icon, bigicon, view, view2, thumb, round, fanart1, fanart2, fanart3"
            fanart=path
            color1=color
            color2=color
            color3=color
            replace=bool(False)
            cache=bool(True)
        """

        replace = self._variables['is_replace']
        if 'replace' in kwargs and isinstance(kwargs['replace'], bool):
            replace = kwargs['replace']

        if self._variables['is_reset']:
            self._variables['is_item'] = False

            app = {'reset': self._variables['reset'], 'render': kwargs}

            if replace:
                xbmc.executebuiltin('XBMC.Container.Update(%s,replace)' %
                                    (sys.argv[0] + '?json' +
                                     urllib.quote_plus(json.dumps(app))))
            else:
                xbmc.executebuiltin('XBMC.Container.Update(%s)' %
                                    (sys.argv[0] + '?json' +
                                     urllib.quote_plus(json.dumps(app))))

        else:

            if kwargs.get('content') and kwargs['content'] in (
                    'files', 'songs', 'artists', 'albums', 'movies', 'tvshows',
                    'episodes', 'musicvideos'):
                xbmcplugin.setContent(int(sys.argv[1]), kwargs['content'])

            if kwargs.get('title') and isinstance(kwargs['title'], basestring):
                xbmcplugin.setPluginCategory(int(sys.argv[1]), kwargs['title'])

            fanart = {}
            if kwargs.get('fanart') and isinstance(kwargs['fanart'],
                                                   basestring):
                fanart['image'] = kwargs['fanart']
            for i in range(1, 4):
                key = 'color' + str(i)
                if kwargs.get(key) and isinstance(kwargs[key], basestring):
                    fanart[key] = kwargs[key]
            if fanart:
                xbmcplugin.setPluginFanart(int(sys.argv[1]), **fanart)

            if kwargs.get('sort'):
                sort = {
                    'album': xbmcplugin.SORT_METHOD_ALBUM,
                    'album_ignore_the':
                    xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE,
                    'artist': xbmcplugin.SORT_METHOD_ARTIST,
                    'ignore_the': xbmcplugin.SORT_METHOD_ARTIST_IGNORE_THE,
                    'bitrate': xbmcplugin.SORT_METHOD_BITRATE,
                    'date': xbmcplugin.SORT_METHOD_DATE,
                    'drive_type': xbmcplugin.SORT_METHOD_DRIVE_TYPE,
                    'duration': xbmcplugin.SORT_METHOD_DURATION,
                    'episode': xbmcplugin.SORT_METHOD_EPISODE,
                    'file': xbmcplugin.SORT_METHOD_FILE,
                    'genre': xbmcplugin.SORT_METHOD_GENRE,
                    'label': xbmcplugin.SORT_METHOD_LABEL,
                    'label_ignore_the':
                    xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE,
                    'listeners': xbmcplugin.SORT_METHOD_LISTENERS,
                    'mpaa_rating': xbmcplugin.SORT_METHOD_MPAA_RATING,
                    'none': xbmcplugin.SORT_METHOD_NONE,
                    'playlist_order': xbmcplugin.SORT_METHOD_PLAYLIST_ORDER,
                    'productioncode': xbmcplugin.SORT_METHOD_PRODUCTIONCODE,
                    'program_count': xbmcplugin.SORT_METHOD_PROGRAM_COUNT,
                    'size': xbmcplugin.SORT_METHOD_SIZE,
                    'song_rating': xbmcplugin.SORT_METHOD_SONG_RATING,
                    'studio': xbmcplugin.SORT_METHOD_STUDIO,
                    'studio_ignore_the':
                    xbmcplugin.SORT_METHOD_STUDIO_IGNORE_THE,
                    'title': xbmcplugin.SORT_METHOD_TITLE,
                    'title_ignore_the':
                    xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE,
                    'tracknum': xbmcplugin.SORT_METHOD_TRACKNUM,
                    'unsorted': xbmcplugin.SORT_METHOD_UNSORTED,
                    'video_rating': xbmcplugin.SORT_METHOD_VIDEO_RATING,
                    'video_runtime': xbmcplugin.SORT_METHOD_VIDEO_RUNTIME,
                    'video_sort_title':
                    xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE,
                    'video_sort_title_ignore_the':
                    xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE,
                    'video_title': xbmcplugin.SORT_METHOD_VIDEO_TITLE,
                    'video_year': xbmcplugin.SORT_METHOD_VIDEO_YEAR
                }
                if kwargs['sort'] in sort:
                    # TODO: Check param "label2Mask": http://mirrors.xbmc.org/docs/python-docs/xbmcplugin.html#-addSortMethod
                    xbmcplugin.addSortMethod(int(sys.argv[1]),
                                             sort[kwargs['sort']])

            if kwargs.get('property') and isinstance(kwargs['property'], dict):
                for key, value in kwargs['property'].iteritem():
                    xbmcplugin.setProperty(int(sys.argv[1]), key, value)

            if kwargs.get('mode'):
                mode = {
                    'list': 50,
                    'biglist': 51,
                    'info': 52,
                    'icon': 54,
                    'bigicon': 501,
                    'view': 53,
                    'view2': 502,
                    'thumb': 500,
                    'round': 501,
                    'fanart1': 57,
                    'fanart2': 59,
                    'fanart3': 510
                }
                if kwargs['mode'] in mode:
                    xbmc.executebuiltin("Container.SetViewMode(%s)" %
                                        mode[kwargs['mode']])

            cache = True
            if 'cache' in kwargs and not kwargs['cache']:
                cache = False

            xbmcplugin.endOfDirectory(int(sys.argv[1]), True, replace, cache)
Exemple #23
0
    def render(self, **kwargs):
        """
        kwargs:
            title=str|unicode
            content="files, songs, artists, albums, movies, tvshows, episodes, musicvideos"
            sort=str
            mode="list, biglist, info, icon, bigicon, view, view2, thumb, round, fanart1, fanart2, fanart3"
            fanart=path
            color1=color
            color2=color
            color3=color
            replace=bool(False)
            cache=bool(True)
        """

        replace = self._variables['is_replace']
        if 'replace' in kwargs and isinstance(kwargs['replace'], bool):
            replace = kwargs['replace']

        if self._variables['is_reset']:
            self._variables['is_item'] = False

            app = {'reset': self._variables['reset'], 'render': kwargs}

            if replace:
                xbmc.executebuiltin('XBMC.Container.Update(%s,replace)' % (sys.argv[0] + '?json' + urllib.quote_plus(json.dumps(app))))
            else:
                xbmc.executebuiltin('XBMC.Container.Update(%s)' % (sys.argv[0] + '?json' + urllib.quote_plus(json.dumps(app))))

        else:

            if kwargs.get('content') and kwargs['content'] in ('files', 'songs', 'artists', 'albums', 'movies', 'tvshows', 'episodes', 'musicvideos'):
                xbmcplugin.setContent(int(sys.argv[1]), kwargs['content'])

            if kwargs.get('title') and isinstance(kwargs['title'], basestring):
                xbmcplugin.setPluginCategory(int(sys.argv[1]), kwargs['title'])

            fanart = {}
            if kwargs.get('fanart') and isinstance(kwargs['fanart'], basestring):
                fanart['image'] = kwargs['fanart']
            for i in range(1,4):
                key = 'color' + str(i)
                if kwargs.get(key) and isinstance(kwargs[key], basestring):
                    fanart[key] = kwargs[key]
            if fanart:
                xbmcplugin.setPluginFanart(int(sys.argv[1]), **fanart)

            if kwargs.get('sort'):
                sort = {
                    'album': xbmcplugin.SORT_METHOD_ALBUM,
                    'album_ignore_the': xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE,
                    'artist': xbmcplugin.SORT_METHOD_ARTIST,
                    'ignore_the': xbmcplugin.SORT_METHOD_ARTIST_IGNORE_THE,
                    'bitrate': xbmcplugin.SORT_METHOD_BITRATE,
                    'date': xbmcplugin.SORT_METHOD_DATE,
                    'drive_type': xbmcplugin.SORT_METHOD_DRIVE_TYPE,
                    'duration': xbmcplugin.SORT_METHOD_DURATION,
                    'episode': xbmcplugin.SORT_METHOD_EPISODE,
                    'file': xbmcplugin.SORT_METHOD_FILE,
                    'genre': xbmcplugin.SORT_METHOD_GENRE,
                    'label': xbmcplugin.SORT_METHOD_LABEL,
                    'label_ignore_the': xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE,
                    'listeners': xbmcplugin.SORT_METHOD_LISTENERS,
                    'mpaa_rating': xbmcplugin.SORT_METHOD_MPAA_RATING,
                    'none': xbmcplugin.SORT_METHOD_NONE,
                    'playlist_order': xbmcplugin.SORT_METHOD_PLAYLIST_ORDER,
                    'productioncode': xbmcplugin.SORT_METHOD_PRODUCTIONCODE,
                    'program_count': xbmcplugin.SORT_METHOD_PROGRAM_COUNT,
                    'size': xbmcplugin.SORT_METHOD_SIZE,
                    'song_rating': xbmcplugin.SORT_METHOD_SONG_RATING,
                    'studio': xbmcplugin.SORT_METHOD_STUDIO,
                    'studio_ignore_the': xbmcplugin.SORT_METHOD_STUDIO_IGNORE_THE,
                    'title': xbmcplugin.SORT_METHOD_TITLE,
                    'title_ignore_the': xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE,
                    'tracknum': xbmcplugin.SORT_METHOD_TRACKNUM,
                    'unsorted': xbmcplugin.SORT_METHOD_UNSORTED,
                    'video_rating': xbmcplugin.SORT_METHOD_VIDEO_RATING,
                    'video_runtime': xbmcplugin.SORT_METHOD_VIDEO_RUNTIME,
                    'video_sort_title': xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE,
                    'video_sort_title_ignore_the': xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE,
                    'video_title': xbmcplugin.SORT_METHOD_VIDEO_TITLE,
                    'video_year': xbmcplugin.SORT_METHOD_VIDEO_YEAR
                }
                if kwargs['sort'] in sort:
                    # TODO: Check param "label2Mask": http://mirrors.xbmc.org/docs/python-docs/xbmcplugin.html#-addSortMethod
                    xbmcplugin.addSortMethod(int(sys.argv[1]), sort[kwargs['sort']])

            if kwargs.get('property') and isinstance(kwargs['property'], dict):
                for key, value in kwargs['property'].iteritem():
                    xbmcplugin.setProperty(int(sys.argv[1]), key, value)

            if kwargs.get('mode'):
                mode = {
                    'list': 50,
                    'biglist': 51,
                    'info': 52,
                    'icon': 54,
                    'bigicon': 501,
                    'view': 53,
                    'view2': 502,
                    'thumb': 500,
                    'round': 501,
                    'fanart1': 57,
                    'fanart2': 59,
                    'fanart3': 510
                }
                if kwargs['mode'] in mode:
                    xbmc.executebuiltin("Container.SetViewMode(%s)" % mode[kwargs['mode']])

            cache = True
            if 'cache' in kwargs and not kwargs['cache']:
                cache = False

            xbmcplugin.endOfDirectory(int(sys.argv[1]), True, replace, cache)