From 90e5f75af043f346bec2545fb5f3e028cb418b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Fri, 23 Aug 2024 15:10:42 +0200 Subject: [PATCH] [cli/models] Support both origin and EA App names (#632) Note that the actual title has different case for different games (e.g. it's "the EA app" for one game, but "The EA App" for another) --- legendary/cli.py | 8 ++++---- legendary/models/game.py | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/legendary/cli.py b/legendary/cli.py index 3ab7b962..6913d171 100644 --- a/legendary/cli.py +++ b/legendary/cli.py @@ -242,7 +242,7 @@ def list_games(self, args): # a third-party application (such as Origin). if not version: _store = game.third_party_store - if _store == 'Origin': + if game.is_origin_game: print(f' - This game has to be activated, installed, and launched via Origin, use ' f'"legendary launch --origin {game.app_name}" to activate and/or run the game.') elif _store: @@ -722,7 +722,7 @@ def _launch_origin(self, args): f'to fetch data for Origin titles before using this command.') return - if not game.third_party_store or game.third_party_store != 'Origin': + if not game.is_origin_game: logger.error(f'The specified game is not an Origin title.') return @@ -856,7 +856,7 @@ def install_game(self, args): if store := game.third_party_store: logger.error(f'The selected title has to be installed via a third-party store: {store}') - if store == 'Origin': + if game.is_origin_game: logger.info(f'For Origin games use "legendary launch --origin {args.app_name}" to ' f'activate and/or run the game.') exit(0) @@ -2125,7 +2125,7 @@ def read_service_response(response): logger.info('Redeemed all outstanding Uplay codes.') elif args.origin: na_games, _ = self.core.get_non_asset_library_items(skip_ue=True) - origin_games = [game for game in na_games if game.third_party_store == 'Origin'] + origin_games = [game for game in na_games if game.is_origin_game] if not origin_games: logger.info('No redeemable games found.') diff --git a/legendary/models/game.py b/legendary/models/game.py index 3dfe043a..8faa5a25 100644 --- a/legendary/models/game.py +++ b/legendary/models/game.py @@ -66,7 +66,11 @@ def is_dlc(self): return self.metadata and 'mainGameItem' in self.metadata @property - def third_party_store(self): + def is_origin_game(self) -> bool: + return self.third_party_store and self.third_party_store.lower() in ['origin', 'the ea app'] + + @property + def third_party_store(self) -> Optional[str]: if not self.metadata: return None return self.metadata.get('customAttributes', {}).get('ThirdPartyManagedApp', {}).get('value', None)