def add_dir(self, name, params, logo='', infoLabels={}, menuItems={}):
        name = util.decode_html(name)
        if 'title' not in infoLabels:
            infoLabels['title'] = ''
        if logo is None:
            logo = ''
        liz = xbmcgui.ListItem(name,
                               iconImage='DefaultFolder.png',
                               thumbnailImage=logo)

        if 'art' in infoLabels.keys():
            liz.setArt(infoLabels['art'])

        if 'selected' in infoLabels.keys():
            wnd = xbmcgui.Window(xbmcgui.getCurrentWindowId())
            util.debug("[SC] wnd: %s [%d]" %
                       (str(wnd), xbmcgui.getCurrentWindowId()))

        try:
            liz.setInfo(type='Video',
                        infoLabels=self._extract_infolabels(infoLabels))
        except:
            sys.exc_info()
            util.debug("CHYBA")
            util.debug(infoLabels)
        items = []
        for mi in menuItems.keys():
            action = menuItems[mi]
            if not type(action) == type({}):
                items.append((mi, action))
            else:
                if 'action-type' in action:
                    action_type = action['action-type']
                    del action['action-type']
                    if action_type == 'list':
                        items.append((mi, 'Container.Update(%s)' %
                                      sctop._create_plugin_url(action)))
                    elif action_type == 'play':
                        items.append((mi, 'PlayMedia(%s)' %
                                      sctop._create_plugin_url(action)))
                    else:
                        items.append((mi, 'RunPlugin(%s)' %
                                      sctop._create_plugin_url(action)))
                else:
                    items.append(
                        (mi,
                         'RunPlugin(%s)' % sctop._create_plugin_url(action)))
        if len(items) > 0:
            liz.addContextMenuItems(items)
        return xbmcplugin.addDirectoryItem(
            handle=int(sys.argv[1]),
            url=sctop._create_plugin_url(params),
            listitem=liz,
            isFolder=True)
 def _link(self, params):
     arg = {
         "play": "/Play/%d" % int(params['id']),
         "title": params['title']
     }
     if 'season' in params:
         arg.update({
             "play":
             "/Play/%d/%d/%d" % (int(params['id']), int(
                 params['season']), int(params['episode']))
         })
     return sctop._create_plugin_url(arg,
                                     'plugin://%s/' % sctop.__scriptid__)
    def upNext(self):
        util.debug("[SC] upNext: start")
        try:
            if self.scid is None or self.upNextEnable == False:
                util.debug("[SC] upNext: nieje nas plugin")
                return

            playTime = xbmc.Player().getTime()
            totalTime = xbmc.Player().getTotalTime()

            if self.itemType == 'episode':
                util.debug("[SC] upNext: mame serial %sx%s" %
                           (str(self.se), str(self.ep)))
                provider = self.parent.provider
                url = provider._url(
                    '/upNext/%s/%s/%s' %
                    (str(self.scid), str(self.se), str(self.ep)))
                util.debug("[SC] upNext URL: %s" % str(url))
                data = provider._json(url)
                util.debug("[SC] upNext data: %s" % str(data))
                if data and "url" in data:
                    #$INFO[Player.TimeRemaining(ss)]
                    nextUpPage = NextUpInfo("sc-NextUpInfo.xml",
                                            sctop.addonInfo('path'), "default",
                                            "1080i")

                    nextUpPage.setItem(data)
                    nextUpPage.show()
                    while xbmc.Player().isPlaying() and (
                            totalTime - playTime >
                            1) and not nextUpPage.isCancel(
                            ) and not nextUpPage.isWatchNow():
                        sctop.sleep(100)
                        try:
                            playTime = xbmc.Player().getTime()
                            totalTime = xbmc.Player().getTotalTime()
                        except:
                            pass

                    nextUpPage.close()
                    shouldPlayDefault = not nextUpPage.isCancel()
                    shouldPlayNonDefault = nextUpPage.isWatchNow()
                    self.upNextEnable = False
                    util.debug(
                        "[SC] upNext: [%s] [%s] " %
                        (str(shouldPlayDefault), str(shouldPlayNonDefault)))
                    if shouldPlayDefault or shouldPlayNonDefault:
                        self.stop()
                        data.update({'play': data['url'], 'url': data['url']})
                        pu = sctop._create_plugin_url(
                            {
                                'dtitle': data['title'],
                                'play': data['url']
                            }, 'plugin://' + sctop.__scriptid__ + '/')
                        util.debug("[SC] upNext pluginurl: %s" % str(pu))
                        self.play(pu)
                        return
                util.debug("[SC] upNExt smola :-(")
                return
            else:
                util.debug("[SC] upNext: mame film")
                return
        except Exception, e:
            util.error('[SC] upNext err: %s' % str(e))
            pass
    def add_video(self, name, params={}, logo='', infoLabels={}, menuItems={}):
        util.debug("_add_video")
        #util.debug("[SC] add video info: %s" % str(infoLabels))
        _infoLabels = self._extract_infolabels(infoLabels)
        name = util.decode_html(name)
        if 'Title' not in _infoLabels:
            _infoLabels['Title'] = name
        util.debug("[SC] params: %s" % str(params))
        url = sctop._create_plugin_url(params)
        if logo == '' or logo is None:
            logo = self.noImage
        li = xbmcgui.ListItem(name,
                              path=url,
                              iconImage='DefaultVideo.png',
                              thumbnailImage=logo)
        li.setInfo(type='Video', infoLabels=_infoLabels)
        mt = sctop.getMediaType()
        util.debug("[SC] item media type: %s" % mt)

        if 'selected' in infoLabels.keys():
            wnd = xbmcgui.Window(xbmcgui.getCurrentWindowId())
            util.debug("[SC] wnd: %s [%d]" %
                       (str(wnd), xbmcgui.getCurrentWindowId()))
        if 'mvideo' in infoLabels.keys():
            li.addStreamInfo('video', infoLabels['mvideo'])
        if 'maudio' in infoLabels.keys():
            li.addStreamInfo('audio', infoLabels['maudio'])
        if 'msubtitle' in infoLabels.keys():
            li.addStreamInfo('subtitle', infoLabels['msubtitle'])
        if 'art' in infoLabels.keys():
            li.setArt(infoLabels['art'])
        li.setProperty('IsPlayable', 'true')
        if 'runtime' in infoLabels.keys() and infoLabels['runtime'] > 0:
            duration = int(infoLabels['runtime']) * 60
            li.addStreamInfo('video', {'duration': duration})
        items = [(xbmc.getLocalizedString(13347), 'Action(Queue)')]

        self.setUniq(li, infoLabels)

        for mi in menuItems.keys():
            action = menuItems[mi]
            if not type(action) == type({}):
                items.append((mi, action))
            else:
                if 'action-type' in action:
                    action_type = action['action-type']
                    del action['action-type']
                    if action_type == 'list':
                        items.append((mi, 'Container.Update(%s)' %
                                      sctop._create_plugin_url(action)))
                    elif action_type == 'play':
                        items.append((mi, 'PlayMedia(%s)' %
                                      sctop._create_plugin_url(action)))
                    elif action_type == 'trailer':
                        items.append((mi, 'PlayMedia(%s)' % action['url']))
                    else:
                        items.append((mi, 'RunPlugin(%s)' %
                                      sctop._create_plugin_url(action)))
                else:
                    items.append(
                        (mi,
                         'RunPlugin(%s)' % sctop._create_plugin_url(action)))

        if len(items) > 0:
            li.addContextMenuItems(items)
        #xbmc.executebuiltin("Container.SetViewMode(515)")
        return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                           url=url,
                                           listitem=li,
                                           isFolder=False)