def addFolder(self):
        if not (os.path.exists(self._favouritesFile) and os.path.exists(self._favouritesFoldersFolder)):
            return False
        
        # get name
        name = getKeyboard(default = '', heading = 'Set name')
        if not name or name == "":
            return False

        # create cfg
        virtualFolderFile = urllib.quote_plus(name) + '.cfg'
        physicalFolder = self._favouritesFoldersFolder
        virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile)
        if os.path.exists(virtualFolderPath):
            common.showInfo('Folder already exists')
            return False
        data = [\
            '\n',
            '########################################################',
            '# ' + name.upper(),
            '########################################################'
            ]
        fu.setFileContent(virtualFolderPath, '\n'.join(data))

        # create link
        linkToFolder = self._createItem(name, 'rss', '', '', None, 'favfolders/' + virtualFolderFile)
        fu.appendFileContent(self._favouritesFile, linkToFolder)
        return True    
    def addXbmcFavourite(self):
        fav_dir = xbmc.translatePath( 'special://profile/favourites.xml' )

        # Check if file exists
        if os.path.exists(fav_dir):
            favourites_xml = fu.getFileContent(fav_dir)
            doc = parseString(favourites_xml)
            xbmcFavs = doc.documentElement.getElementsByTagName('favourite')
            menuItems = []
            favItems = []
            for doc in xbmcFavs:
                title = doc.attributes['name'].nodeValue
                menuItems.append(title)
                try:
                    icon = doc.attributes ['thumb'].nodeValue
                except:
                    icon = ''
                url = doc.childNodes[0].nodeValue
                favItem = XbmcFavouriteItem(title, icon, url)
                favItems.append(favItem)

            select = xbmcgui.Dialog().select('Choose' , menuItems)
            if select == -1:
                return False
            else:
                item = favItems[select].convertToCListItem()
                self.addToFavourites(item)
                return True

        common.showInfo('No favourites found')
        return False
 def playWebDriver(self, url, title):
     try:
         import liveremote
         video = liveremote.resolve(url)
         liz = xbmcgui.ListItem(title)
         liz.setPath(video)
         liz.setProperty('IsPlayable','true')
         xbmc.Player(self.getPlayerType()).play(video, liz)
     except:
         import sys,traceback
         traceback.print_exc(file = sys.stdout)
         common.showInfo('This is not the option you are looking for.')
Exemple #4
0
 def playWebDriver(self, url, title):
     try:
         import liveremote
         video = liveremote.resolve(url)
         liz = xbmcgui.ListItem(title)
         liz.setPath(video)
         liz.setProperty('IsPlayable', 'true')
         xbmc.Player().play(video, liz)
     except:
         import sys, traceback
         traceback.print_exc(file=sys.stdout)
         common.showInfo('This is not the option you are looking for.')
 def add(self, rootFolder=None):
     menuItems = ["Add folder", "Add SportsDevil item", "Add xbmc favourite"]
     select = xbmcgui.Dialog().select('Choose', menuItems)
     if select == 0:
         name = getKeyboard(default = '', heading = 'Set name')
         if name and len(name) > 0:
             return self._addFolder(name, rootFolder)
     elif select == 1:
         common.showInfo('Please browse through SportsDevil and use \ncontext menu entry "Add to SportsDevil favourites"')
     elif select == 2:
         return self._addXbmcFavourite(rootFolder)
     return False
 def add(self, rootFolder=None):
     menuItems = ["Add folder", "Add PGLiveTV item", "Add xbmc favourite"]
     select = xbmcgui.Dialog().select("Choose", menuItems)
     if select == 0:
         name = getKeyboard(default="", heading="Set name")
         if name and len(name) > 0:
             return self._addFolder(name, rootFolder)
     elif select == 1:
         common.showInfo('Please browse through PGLiveTV and use \ncontext menu entry "Add to PGLiveTV favourites"')
     elif select == 2:
         return self._addXbmcFavourite(rootFolder)
     return False
