def _get_owned_games(self): games_to_send = [] for product in self.products_cache: if self.products_cache[product]["owned"] and self.products_cache[product]["free_to_play"]: games_to_send.append(Game(self.products_cache[product]['local_id'], product, None, LicenseInfo(LicenseType.FreeToPlay))) elif self.products_cache[product]["owned"]: games_to_send.append(Game(self.products_cache[product]['local_id'], product, None, LicenseInfo(LicenseType.SinglePurchase))) return games_to_send
async def test_simple(authenticated_plugin, backend_client): backend_client.get_owned_games.return_value = json.loads(""" {'data': {'Launcher': {'libraryItems': {'records': [ { 'catalogItemId': '4fe75bbc5a674f4f9b356b5c90567da5', 'namespace': 'fn', 'appName': 'Fortnite', 'catalogItem': { 'id': '4fe75bbc5a674f4f9b356b5c90567da5', 'namespace': 'fn', 'title': 'Fortnite', 'categories': [{ 'path': 'games' }, { 'path': 'applications' } ], 'releaseInfo': [{ 'platform': ['Windows', 'Mac'] } ], 'dlcItemList': None, 'mainGameItem': None }}, { 'catalogItemId': 'fb39bac8278a4126989f0fe12e7353af', 'namespace': 'min', 'appName': 'Min', 'catalogItem': { 'id': 'fb39bac8278a4126989f0fe12e7353af', 'namespace': 'min', 'title': 'Hades', 'categories': [{ 'path': 'games' }, { 'path': 'applications' } ], 'releaseInfo': [{ 'platform': ['Windows', 'Win32'] } ], 'dlcItemList': None, 'mainGameItem': None } } ] } } } }""".replace("'", '"').replace("None", "null")) games = await authenticated_plugin.get_owned_games() assert games == [ Game("Fortnite", "Fortnite", [], LicenseInfo(LicenseType.SinglePurchase, None)), Game("Min", "Hades", [], LicenseInfo(LicenseType.SinglePurchase, None)) ]
async def test_multiple_games(games_cache_mock, authenticated_plugin): games_cache_mock.get_owned_games = MagicMock(return_value=async_gen([ App(appid="281990", title="Stellaris", type="game", parent=None), App(appid="236850", title="Europa Universalis IV", type="game", parent=None), ])) result = await authenticated_plugin.get_owned_games() assert result == [ Game("281990", "Stellaris", [], LicenseInfo(LicenseType.SinglePurchase, None)), Game("236850", "Europa Universalis IV", [], LicenseInfo(LicenseType.SinglePurchase, None)) ]
async def get_owned_games(self): owned_ids = [] matched_ids = [] games_to_send = [] pre_orders = [] try: owned_ids = await self.bethesda_client.get_owned_ids() except UnknownError as e: log.warning(f"No owned games detected {repr(e)}") log.info(f"Owned Ids: {owned_ids}") if owned_ids: for entitlement_id in owned_ids: for product in self.products_cache: if 'reference_id' in self.products_cache[product]: for reference_id in self.products_cache[product][ 'reference_id']: if entitlement_id in reference_id: self.products_cache[product]['owned'] = True matched_ids.append(entitlement_id) pre_orders = set(owned_ids) - set(matched_ids) for pre_order in pre_orders: pre_order_details = await self.bethesda_client.get_game_details( pre_order) if pre_order_details and 'Entry' in pre_order_details: for entry in pre_order_details['Entry']: if 'fields' in entry and 'productName' in entry['fields']: if entry['fields'][ 'productName'] in self.products_cache: self.products_cache[ entry['fields']['productName']]['owned'] = True else: games_to_send.append( Game( pre_order, entry['fields']['productName'] + " (Pre Order)", None, LicenseInfo(LicenseType.SinglePurchase))) break for product in self.products_cache: if self.products_cache[product]["owned"] and self.products_cache[ product]["free_to_play"]: games_to_send.append( Game(self.products_cache[product]['local_id'], product, None, LicenseInfo(LicenseType.FreeToPlay))) elif self.products_cache[product]["owned"]: games_to_send.append( Game(self.products_cache[product]['local_id'], product, None, LicenseInfo(LicenseType.SinglePurchase))) log.info(f"Games to send (with free games): {games_to_send}") self.owned_games_cache = games_to_send return games_to_send
async def test_success(plugin, read, write): request = {"jsonrpc": "2.0", "id": "3", "method": "import_owned_games"} read.side_effect = [ async_return_value(create_message(request)), async_return_value(b"", 10) ] plugin.get_owned_games.return_value = async_return_value([ Game("3", "Doom", None, LicenseInfo(LicenseType.SinglePurchase, None)), Game("5", "Witcher 3", [ Dlc("7", "Hearts of Stone", LicenseInfo(LicenseType.SinglePurchase, None)), Dlc("8", "Temerian Armor Set", LicenseInfo(LicenseType.FreeToPlay, None)), ], LicenseInfo(LicenseType.SinglePurchase, None)) ]) await plugin.run() plugin.get_owned_games.assert_called_with() assert get_messages(write) == [{ "jsonrpc": "2.0", "id": "3", "result": { "owned_games": [{ "game_id": "3", "game_title": "Doom", "license_info": { "license_type": "SinglePurchase" } }, { "game_id": "5", "game_title": "Witcher 3", "dlcs": [{ "dlc_id": "7", "dlc_title": "Hearts of Stone", "license_info": { "license_type": "SinglePurchase" } }, { "dlc_id": "8", "dlc_title": "Temerian Armor Set", "license_info": { "license_type": "FreeToPlay" } }], "license_info": { "license_type": "SinglePurchase" } }] } }]
def test_success(plugin, read, write): request = {"jsonrpc": "2.0", "id": "3", "method": "import_owned_games"} read.side_effect = [json.dumps(request).encode() + b"\n", b""] plugin.get_owned_games.coro.return_value = [ Game("3", "Doom", None, LicenseInfo(LicenseType.SinglePurchase, None)), Game("5", "Witcher 3", [ Dlc("7", "Hearts of Stone", LicenseInfo(LicenseType.SinglePurchase, None)), Dlc("8", "Temerian Armor Set", LicenseInfo(LicenseType.FreeToPlay, None)), ], LicenseInfo(LicenseType.SinglePurchase, None)) ] asyncio.run(plugin.run()) plugin.get_owned_games.assert_called_with() response = json.loads(write.call_args[0][0]) assert response == { "jsonrpc": "2.0", "id": "3", "result": { "owned_games": [{ "game_id": "3", "game_title": "Doom", "license_info": { "license_type": "SinglePurchase" } }, { "game_id": "5", "game_title": "Witcher 3", "dlcs": [{ "dlc_id": "7", "dlc_title": "Hearts of Stone", "license_info": { "license_type": "SinglePurchase" } }, { "dlc_id": "8", "dlc_title": "Temerian Armor Set", "license_info": { "license_type": "FreeToPlay" } }], "license_info": { "license_type": "SinglePurchase" } }] } }
async def get_owned_games(self) -> List[Game]: owned_applications = list() wgni = self._wgc.get_wgni_client() login_info = wgni.login_info_get() if login_info is None: self._logger.error('plugin/get_owned_games: login info is None', exc_info=True) return owned_applications realm = wgni.get_account_realm() if realm is None: self._logger.error('plugin/get_owned_games: realm is None', exc_info=True) return owned_applications for instance in (await self._wgc.get_owned_applications(realm)).values(): license_info = LicenseInfo( LicenseType.SinglePurchase if instance.is_application_purchased() else LicenseType.FreeToPlay, None) owned_applications.append( Game(instance.get_application_id(), instance.get_application_fullname(), None, license_info)) return owned_applications
def _parse_owned_product(self, game, dlcs): games_dlcs = [] is_game = False is_application = False for category in game['catalogItem']['categories']: if category['path'] == 'games': is_game = True if category['path'] == 'applications': is_application = True if not is_game or not is_application: return for dlc in dlcs: if game['catalogItemId'] == dlc.parent_id: games_dlcs.append( Dlc(dlc.dlc_id, dlc.dlc_title, LicenseInfo(LicenseType.SinglePurchase))) if game['catalogItemId'] == dlc.dlc_id: # product is a dlc, skip return self._game_info_cache[game['appName']] = GameInfo( game['namespace'], game['appName'], game['catalogItem']['title']) return Game(game['appName'], game['catalogItem']['title'], games_dlcs, LicenseInfo(LicenseType.SinglePurchase))
async def get_owned_games(self): owned_games = [] for game in self.games.values(): license_info = LicenseInfo(LicenseType.OtherUserLicense, None) owned_games.append(Game(game_id=game.game_id, game_title=game.game_title, dlcs=None, license_info=license_info)) return owned_games
async def get_owned_games(self): logging.debug('getting owned games') logger.info('auth_cookies: %s' % self._auth_cookies) r = self.request_url('https://stadia.google.com/home') # with open(os.sep.join([str(pathlib.Path.home()), 'stadio-home.html']), 'wb') as f: # f.write(r.content) # add games in "library" games = [ m[1] for m in re.finditer( 'class="GqLi4d QAAyWd qu6XL"[^>]*aria-label="(.*?)"', r.text) ] games = [re.sub(' ansehen.$', '', g) for g in games] # add last played game m = re.search( 'class="Rt8Z2e qRvogc QAAyWd" aria-label="(.*?) Spielen"', r.text) if m: games.append(m[1]) logger.info('games: %s' % games) games = [ Game(g, g, [], LicenseInfo(LicenseType.OtherUserLicense)) for g in games ] return games
async def get_owned_games(self): free_to_play = False dlcs = list() for dlc in self._gw2_api.get_owned_games(): if dlc == 'PlayForFree': free_to_play = True continue if dlc == 'GuildWars2': continue dlc_id = dlc dlc_name = dlc if dlc_id == 'HeartOfThorns': dlc_name = 'Heart of Thorns' elif dlc_id == 'PathOfFire': dlc_name = 'Path of Fire' dlcs.append(Dlc(dlc_id = dlc_id, dlc_title = dlc_name, license_info = LicenseInfo(license_type = LicenseType.SinglePurchase))) license_type = LicenseType.SinglePurchase if free_to_play: license_type = LicenseType.FreeToPlay return [ Game(game_id = self.GAME_ID, game_title = self.GAME_NAME, dlcs = dlcs, license_info = LicenseInfo(license_type = license_type)) ]
async def get_games(ws: websocket.WebSocket): log.debug( "DISCORD_SCRAPE_GAMES: Scraping the user's games from the Discord client..." ) games = [] games_json = await get_data_from_local_cache(ws, "InstallationManagerStore") if not json.loads(games_json)["_state"]["installationPaths"]: log.debug( "DISCORD_SCRAPED_GAMES: [] (The user has no games on Discord!)") return [] games_string = "" for path in json.loads(games_json)["_state"]["installationPaths"]: if os.path.isdir(path): for folder in os.path.os.listdir(path): if os.path.isdir(os.path.join(path, folder)): info_file_path = os.path.join( os.path.join(path, folder, "application_info.json")) if os.path.isfile(info_file_path): app_info = json.loads(open(info_file_path).read()) games.append( Game(app_info["application_id"], app_info["name"], [], LicenseInfo(LicenseType.SinglePurchase))) games_string += (str(app_info["name"]) + ", ") log.debug(f"DISCORD_SCRAPED_GAMES: [{games_string[:-2]}]") return games
async def get_owned_games(self) -> List[Game]: return [Game( game_id=self._GAME_ID , game_title="Path of Exile" , dlcs=[] , license_info=LicenseInfo(LicenseType.FreeToPlay) )]
async def get_owned_games(self): if self._steam_id is None: raise AuthenticationRequired() games = await self._client.get_games(self._steam_id) owned_games = [] try: for game in games: owned_games.append( Game(str(game["appid"]), game["name"], [], LicenseInfo(LicenseType.SinglePurchase, None))) except (KeyError, ValueError): logging.exception("Can not parse backend response") raise UnknownBackendResponse() self._own_games = games game_ids = list(map(lambda x: x.game_id, owned_games)) other_games = await self.get_steam_sharing_games(game_ids) for i in other_games: owned_games.append(i) return owned_games
def update_game_cache(self): game_list = [] if os.path.isfile(self.playlist_path): with open(self.playlist_path) as playlist_json: playlist_dict = json.load(playlist_json) for entry in playlist_dict["items"]: if os.path.abspath(user_config.rom_path) in os.path.abspath( entry["path"]) and os.path.isfile(entry["path"]): provided_name = entry["label"].split(" (")[0] if provided_name in corrections.correction_list: correct_name = corrections.correction_list[ provided_name] else: correct_name = provided_name game_list.append( Game(correct_name, correct_name, None, LicenseInfo(LicenseType.SinglePurchase, None))) #adds games when added while running for entry in game_list: if entry not in self.game_cache: self.game_cache.append(entry) self.add_game(entry) #removes games when removed while running for entry in self.game_cache: if entry not in game_list: self.game_cache.remove(entry) self.remove_game(entry.game_id)
async def get_steam_sharing_games(self, owngames: List[str]) -> List[Game]: profiles = list( filter( lambda x: x.user_name.endswith(FRIEND_SHARING_END_PATTERN + "*" ), self._own_friends)) newgames: List[Game] = [] self._family_sharing_games = [] for i in profiles: othergames = await self._client.get_games(i.user_id) try: for game in othergames: hasit = any(f == str(game["appid"]) for f in owngames) or any( f.game_id == str(game["appid"]) for f in newgames) if not hasit: self._family_sharing_games.append(str(game["appid"])) newgame = Game( str(game["appid"]), game["name"], [], LicenseInfo(LicenseType.OtherUserLicense, i.user_name)) newgames.append(newgame) except (KeyError, ValueError): logging.exception("Can not parse backend response") raise UnknownBackendResponse() return newgames
async def get_owned_games(self): self.config.cfg.read(os.path.expandvars(config.CONFIG_LOC)) method = self.config.cfg.get("Method", "method") owned_games = [] if(method == "default"): logging.debug("DEV: Default method has been chosen") self.games = self.ps2_client._get_games_database() elif(method == "giant"): logging.debug("DEV: Giant bomb method has been chosen") self.games = self.ps2_client._get_games_giant_bomb() else: logging.debug("DEV: ISO method has been chosen") self.games = self.ps2_client._get_games_read_iso() for game in self.games: owned_games.append( Game( game.id, game.name, None, LicenseInfo(LicenseType.SinglePurchase, None) ) ) return owned_games
async def _update_owned_games(self): new_games = self._games_cache.get_added_games() for game in new_games: self.add_game( Game(game, new_games[game], [], license_info=LicenseInfo(LicenseType.SinglePurchase)))
def game_parser(title): return Game( game_id=title["titleId"], game_title=title["name"], dlcs=[], license_info=LicenseInfo(LicenseType.SinglePurchase, None) )
async def get_games(self): logging.debug("Opening connection to itch butler.db") self.itch_db = sqlite3.connect(ITCH_DB_PATH) self.itch_db_cursor = self.itch_db.cursor() resp = list(self.itch_db_cursor.execute("SELECT * FROM games")) downloaded = [x[0] for x in list(self.itch_db_cursor.execute("SELECT game_id FROM downloads"))] self.itch_db.close() logging.debug("Closing connection to itch butler.db") games = [] logging.debug("Starting building games...") for game in resp: logging.debug(f"Building game {game[0]} ({game[2]})") if game[0] not in downloaded: logging.debug(f"Game {game[0]} ({game[2]}) seems to be only cached, skipping...") continue can_be_bought = True if game[11] == 1 else False min_price = game[10] license_type = LicenseType.FreeToPlay if can_be_bought and min_price > 0: license_type = LicenseType.SinglePurchase games.append(Game(game_id=game[0], game_title=game[2], dlcs=None, license_info=LicenseInfo(license_type))) logging.debug(f"Built {game[0]} ({game[2]})") self.game_ids = [x.game_id for x in games] logging.debug("Finished building games") return games
def poe_game(poe_plugin): return Game( poe_plugin._GAME_ID , game_title="Path of Exile" , dlcs=[] , license_info=LicenseInfo(license_type=LicenseType.FreeToPlay) )
def update_game_cache(self): game_list = [] if os.path.isfile(self.playlist_path): with open(self.playlist_path) as playlist_json: playlist_dict = json.load(playlist_json) for entry in playlist_dict["items"]: rom_path = entry["path"].split("#")[0] if os.path.isfile(rom_path): provided_name = self.format_game(entry["label"]) game_list.append( Game(provided_name, provided_name, None, LicenseInfo(LicenseType.SinglePurchase, None))) #adds games when added while running for entry in game_list: if entry not in self.game_cache: self.game_cache.append(entry) self.add_game(entry) #removes games when removed while running for entry in self.game_cache: if entry not in game_list: self.game_cache.remove(entry) self.remove_game(entry.game_id)
def update_game_cache(self): game_list = [] region = "" serial = "" archive_name = "" with open(os.path.abspath( os.path.dirname(os.path.realpath(__file__)) + "/PS1_archive.json"), encoding="latin-1") as serials_json: self.serials = json.load(serials_json) if os.path.isfile(self.playlist_path): with open(self.playlist_path) as playlist_json: playlist_dict = json.load(playlist_json) for entry in playlist_dict["items"]: if os.path.abspath(user_config.rom_path) in os.path.abspath( entry["path"]) and os.path.isfile(entry["path"]): if "(Europe)" in entry["label"]: region = "PAL" if "(USA)" in entry["label"]: region = "NTSC-U" if "(Japan)" in entry["label"]: region = "NTSC-J" if entry["label"].split( " (")[0] in corrections.correction_list: correct_name = corrections.correction_list[ entry["label"].split(" (")[0]]["Correct_Label"] archive_name = corrections.correction_list[ entry["label"].split(" (")[0]]["Archive_Label"] else: correct_name = entry["label"].split(" (")[0] for s_entry in self.serials: if (entry["label"].split(" (")[0].upper() == s_entry["NAME"].split(" - [")[0] or \ archive_name == s_entry["NAME"].split(" - [")[0]) and region == s_entry["REGION"]: serial = s_entry["SERIAL"].replace("-", "") if "Disc" in entry["label"] and entry[ "label"] not in corrections.correction_list: if "Disc 1" in entry["label"]: pass else: continue game_list.append( Game(serial, correct_name, None, LicenseInfo(LicenseType.SinglePurchase, None))) archive_name = "" for entry in game_list: if entry not in self.game_cache: self.game_cache.append(entry) self.add_game(entry) for entry in self.game_cache: if entry not in game_list: self.game_cache.remove(entry) self.remove_game(entry.game_id) self.booted = True
async def get_owned_games(self): if self._user_info_cache.steam_id is None: raise AuthenticationRequired() await self._games_cache.wait_ready(90) owned_games = [] self._games_cache.add_game_lever = True try: temp_title = None for app in self._games_cache.get_owned_games(): if str(app.appid) == "292030": temp_title = app.title owned_games.append( Game( str(app.appid), app.title, [], LicenseInfo(LicenseType.SinglePurchase, None) ) ) if temp_title: dlcs = [] for dlc in self._games_cache.get_dlcs(): dlcs.append(str(dlc.appid)) if "355880" in dlcs or ("378648" in dlcs and "378649" in dlcs): owned_games.append(Game( "499450", temp_title, [], LicenseInfo(LicenseType.SinglePurchase, None) )) except (KeyError, ValueError): logger.exception("Can not parse backend response") raise UnknownBackendResponse() finally: self._owned_games_parsed = True self.persistent_cache['games'] = self._games_cache.dump() self.push_cache() return owned_games
async def get_owned_games(self): if not self.authentication_client.is_authenticated(): raise AuthenticationRequired() def _parse_classic_games(classic_games): for classic_game in classic_games["classicGames"]: log.info(f"looking for {classic_game} in classic games") try: blizzard_game = Blizzard[classic_game["localizedGameName"].replace(u'\xa0', ' ')] log.info(f"match! {blizzard_game}") classic_game["titleId"] = blizzard_game.uid classic_game["gameAccountStatus"] = "Good" except KeyError: continue return classic_games def _get_not_added_free_games(owned_games): owned_games_ids = [] for game in owned_games: if "titleId" in game: owned_games_ids.append(str(game["titleId"])) return [{"titleId": game.blizzard_id, "localizedGameName": game.name, "gameAccountStatus": "Free"} for game in Blizzard.free_games if game.blizzard_id not in owned_games_ids] try: games = await self.backend_client.get_owned_games() classic_games = _parse_classic_games(await self.backend_client.get_owned_classic_games()) owned_games = games["gameAccounts"] + classic_games["classicGames"] # Add wow classic if retail wow is present in owned games for owned_game in owned_games.copy(): if 'titleId' in owned_game: if owned_game['titleId'] == 5730135: owned_games.append({'titleId': 'wow_classic', 'localizedGameName': 'World of Warcraft Classic', 'gameAccountStatus': owned_game['gameAccountStatus']}) free_games_to_add = _get_not_added_free_games(owned_games) owned_games += free_games_to_add log.info(f"Owned games {owned_games} with free games") self.owned_games_cache = owned_games return [ Game( str(game["titleId"]), game["localizedGameName"], [], LicenseInfo(License_Map[game["gameAccountStatus"]]), ) for game in self.owned_games_cache if "titleId" in game ] except Exception as e: log.exception(f"failed to get owned games: {repr(e)}") raise
def result_owned_club_games(): data = json.loads( '''{"jsonrpc": "2.0", "id": "3", "result": {"owned_games": [{"game_id": "6678eff0-1293-4f87-8c8c-06a4ca646068", "game_title": "Assassin's Creed\u00ae Unity", "dlcs": [], "license_info": {"license_type": "SinglePurchase"}}, {"game_id": "f40e304d-8e8d-4343-8270-d06487c35add", "game_title": "Far Cry\u00ae 5", "dlcs": [], "license_info": {"license_type": "SinglePurchase"}}, {"game_id": "6edd234a-abff-4e90-9aab-b9b9c6e49ff7", "game_title": "Tom Clancy's The Division\u2122 ", "dlcs": [], "license_info": {"license_type": "SinglePurchase"}}, {"game_id": "1d1273d9-2120-4e55-8d98-66e08781258e", "game_title": "Trackmania Turbo", "dlcs": [], "license_info": {"license_type": "SinglePurchase"}}, {"game_id": "50228b8c-bbaa-4c32-83c6-2831a1ac317c", "game_title": "Far Cry\u00ae 3", "dlcs": [], "license_info": {"license_type": "SinglePurchase"}}, {"game_id": "4bd0476b-acec-446d-b526-23a0209101ca", "game_title": "Far Cry\u00ae 3 Blood Dragon", "dlcs": [], "license_info": {"license_type": "SinglePurchase"}}]}}\n''' ) return [ Game(game['game_id'], game['game_title'], [], LicenseInfo(LicenseType.SinglePurchase)) for game in data['result']['owned_games'] ]
async def get_owned_games(self): self.games = self.backend_client.get_games_db() owned_games = [] for game in self.games: owned_games.append( Game(game.id, game.name, None, LicenseInfo(LicenseType.SinglePurchase, None))) return owned_games
async def test_multiple_games(authenticated_plugin, backend_client, steam_id): # only fields important for the logic backend_client.get_games.return_value = [{ "appid": 281990, "name": "Stellaris" }, { "appid": 236850, "name": "Europa Universalis IV" }] result = await authenticated_plugin.get_owned_games() assert result == [ Game("281990", "Stellaris", [], LicenseInfo(LicenseType.SinglePurchase, None)), Game("236850", "Europa Universalis IV", [], LicenseInfo(LicenseType.SinglePurchase, None)) ] backend_client.get_games.assert_called_with(steam_id)
async def get_owned_games(self): games_retroarch = [] for rom in self.games_cache: games_retroarch.append( Game(rom, rom, None, LicenseInfo(LicenseType.SinglePurchase, None))) return games_retroarch
async def get_owned_games(self): owned_games = [] self.games = self.gb_client._get_games_giant_bomb() for game in self.games: owned_games.append( Game(game.id, game.name, None, LicenseInfo(LicenseType.SinglePurchase, None))) return owned_games