def query_game_information(self, nvapp): game_info = [] self.logger.info("Trying to get information for game: %s" % nvapp.title) if nvapp.title not in self.game_blacklist: for scraper in self.scraper_chain: if scraper.is_enabled(): game_info.append(Game.from_api_response(scraper.get_game_information(nvapp))) else: game = Game(nvapp.title, None) if nvapp.title == 'Steam': fanart_path = os.path.join(self.plugin.addon.getAddonInfo('path'), 'resources/statics/steam_wallpaper___globe_by_diglididudeng-d7kq9v9.jpg') fanart = Fanart(fanart_path, fanart_path) game.fanarts[os.path.basename(fanart_path)] = fanart for scraper in self.scraper_chain: if scraper.name() == 'NvHTTP': game.posters = scraper.get_game_information(nvapp).posters game_info.append(game) game = game_info[0] while len(game_info) > 1: next_game = game_info.pop() game.merge(next_game) return game
def query_game_information(self, game_name): """ :type game_name: str :rtype game: Game """ game_info = [] self.logger.info("Trying to get information for game: %s" % game_name) if game_name not in self.game_blacklist: for scraper in self.scraper_chain: if scraper.is_enabled(): game_info.append(Game.from_api_response(scraper.get_game_information(game_name))) else: game = Game(game_name, None) if game_name == 'Steam': fanart_path = os.path.join(self.plugin.addon.getAddonInfo('path'), 'resources/statics/steam_wallpaper___globe_by_diglididudeng-d7kq9v9.jpg') fanart = Fanart(fanart_path, fanart_path) game.fanarts[os.path.basename(fanart_path)] = fanart game_info.append(game) game = game_info[0] while len(game_info) > 1: next_game = game_info.pop() game.merge(next_game) return game
def testGameMergeSelfNone(self): game1 = Game('Name') game2 = Game('Name') game2.genre = ['Action', 'Adventure'] game2.posters = ['/path/to/poster'] game2.fanarts = ['path/to/art/1', 'path/to/art/2', 'path/to/art/3'] game1.merge(game2) self.assertEqual(game1.genre, ['Action', 'Adventure']) self.assertEqual(game1.posters, ['/path/to/poster']) self.assertEqual(game1.fanarts, ['path/to/art/1', 'path/to/art/2', 'path/to/art/3']) self.assertEqual(game1.get_selected_fanart(), 'path/to/art/1') self.assertEqual(game1.get_selected_poster(), '/path/to/poster')
def testGameMergeSelfFilled(self): game1 = Game('Name') game1.genre = ['Shooter', 'Adventure'] game1.posters = ['/path/to/poster/original'] game1.fanarts = ['path/to/art/1-1', 'path/to/art/1-2', 'path/to/art/1-3'] game2 = Game('Name') game2.genre = ['Action', 'Adventure'] game2.posters = ['/path/to/poster'] game2.fanarts = ['path/to/art/1', 'path/to/art/2', 'path/to/art/1-3'] game1.merge(game2) self.assertEqual(game1.genre, ['Action', 'Adventure', 'Shooter']) self.assertEqual('/path/to/poster/original' in game1.posters, True) self.assertEqual('/path/to/poster' in game1.posters, True) self.assertEqual('path/to/art/1' in game1.fanarts, True) self.assertEqual('path/to/art/2' in game1.fanarts, True) self.assertEqual('path/to/art/1-1' in game1.fanarts, True) self.assertEqual('path/to/art/1-2' in game1.fanarts, True) self.assertEqual('path/to/art/1-3' in game1.fanarts, True)
def refresh_games(self): game_list = self.moonlight_helper.list_games() storage = self.core.get_storage() game_version_storage = self.plugin.get_storage('game_version') cache = {} if game_version_storage.get('version') == Game.version: cache = storage.raw_dict().copy() storage.clear() i = 1 for nvapp in game_list: game = Game(nvapp.title) if nvapp.id in cache: if not storage.get(nvapp.id): storage[nvapp.id] = cache.get(nvapp.id)[0] else: try: storage[ nvapp.id] = self.scraper_chain.query_game_information( nvapp) except KeyError: self.logger.info( 'Key Error thrown while getting information for game {0}: {1}' .format(nvapp.title, KeyError.message)) storage[nvapp.id] = game i += 1 game_version_storage.clear() game_version_storage['version'] = Game.version storage.sync() game_version_storage.sync()
def get_games(self): """ Fills local game storage with scraper results (if enabled) or game names (if scrapers are disabled) """ game_list = self.moonlight_helper.list_games() if game_list is None or len(game_list) == 0: xbmcgui.Dialog().notification( self.core.string('name'), 'Getting game list failed. ' + 'This usually means your host wasn\'t paired properly.', '', 20000) return progress_dialog = xbmcgui.DialogProgress() progress_dialog.create(self.core.string('name'), 'Refreshing Game List') if game_list is None or len(game_list) == 0: xbmcgui.Dialog().notification(self.core.string('name'), self.core.string('empty_game_list')) return bar_movement = int(1.0 / len(game_list) * 100) storage = self.core.get_storage() game_version_storage = self.plugin.get_storage('game_version') cache = {} if game_version_storage.get('version') == Game.version: cache = storage.raw_dict().copy() storage.clear() i = 1 for nvapp in game_list: progress_dialog.update(bar_movement * i, 'Processing: %s' % nvapp.title, '') game = Game(nvapp.title) if nvapp.id in cache: if not storage.get(nvapp.id): progress_dialog.update( bar_movement * i, line2='Restoring information from cache') storage[nvapp.id] = cache.get(nvapp.id)[0] else: try: progress_dialog.update( bar_movement * i, line2='Getting Information from Local Sources') storage[ nvapp.id] = self.scraper_chain.query_game_information( nvapp) except KeyError: self.logger.info( 'Key Error thrown while getting information for game {0}: {1}' .format(nvapp.title, KeyError.message)) storage[nvapp.id] = game i += 1 game_version_storage.clear() game_version_storage['version'] = Game.version storage.sync() game_version_storage.sync()
def testGameMergeSelfFilled(self): game1 = Game('Name') game1.genre = ['Shooter', 'Adventure'] game1.posters = ['/path/to/poster/original'] game1.fanarts = [ 'path/to/art/1-1', 'path/to/art/1-2', 'path/to/art/1-3' ] game2 = Game('Name') game2.genre = ['Action', 'Adventure'] game2.posters = ['/path/to/poster'] game2.fanarts = ['path/to/art/1', 'path/to/art/2', 'path/to/art/1-3'] game1.merge(game2) self.assertEqual(game1.genre, ['Action', 'Adventure', 'Shooter']) self.assertEqual('/path/to/poster/original' in game1.posters, True) self.assertEqual('/path/to/poster' in game1.posters, True) self.assertEqual('path/to/art/1' in game1.fanarts, True) self.assertEqual('path/to/art/2' in game1.fanarts, True) self.assertEqual('path/to/art/1-1' in game1.fanarts, True) self.assertEqual('path/to/art/1-2' in game1.fanarts, True) self.assertEqual('path/to/art/1-3' in game1.fanarts, True)