Exemple #7
0
 def add(self, rootFolder=None):
     menuItems = ["Add folder", "Add PGLiveTV item", "Add xbmc favourite"]
     select = xbmcgui.Dialog().select('Choose', menuItems)
     if select == 0:
         name = getKeyboard(default='', heading='Set name')
         if name and len(name) > 0:
             return self._addFolder(name, rootFolder)
     elif select == 1:
         common.showInfo(
             'Please browse through PGLiveTV and use \ncontext menu entry "Add to PGLiveTV favourites"'
         )
     elif select == 2:
         return self._addXbmcFavourite(rootFolder)
     return False
 def addItem(self):
     menuItems = ["Add folder", "Add SportsDevil item", "Add xbmc favourite"]
     select = xbmcgui.Dialog().select('Choose', menuItems)
     if select == -1:
         return False
     elif select == 0:
         return self.addFolder()
     elif select == 1:
         common.showInfo('Please browse through SportsDevil and use \ncontext menu entry "Add to SportsDevil favourites"')
         xbmc.executebuiltin('Action(ParentFolder)')
         return False
     elif select == 2:
         return self.addXbmcFavourite()
     return True
 def _addXbmcFavourite(self, root):      
     xbmcFavs = self._parseXbmcFavourites()
     if xbmcFavs is None:
         common.showInfo('Favourites file not found')
     elif len(xbmcFavs) == 0:
         common.showInfo('No favourites found')
     else:            
         select = xbmcgui.Dialog().select('Choose' , map(lambda x: x.title, xbmcFavs))
         if select == -1:
             return False
         else:
             item = xbmcFavs[select].convertToCListItem()
             self.addItem(item, root)
             return True
     return False   
Exemple #10
0
 def _addXbmcFavourite(self, root):
     xbmcFavs = self._parseXbmcFavourites()
     if xbmcFavs is None:
         common.showInfo('Favourites file not found')
     elif len(xbmcFavs) == 0:
         common.showInfo('No favourites found')
     else:
         select = xbmcgui.Dialog().select('Choose',
                                          map(lambda x: x.title, xbmcFavs))
         if select == -1:
             return False
         else:
             item = xbmcFavs[select].convertToCListItem()
             self.addItem(item, root)
             return True
     return False
Exemple #11
0
    def playVideo(self, videoItem, isAutoplay = False):
        if not videoItem:
            return

        if ('offline' in videoItem['url']):
            common.showInfo('Stream is offline - please try again later.')
            return

        if any(x in videoItem['url'] for x in ['hls://', 'hlsvariant://', 'httpstream://', 'hds://', 'akamaihd://']):
            self.playSLProxy(videoItem)
            return
        
        listitem = self.createXBMCListItem(videoItem)

        title = videoItem['videoTitle']
        if title:
            listitem.setInfo('video', {'title': title})

        if not isAutoplay:
            xbmcplugin.setResolvedUrl(self.handle, True, listitem)
        else:
            url = urllib.unquote_plus(videoItem['url'])
            xbmc.Player().play(url, listitem)
    def changeLabel(self, cfgFile, item, newLabel):
        if os.path.exists(cfgFile):
            oldfav = self._createFavourite(item)
            old = fu.getFileContent(cfgFile)

            # if it's a virtual folder, change target url too; check if target already exists; rename target
            # (helpful, if you want to edit files manually)

            if self._isVirtualFolder(item):
                url = item.getInfo('url')
                oldTargetFile = os.path.join(self._favouritesFoldersFolder, url.split('/')[1])
                # check if new target is valid
                newTargetFile = os.path.join(self._favouritesFoldersFolder, urllib.quote_plus(newLabel) + '.cfg')
                if os.path.exists(newTargetFile):
                    common.showInfo('Folder already exists')
                    return
                # rename target
                os.rename(oldTargetFile, newTargetFile)
                # update target url
                item.setInfo('url', 'favfolders/' + urllib.quote_plus(newLabel) + '.cfg')

            newfav = self._createFavourite(item, title=newLabel)
            new = old.replace(enc.smart_unicode(oldfav).encode('utf-8'), enc.smart_unicode(newfav).encode('utf-8'))
            fu.setFileContent(cfgFile, new)
