15
15
AccessDenied , AuthenticationRequired , InvalidCredentials , UnknownBackendResponse , UnknownError
16
16
)
17
17
from galaxy .api .plugin import create_and_run_plugin , Plugin
18
- from galaxy .api .types import Achievement , Authentication , FriendInfo , Game , GameTime , LicenseInfo , NextStep
18
+ from galaxy .api .types import Achievement , Authentication , FriendInfo , Game , GameTime , LicenseInfo , NextStep , GameLibrarySettings
19
19
20
20
from backend import AuthenticatedHttpClient , MasterTitleId , OfferId , OriginBackendClient , Timestamp
21
21
from local_games import get_local_content_path , LocalGames
22
22
from uri_scheme_handler import is_uri_handler_installed
23
23
from version import __version__
24
-
24
+ import re
25
25
26
26
def is_windows ():
27
27
return platform .system ().lower () == "windows"
@@ -38,6 +38,14 @@ def is_windows():
38
38
"&redirect_uri=https://www.origin.com/views/login.html" ,
39
39
"end_uri_regex" : r"^https://www\.origin\.com/views/login\.html.*"
40
40
}
41
+ def regex_pattern (regex ):
42
+ return ".*" + re .escape (regex ) + ".*"
43
+
44
+ JS = {regex_pattern (r"originX/login?execution" ): [
45
+ r'''
46
+ document.getElementById("rememberMe").click();
47
+ '''
48
+ ]}
41
49
42
50
MultiplayerId = NewType ("MultiplayerId" , str )
43
51
AchievementsImportContext = namedtuple ("AchievementsImportContext" , ["owned_games" , "achievements" ])
@@ -97,7 +105,7 @@ async def authenticate(self, stored_credentials=None):
97
105
stored_cookies = stored_credentials .get ("cookies" ) if stored_credentials else None
98
106
99
107
if not stored_cookies :
100
- return NextStep ("web_session" , AUTH_PARAMS )
108
+ return NextStep ("web_session" , AUTH_PARAMS , js = JS )
101
109
102
110
return await self ._do_authenticate (stored_cookies )
103
111
@@ -111,7 +119,6 @@ async def get_owned_games(self):
111
119
self ._check_authenticated ()
112
120
113
121
owned_offers = await self ._get_owned_offers ()
114
-
115
122
games = []
116
123
for offer in owned_offers :
117
124
game = Game (
@@ -304,6 +311,26 @@ async def get_game_time(self, game_id: OfferId, last_played_games: Any) -> GameT
304
311
logging .exception ("Failed to import game times" )
305
312
raise UnknownBackendResponse (str (e ))
306
313
314
+ async def prepare_game_library_settings_context (self , game_ids : List [str ]) -> Any :
315
+ self ._check_authenticated ()
316
+ hidden_games = await self ._backend_client .get_hidden_games (self ._user_id )
317
+ favorite_games = await self ._backend_client .get_favorite_games (self ._user_id )
318
+
319
+ library_context = {}
320
+ for game_id in game_ids :
321
+ library_context [game_id ] = {'hidden' : game_id in hidden_games , 'favorite' : game_id in favorite_games }
322
+ return library_context
323
+
324
+ async def get_game_library_settings (self , game_id : str , context : Any ) -> GameLibrarySettings :
325
+ if not context :
326
+ # Unable to retrieve context
327
+ return GameLibrarySettings (game_id , None , None )
328
+ game_library_settings = context .get (game_id )
329
+ if game_library_settings is None :
330
+ # Able to retrieve context but game is not in its values -> It doesnt have any tags or hidden status set
331
+ return GameLibrarySettings (game_id , [], False )
332
+ return GameLibrarySettings (game_id , ['favorite' ] if game_library_settings ['favorite' ] else [], game_library_settings ['hidden' ])
333
+
307
334
def game_times_import_complete (self ):
308
335
if self ._persistent_cache_updated :
309
336
self .push_cache ()
0 commit comments