def _parseParameters(self, params): # ugly workaround for OpenELEC (sorts query parameters alphabetically) myparameters = params.split('&') mode = filter(lambda x: x.startswith('mode='), myparameters) codedItem = filter(lambda x: x.startswith('url='), myparameters) myparameters.remove(mode[0]) myparameters.remove(codedItem[0]) myparameters.append(codedItem[0][4:]) mode = int(mode[0].split('=')[1]) item = ListItem.fromUrl('&'.join(myparameters)) return [mode, item]
def run(self, paramstring): common.log('SportsDevil running') try: # Main Menu if len(paramstring) <= 2: mainMenu = ListItem.fromUrl(self.MAIN_MENU_FILE) tmpList = self.parseView(mainMenu) if tmpList: self.currentlist = tmpList # if addon is started currFolder = xbmcUtils.getCurrentFolderPath() if not currFolder.startswith(self.base): xbmcplugin.setPluginFanart(self.handle, common.Paths.pluginFanart) self.clearCache() if common.getSetting('autoupdate') == 'true': self.update() else: params = paramstring[1:] [mode, item] = self._parseParameters(params) # 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: 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: self.executeItem(item) elif mode == Mode.PLAY: self.playVideo(item) 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.REMOVEFROMCUSTOMMODULES: self.removeCustomModule(item) elif mode == Mode.UPDATE: self.update() elif mode == Mode.DOWNLOADCUSTOMMODULE: self.downloadCustomModule() except Exception, e: if common.enable_debug: traceback.print_exc(file = sys.stdout) common.showError('Error running SportsDevil.\n\nReason:\n' + str(e))