Exemple #13
0
    def parseView(self, lItem):

        def endOfDirectory(succeeded=True):
            xbmcplugin.endOfDirectory(handle=self.handle, succeeded=succeeded, cacheToDisc=True)

        if not lItem:
            endOfDirectory(False)
            return None

        if lItem['type'] == 'search':
            search_phrase = self.getSearchPhrase()
            if not search_phrase:
                common.log("search canceled")
                endOfDirectory(False)
                return None
            else:
                lItem['type'] = 'rss'
                lItem['url'] =  lItem['url'] % (urllib.quote_plus(search_phrase))

        url = lItem['url']

        if url == common.Paths.customModulesFile: 
            self.customModulesManager.getCustomModules()

        tmpList = None
        result = self.parser.parse(lItem)
        if result.code == ParsingResult.Code.SUCCESS:
            tmpList = result.list
        else:
            if result.code == ParsingResult.Code.CFGFILE_NOT_FOUND:
                common.showError("Cfg file not found")
            elif result.code == ParsingResult.Code.CFGSYNTAX_INVALID:
                common.showError("Cfg syntax invalid")
            elif result.code == ParsingResult.Code.WEBREQUEST_FAILED:
                common.showError("Web request failed")

            endOfDirectory(False)
            return None

        # if it's the main menu, add folder 'Favourites' and 'Custom Modules
        if url == self.MAIN_MENU_FILE:
            tmp = ListItem.create()
            tmp['title'] = '[COLOR green]Favourites[/COLOR]'
            tmp['type'] = 'rss'
            tmp['icon'] = os.path.join(common.Paths.imgDir, 'bookmark.png')
            tmp['url'] = str(common.Paths.favouritesFile)
            tmpList.items.insert(0, tmp)
            
            tmp = ListItem.create()
            tmp['title'] = '[COLOR red]Custom Modules[/COLOR]'
            tmp['type'] = 'rss'
            tmp['url'] = os.path.join(common.Paths.customModulesDir, 'custom.cfg')
            tmpList.items.insert(0, tmp)

        # if it's the favourites menu, add item 'Add item'
        elif url == common.Paths.favouritesFile or url.startswith('favfolders'):
            
            if url.startswith('favfolders'):
                url = os.path.normpath(os.path.join(common.Paths.favouritesFolder, url)) 
            
            tmp = ListItem.create()
            tmp['title'] = 'Add item...'
            tmp['type'] = 'command'
            tmp['icon'] = os.path.join(common.Paths.imgDir, 'bookmark_add.png')
            action = 'RunPlugin(%s)' % (self.base + '?mode=' + str(Mode.ADDITEM) + '&url=' + url)
            tmp['url'] = action
            tmpList.items.append(tmp)
        
        # if it's the custom modules  menu, add item 'more...'
        elif url == common.Paths.customModulesFile:            
            tmp = ListItem.create()
            tmp['title'] = 'more...'
            tmp['type'] = 'command'
            #tmp['icon'] = os.path.join(common.Paths.imgDir, 'bookmark_add.png')
            action = 'RunPlugin(%s)' % (self.base + '?mode=' + str(Mode.DOWNLOADCUSTOMMODULE) + '&url=')
            tmp['url'] = action
            tmpList.items.append(tmp)


        # Create menu or play, if it's a single video and autoplay is enabled
        proceed = False

        count = len(tmpList.items)
        if count == 0:
            if url.startswith('favfolders'):
                proceed = True
            else:
                common.showInfo('No stream available')
        elif count > 0 and not (common.getSetting('autoplay') == 'true' and count == 1 and len(tmpList.getVideos()) == 1):
            # sort methods
            sortKeys = tmpList.sort.split('|')
            setSortMethodsForCurrentXBMCList(self.handle, sortKeys)

            # Add items to XBMC list
            for m in tmpList.items:
                self.addListItem(m, len(tmpList.items))

            proceed = True

        endOfDirectory(proceed)
        common.log('End of directory')
        return tmpList
Exemple #14
0
    def run(self, argv=None):

        self.addon = Addon('plugin.video.ViendoKodiStreaming', argv)

        common.log('ViendoKodiStreaming running')

        base = argv[0]
        handle = int(argv[1])
        parameter = argv[2]
        self.base = base
        self.handle = handle

        paramstring = urllib.unquote_plus(parameter)
        common.log(paramstring)

        try:

            # if addon is started
            listItemPath = xbmcUtils.getListItemPath()
            if not listItemPath.startswith(self.base):
                if not ('mode=' in paramstring
                        and not 'mode=1&' in paramstring):
                    xbmcplugin.setPluginFanart(self.handle,
                                               common.Paths.pluginFanart)
                    self.clearCache()

                    #if common.getSetting('autoupdate') == 'true':
                    #    self.update()

            # Main Menu
            if '98VKS' in paramstring:
                nametorrent = os.path.normpath(paramstring.split('url=')[1])
                if nametorrent == 'quasar':
                    addonTorrent = 'item_info_build=plugin://plugin.video.quasar/play?uri=%s'
                elif nametorrent == 'pulsar':
                    addonTorrent = 'item_info_build=plugin://plugin.video.pulsar/play?uri=%s'
                elif nametorrent == 'kmediatorrent':
                    addonTorrent = 'item_info_build=plugin://plugin.video.kmediatorrent/play/%s'
                elif nametorrent == "torrenter":
                    addonTorrent = 'item_info_build=plugin://plugin.video.torrenter/?action=playSTRM&url=%s&not_download_only=True'
                elif nametorrent == "yatp":
                    addonTorrent = 'item_info_build=plugin://plugin.video.yatp/?action=play&torrent=%s'
                else:
                    addonTorrent = 'item_info_build=plugin://plugin.video.xbmctorrent/play/%s'

                cFichero = common.Paths.catchersDir + '/' + 'torrent.txt'
                outfile = open(cFichero, 'w')  # Indicamos el valor 'w'.
                outfile.write('item_info_name=url\n' +
                              'item_info_from=@PARAM1@\n' + addonTorrent +
                              '\n')
                outfile.close()
                common.showInfo(
                    '[COLOR red]NO INSTALAR[/COLOR] conjuntamente los addon pulsar y quasar.\nYa que tendremos problemas de compatibilidad y no funcionará ninguno. [COLOR lime] \nPara los torrent se utilizará: [/COLOR] '
                    + nametorrent)

            elif len(paramstring) <= 2:
                mainMenu = ListItem.create()
                mainMenu['url'] = self.MAIN_MENU_FILE
                tmpList = self.parseView(mainMenu)
                if tmpList:
                    self.currentlist = tmpList

            else:
                [mode, item] = self._parseParameters()

                # switch(mode)
                if mode == Mode.VIEW:
                    tmpList = self.parseView(item)
                    if tmpList:
                        self.currentlist = tmpList
                        count = len(self.currentlist.items)
                        if count == 1:
                            # Autoplay single video
                            autoplayEnabled = common.getSetting(
                                'autoplay') == 'true'
                            if autoplayEnabled:
                                videos = self.currentlist.getVideos()
                                if len(videos) == 1:
                                    self.playVideo(videos[0], True)

                elif mode == Mode.ADDITEM:
                    tmp = os.path.normpath(paramstring.split('url=')[1])
                    if tmp:
                        suffix = tmp.split(os.path.sep)[-1]
                        tmp = tmp.replace(suffix,
                                          '') + urllib.quote_plus(suffix)
                    if self.favouritesManager.add(tmp):
                        xbmc.executebuiltin('Container.Refresh()')

                elif mode in [
                        Mode.ADDTOFAVOURITES, Mode.REMOVEFROMFAVOURITES,
                        Mode.EDITITEM
                ]:

                    if mode == Mode.ADDTOFAVOURITES:
                        self.favouritesManager.addItem(item)
                    elif mode == Mode.REMOVEFROMFAVOURITES:
                        self.favouritesManager.removeItem(item)
                        xbmc.executebuiltin('Container.Refresh()')
                    elif mode == Mode.EDITITEM:
                        if self.favouritesManager.editItem(item):
                            xbmc.executebuiltin('Container.Refresh()')

                elif mode == Mode.EXECUTE:
                    self.executeItem(item)

                elif mode == Mode.PLAY:
                    self.playVideo(item)

                elif mode == Mode.WEBDRIVER:
                    url = urllib.quote(item['url'])
                    title = item['title']
                    self.playWebDriver(url, title)

                elif mode == Mode.QUEUE:
                    self.queueAllVideos(item)

                elif mode == Mode.CHROME:
                    url = urllib.quote(item['url'])
                    title = item['title']
                    self.launchChrome(url, title)

                elif mode == Mode.SAY:
                    #title = item['title']
                    url = ""

                elif mode == Mode.INSTALLADDON:
                    success = install(item['url'])
                    if success:
                        xbmc.sleep(100)
                        if xbmcUtils.getCurrentWindowXmlFile(
                        ) == 'DialogAddonSettings.xml':
                            # workaround to update settings dialog
                            common.setSetting('', '')

        except Exception, e:
            common.showError('Error running ViendoKodiStreaming')
            common.log('Error running ViendoKodiStreaming. Reason:' + str(e))
Exemple #15
0
    def parseView(self, lItem):
        def endOfDirectory(succeeded=True):
            if self.handle > -1:
                xbmcplugin.endOfDirectory(handle=self.handle,
                                          succeeded=succeeded,
                                          cacheToDisc=True)
            else:
                common.log('Handle -1')

        if not lItem:
            endOfDirectory(False)
            return None

        if lItem['type'] == 'search':
            search_phrase = self.getSearchPhrase()
            if not search_phrase:
                common.log("search canceled")
                endOfDirectory(False)
                return None
            else:
                lItem['type'] = 'rss'
                lItem['url'] = lItem['url'] % (
                    urllib.quote_plus(search_phrase))

        url = lItem['url']

        if url == common.Paths.customModulesFile:
            self.customModulesManager.getCustomModules()

        tmpList = None
        result = self.parser.parse(lItem)
        if result.code == ParsingResult.Code.SUCCESS:
            tmpList = result.list
        elif result.code == ParsingResult.Code.CFGFILE_NOT_FOUND:
            common.showError("No encuentro el fichero Cfg")
            endOfDirectory(False)
            return None
        elif result.code == ParsingResult.Code.CFGSYNTAX_INVALID:
            common.showError("sintaxis invalida en Cfg")
            endOfDirectory(False)
            return None
        elif result.code == ParsingResult.Code.WEBREQUEST_FAILED:
            common.showError("Ha fallado la llamada a la Web")
            if len(result.list.items) > 0:
                tmpList = result.list
            else:
                endOfDirectory(False)
                return None

        # if it's the main menu, add folder 'Favourites' and 'Custom Modules
        if url == self.MAIN_MENU_FILE:
            tmp = ListItem.create()
            tmp['title'] = ' [COLOR blue]ViendoKodi[/COLOR] [COLOR red]Streaming[/COLOR]'
            tmp['type'] = 'say'
            tmp['url'] = ''
            tmp['icon'] = os.path.join(common.Paths.imgDir, 'icon.png')
            tmpList.items.insert(0, tmp)
            tmp = ListItem.create()
            tmp['title'] = '[COLOR red][B] [/B][/COLOR]'
            tmp['type'] = 'say'
            tmp['url'] = ''
            tmp['icon'] = os.path.join(common.Paths.imgDir, 'icon.png')

            tmpList.items.insert(1, tmp)

            #tmp = ListItem.create()
            #tmp['title'] = '[COLOR red]Custom Modules[/COLOR]'
            #tmp['type'] = 'rss'
            #tmp['url'] = os.path.join(common.Paths.customModulesDir, 'custom.cfg')
            #tmpList.items.insert(0, tmp)

        # if it's the favourites menu, add item 'Add item'
        elif url == common.Paths.favouritesFile or url.startswith(
                'favfolders'):

            if url.startswith('favfolders'):
                url = os.path.normpath(
                    os.path.join(common.Paths.favouritesFolder, url))

            tmp = ListItem.create()
            tmp['title'] = 'Add item...'
            tmp['type'] = 'command'
            tmp['icon'] = os.path.join(common.Paths.imgDir, 'bookmark_add.png')
            action = 'RunPlugin(%s)' % (self.base + '?mode=' +
                                        str(Mode.ADDITEM) + '&url=' + url)
            tmp['url'] = action
            tmpList.items.append(tmp)

        # Create menu or play, if it's a single video and autoplay is enabled
        count = len(tmpList.items)
        if (count == 0 and not url.startswith('favfolders')):
            common.showInfo('No stream available')
            #Directory with 0 items
            endOfDirectory(False)
        elif not (common.getSetting('autoplay') == 'true' and count == 1
                  and len(tmpList.getVideos()) == 1):
            # sort methods
            sortKeys = tmpList.sort.split('|')
            setSortMethodsForCurrentXBMCList(self.handle, sortKeys)

            # Add items to XBMC list
            for m in tmpList.items:
                self.addListItem(m, len(tmpList.items))
            #Directory with >1 items
            endOfDirectory(True)
        else:
            #Directory with 0 items
            endOfDirectory(False)
        return tmpList
Exemple #16
0
    def parseView(self, lItem):
        def endOfDirectory(succeeded=True):
            xbmcplugin.endOfDirectory(handle=self.handle,
                                      succeeded=succeeded,
                                      cacheToDisc=True)

        if not lItem:
            endOfDirectory(False)
            return None

        if lItem['type'] == 'search':
            search_phrase = self.getSearchPhrase()
            if not search_phrase:
                common.log("search canceled")
                endOfDirectory(False)
                return None
            else:
                lItem['type'] = 'rss'
                lItem['url'] = lItem['url'] % (
                    urllib.quote_plus(search_phrase))

        url = lItem['url']

        if url == common.Paths.customModulesFile:
            self.customModulesManager.getCustomModules()

        tmpList = None
        result = self.parser.parse(lItem)
        if result.code == ParsingResult.Code.SUCCESS:
            tmpList = result.list
        else:
            if result.code == ParsingResult.Code.CFGFILE_NOT_FOUND:
                common.showError("Cfg file not found")
            elif result.code == ParsingResult.Code.CFGSYNTAX_INVALID:
                common.showError("Cfg syntax invalid")
            elif result.code == ParsingResult.Code.WEBREQUEST_FAILED:
                common.showError("Web request failed")

            endOfDirectory(False)
            return None

        # if it's the main menu, add folder 'Favourites' and 'Custom Modules
        if url == self.MAIN_MENU_FILE:
            tmp = ListItem.create()
            tmp['title'] = 'Favourites'
            tmp['type'] = 'rss'
            tmp['icon'] = os.path.join(common.Paths.imgDir, 'bookmark.png')
            tmp['url'] = str(common.Paths.favouritesFile)
            tmpList.items.insert(0, tmp)

            tmp = ListItem.create()
            tmp['title'] = '[COLOR red]Custom Modules[/COLOR]'
            tmp['type'] = 'rss'
            tmp['url'] = os.path.join(common.Paths.customModulesDir,
                                      'custom.cfg')
            tmpList.items.insert(0, tmp)

        # if it's the favourites menu, add item 'Add item'
        elif url == common.Paths.favouritesFile or url.startswith(
                'favfolders'):

            if url.startswith('favfolders'):
                url = os.path.normpath(
                    os.path.join(common.Paths.favouritesFolder, url))

            tmp = ListItem.create()
            tmp['title'] = 'Add item...'
            tmp['type'] = 'command'
            tmp['icon'] = os.path.join(common.Paths.imgDir, 'bookmark_add.png')
            action = 'RunPlugin(%s)' % (self.base + '?mode=' +
                                        str(Mode.ADDITEM) + '&url=' + url)
            tmp['url'] = action
            tmpList.items.append(tmp)

        # if it's the custom modules  menu, add item 'more...'
        elif url == common.Paths.customModulesFile:
            tmp = ListItem.create()
            tmp['title'] = 'more...'
            tmp['type'] = 'command'
            #tmp['icon'] = os.path.join(common.Paths.imgDir, 'bookmark_add.png')
            action = 'RunPlugin(%s)' % (self.base + '?mode=' + str(
                Mode.DOWNLOADCUSTOMMODULE) + '&url=')
            tmp['url'] = action
            tmpList.items.append(tmp)

        # Create menu or play, if it's a single video and autoplay is enabled
        proceed = False

        count = len(tmpList.items)
        if count == 0:
            if url.startswith('favfolders'):
                proceed = True
            else:
                common.showInfo('No stream available')
        elif count > 0 and not (common.getSetting('autoplay') == 'true' and
                                count == 1 and len(tmpList.getVideos()) == 1):
            # sort methods
            sortKeys = tmpList.sort.split('|')
            setSortMethodsForCurrentXBMCList(self.handle, sortKeys)

            # Add items to XBMC list
            for m in tmpList.items:
                self.addListItem(m, len(tmpList.items))

            proceed = True

        endOfDirectory(proceed)
        common.log('End of directory')
        return tmpList
    def run(self, argv=None):

        self.addon = Addon('plugin.video.ViendoKodiStreaming', argv)

        common.log('ViendoKodiStreaming running')

        base = argv[0]
        handle = int(argv[1])
        parameter = argv[2]
        self.base = base
        self.handle = handle

        paramstring = urllib.unquote_plus(parameter)
        common.log(paramstring)
        try:

            # if addon is started
            listItemPath = xbmcUtils.getListItemPath()
            if not listItemPath.startswith(self.base):
                if not('mode=' in paramstring and not 'mode=1&' in paramstring):
                    xbmcplugin.setPluginFanart(self.handle, common.Paths.pluginFanart)
                    self.clearCache()

                    #if common.getSetting('autoupdate') == 'true':
                    #    self.update()


            # Main Menu
            if '98VKS' in paramstring:
                nametorrent = os.path.normpath(paramstring.split('url=')[1])
                if nametorrent == 'quasar':
                    addonTorrent = 'item_info_build=plugin://plugin.video.quasar/play?uri=%s'
                elif nametorrent == 'pulsar':
                    addonTorrent = 'item_info_build=plugin://plugin.video.pulsar/play?uri=%s'
                elif nametorrent == 'kmediatorrent':
                    addonTorrent = 'item_info_build=plugin://plugin.video.kmediatorrent/play/%s'
                elif nametorrent == "torrenter":
                    addonTorrent = 'item_info_build=plugin://plugin.video.torrenter/?action=playSTRM&url=%s&not_download_only=True'
                elif nametorrent == "yatp":
                    addonTorrent = 'item_info_build=plugin://plugin.video.yatp/?action=play&torrent=%s'
                else:
                    addonTorrent = 'item_info_build=plugin://plugin.video.xbmctorrent/play/%s'

                cFichero = common.Paths.catchersDir + '/'+'torrent.txt'
                outfile = open(cFichero, 'w') # Indicamos el valor 'w'.
                outfile.write('item_info_name=url\n'
                + 'item_info_from=@PARAM1@\n' + addonTorrent + '\n' )
                outfile.close()
                common.showInfo('Para los torrent se utilizará ' + nametorrent )

            elif len(paramstring) <= 2:
                mainMenu = ListItem.create()
                mainMenu['url'] = self.MAIN_MENU_FILE
                tmpList = self.parseView(mainMenu)
                if tmpList:
                    self.currentlist = tmpList

            else:

                [mode, item] = self._parseParameters()

                # switch(mode)
                if mode == Mode.VIEW:
                    tmpList = self.parseView(item)
                    if tmpList:
                        self.currentlist = tmpList
                        count = len(self.currentlist.items)
                        if count == 1:
                            # Autoplay single video
                            autoplayEnabled = common.getSetting('autoplay') == 'true'
                            if autoplayEnabled:
                                videos = self.currentlist.getVideos()
                                if len(videos) == 1:
                                    self.playVideo(videos[0], True)

                elif mode == Mode.ADDITEM:
                    tmp = os.path.normpath(paramstring.split('url=')[1])
                    if tmp:
                        suffix = tmp.split(os.path.sep)[-1]
                        tmp = tmp.replace(suffix,'') + urllib.quote_plus(suffix)
                    if self.favouritesManager.add(tmp):
                        xbmc.executebuiltin('Container.Refresh()')


                elif mode in [Mode.ADDTOFAVOURITES, Mode.REMOVEFROMFAVOURITES, Mode.EDITITEM]:

                    if mode == Mode.ADDTOFAVOURITES:
                        self.favouritesManager.addItem(item)
                    elif mode == Mode.REMOVEFROMFAVOURITES:
                        self.favouritesManager.removeItem(item)
                        xbmc.executebuiltin('Container.Refresh()')
                    elif mode == Mode.EDITITEM:
                        if self.favouritesManager.editItem(item):
                            xbmc.executebuiltin('Container.Refresh()')


                elif mode == Mode.EXECUTE:
                    self.executeItem(item)

                elif mode == Mode.PLAY:
                    self.playVideo(item)

                elif mode == Mode.WEBDRIVER:
                    url = urllib.quote(item['url'])
                    title = item['title']
                    self.playWebDriver(url, title)

                elif mode == Mode.QUEUE:
                    self.queueAllVideos(item)

                elif mode == Mode.DOWNLOAD:
                    url = urllib.unquote(item['url'])
                    title = item['title']
                    self.downloadVideo(url, title)

                elif mode == Mode.CHROME:
                    url = urllib.quote(item['url'])
                    title = item['title']
                    self.launchChrome(url, title)

                elif mode == Mode.REMOVEFROMCUSTOMMODULES:
                    self.removeCustomModule(item)

                #elif mode == Mode.UPDATE:
                #    self.update()
                elif mode == Mode.SAY:
                    #title = item['title']
                    url = ""

                elif mode == Mode.DOWNLOADCUSTOMMODULE:
                    self.downloadCustomModule()

                elif mode == Mode.INSTALLADDON:
                    success = install(item['url'])
                    if success:
                        xbmc.sleep(100)
                        if xbmcUtils.getCurrentWindowXmlFile() == 'DialogAddonSettings.xml':
                            # workaround to update settings dialog
                            common.setSetting('', '')

        except Exception, e:
            common.showError('Error running ViendoKodiStreaming')
            common.log('Error running ViendoKodiStreaming. Reason:' + str(e))
    def run(self, paramstring):
        common.log('SportsDevil running')
        try:
            # Main Menu
            if len(paramstring) <= 2:
                # Set fanart
                xbmcplugin.setPluginFanart(self.handle, common.Paths.pluginFanart)

                # Clear cache
                self.clearCache()

                # Show Main Menu
                tmpList = self.parseView(self.MAIN_MENU_FILE)
                if tmpList:
                    self.currentlist = tmpList
                    self.curr_file = tmpList.cfg

            else:
                params = paramstring
                mode, codedItem = params.split('&',1)
                mode = int(mode.split('=')[1])

                codedItem = codedItem[4:]
                item = decodeUrl(codedItem)

                # switch(mode)
                if mode == Mode.VIEW:
                    tmpList = self.parseView(codedItem)
                    if tmpList:
                        self.currentlist = tmpList
                        self.curr_file = tmpList.cfg
                        count = len(self.currentlist.items)
                        if count == 0:
                            common.showInfo('No stream available')
                        elif count == 1:
                            # Autoplay single video
                            autoplayEnabled = common.getSetting('autoplay') == 'true'
                            if autoplayEnabled:
                                videos = self.currentlist.getVideos()
                                if len(videos) == 1:
                                    self.playVideo(videos[0], True)


                elif mode == Mode.ADDITEM:
                    if self.favouritesManager.addItem():
                        xbmc.executebuiltin('Container.Refresh()')

                elif mode in [Mode.ADDTOFAVOURITES, Mode.REMOVEFROMFAVOURITES, Mode.EDITITEM]:

                    if mode == Mode.ADDTOFAVOURITES:
                        self.favouritesManager.addToFavourites(item)
                    elif mode == Mode.REMOVEFROMFAVOURITES:
                        self.favouritesManager.removeItem(item)
                        xbmc.executebuiltin('Container.Refresh()')
                    elif mode == Mode.EDITITEM:
                        if self.favouritesManager.editItem(item):
                            xbmc.executebuiltin('Container.Refresh()')

                elif mode == Mode.EXECUTE:
                    url = item['url']
                    if url.find('(') > -1:
                        xbmcCommand = parseText(url,'([^\(]*).*')
                        if xbmcCommand.lower() in ['activatewindow', 'runscript', 'runplugin', 'playmedia']:
                            if xbmcCommand.lower() == 'activatewindow':
                                params = parseText(url, '.*\(\s*(.+?)\s*\).*').split(',')
                                for i in range(len(params)-1,-1,-1):
                                    p = params[i]
                                    if p == 'return':
                                        params.remove(p)
                                path = enc.unescape(params[len(params)-1])
                                xbmc.executebuiltin('Container.Update(' + path + ')')
                                return
                            xbmc.executebuiltin(enc.unescape(url))

                elif mode == Mode.PLAY:
                    self.playVideo(item)

                elif mode == Mode.QUEUE:
                    dia = DialogProgress()
                    dia.create('SportsDevil', 'Get videos...' + item['title'])
                    dia.update(0)

                    items = self.getVideos(item, dia)
                    if items:
                        for it in items:
                            item = self.createXBMCListItem(it)
                            uc = sys.argv[0] + '?mode=' + str(Mode.PLAY) + '&url=' + codeUrl(it)
                            item.setProperty('IsPlayable', 'true')
                            item.setProperty('IsFolder','false')
                            xbmc.PlayList(1).add(uc, item)
                        resultLen = len(items)
                        msg = 'Queued ' + str(resultLen) + ' video'
                        if resultLen > 1:
                            msg += 's'
                        dia.update(100, msg)
                        xbmc.sleep(500)
                        dia.update(100, msg,' ',' ')
                    else:
                        dia.update(0, 'No items found',' ')

                    xbmc.sleep(700)
                    dia.close()

                elif mode == Mode.DOWNLOAD:
                    url = urllib.unquote(item['url'])
                    title = item['title']
                    self.downloadVideo(url, title)

        except Exception, e:
            if common.enable_debug:
                traceback.print_exc(file = sys.stdout)
            common.showError('Error running SportsDevil.\n\nReason:\n' + str(e))