+
    Ki_.  c                   sl    ^ RI t ^ RIt^ RIHt ^ RIHt ^ RIt^ RIHt ^ RIH	t	H
t
 R t ! R R4      tR# )	i    N)datetime)gettext)logger)CHROME_USERAGENT
CLUB_APPIDc                 sL    R p\         P                  ! V R\        V4       R4      # )z2022-01-25T05:44:59.192453Nz%Y-%m-%dT%H:%M:%S.%f)r    ZstrptimeZlen)Zdate_strZdate_example   & ?/usr/lib/python3.14/site-packages/lutris/util/ubisoft/client.py
parse_dater      s(    /LX&9L(9:<RSS    c                   s   a  ] tR t^t o R tR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )UbisoftConnectClientc           
     s    Wn         R V n        R V n        R V n        R V n        R V n        R V n        R V n        RV n        \        P                  ! 4       V n        V P                  P                  P                  RR R\        R\        RR /4       R # )NFAuthorization	Ubi-AppId
User-AgentUbi-SessionId)_service_auth_lost_callbacktoken
session_idrefresh_tokenrefresh_timeuser_id	user_name*_UbisoftConnectClient__refresh_in_progressrequestsZsession_sessionheadersupdater   r   )selfZservice   &&r   __init__ZUbisoftConnectClient.__init__   s    #' 
! %*" ((*$$dK\K[]lnrs	
r   c                s    V P                   '       d   \        P                  ! R 4       V P                  P	                  4        R# )g      ?N)r   timesleepr   closer      &r   r    ZUbisoftConnectClient.close$   s)    %%%JJsOr   c                s     V P                   P                  ! W.VO5/ VB #   \         d"   p\        P                  ! T4        R p?R # R p?ii ; iN)r   request	Exceptionr   Z	exception)r   methodurlargskwargsexs   &&&*, r   r$   ZUbisoftConnectClient.request*   sG    	!==((FtFvFF 	!R  	!s   " AA		Ac                s    Wn         R # r#   )r   )r   Zcallbackr   r   set_auth_lost_callbackZ+UbisoftConnectClient.set_auth_lost_callback0   s    #+ r   c                s    V P                   R J# r#   )r   r!   r"   r   is_authenticatedZ%UbisoftConnectClient.is_authenticated3   s    zz%%r   c                sf   V'       d   R V9  d   V P                   P                  VR &   RV9   d<   VR,           F  pVR,          V,          VR ,          V&   K  	  VP                  R4       V P                  ! V.VO5/ VB pVP	                  4       pRV9   d   RV9   d   \        VR,          4      hV# )r   add_to_headersZ	errorCodeZmessage)r   r   popr$   jsonRuntimeError)r   r&   r(   r)   Zheaderresponseresult   &&*,   r   _do_requestZ UbisoftConnectClient._do_request6   s    &0 $ 5 5F9v% !122,23C,DV,Ly!&) 3JJ'(<<888& Y&%8vi011r   c                s(   / p R pV P                   '       dV   V P                  RJ ;'       g@    \        P                  ! 4       \        P                  ! \        V P                  4      4      8  pV'       d)   V P                  4        V P                  ! V.VO5/ VB pV#  V P                  ! V.VO5/ VB pV#   \         di    \        P                  ! R4       T P                   '       g   \        P                  ! R4       T P                  4        T P                  ! T.TO5/ TB p T# i ; i  \         d[   p\        P                  ! RT4       T P                  '       d   T P                  4        \        \        R4      T,          4      ThRp?ii ; i)FNzFallback refreshzONo refresh token present, possibly unchecked remember me when connecting pluginz6Unable to refresh authentication calling auth lost: %sz(Ubisoft authentication has been lost: %s)r   r   r    nowZfromtimestampZint_refresh_authr4   r%   r   debugZwarningZerrorr   r0   _)r   r&   r(   r)   r2   Zrefresh_neededr*   r3   r   _do_request_safeZ%UbisoftConnectClient._do_request_safeD   sx   	["N!!!!%!2!2d!: " "hllnxOeOe))*P ? ""$))&B4B6B$ !
G!--fFtFvFF  ! GLL!34---m &&(!--fFtFvFF G  	[LLQSUV'''((*q!KLrQRXZZ		[sM   D, D, AD, 5&D, B6 62D))<D)%D, (D))D, ,F7AFFc           
     sB    V P                  R RRRRRR\        /R7       R# )	Zoptions7https://public-ubiservices.ubi.com/v3/profiles/sessionsOriginhttps://connect.ubisoft.comRefererzhttps://connect.ubisoft.com/r   r   N)r4   r   r!   r"   r   _do_options_requestZ(UbisoftConnectClient._do_options_requestb   s2    E79. 	 	
r   c                s   V P                   '       d-   V P                   '       d   \        P                  ! R 4       K*  R# RV n          V P                  4        V P                  P                  V P                  4       4       RT n         R#    T P                  4        T P                  4        T P                  P                  T P                  4       4        LV; i  RT n         i ; i)g?TFN)r   r   r   _refresh_ticketr   store_credentialsget_credentials_refresh_remember_mer!   r"   r   r6   Z"UbisoftConnectClient._refresh_authm   s    %%%,,,

3 - *.D&3$$&//0D0D0FG .3*H))+$$&//0D0D0FG-2*s   9B	 	ACC 	C"c                s    V P                  4        V P                  R RRRRRRRRR	V P                   2R
RR\        R\        RRRRRR/
RR/R7      pV P                  V4       R# )postr:   Accept*/*Accept-Encodinggzip, deflate, brAccept-Languageen-US;en;q=0.5r
   zrm_v1 t=Content-Typeapplication/jsonr   r   Hostpublic-ubiservices.ubi.comr;   r<   r=   Z
rememberMeT)r   r/   N)r?   r4   r   r   r   _handle_authorization_responser   jr   r   rC   Z)UbisoftConnectClient._refresh_remember_me}   s      "E%!#6!#38D,>,>+?!@ 2Z.478 %  
" 	++A.r   c                s    V P                  4        V P                  R RRRRRRRRR	V P                   2R
RR\        R\        RRRRRR/
R7      pV P                  V4       R# )Zputr:   rE   rF   rG   rH   rI   rJ   r
   	Ubi_v1 t=rK   rL   r   r   rM   rN   r;   r<   r=   r>   N)r?   r4   r   r   r   rO   rP   r   r   r@   Z$UbisoftConnectClient._refresh_ticket   s      "E%!#6!#39TZZL!9 2Z.478  
  	++A.r   c                s
   R V9   d|   RV9   ds   \         P                  ! 4       \        VR ,          4      \        VR,          4      ,
          ,           p\        VP	                  4       4      VR&   V P                  V4       R# R# R# )Z
expirationZ
serverTimerefreshTimeN)r    r5   r   ZroundZ	timestamprestore_credentials)r   rQ   r      && r   rO   Z3UbisoftConnectClient._handle_authorization_response   si    1!2#<<>Z,-H:VWXdVeKf-fgL$\%;%;%=>Am$$Q' "3r   c                s   VR ,          V n         VR,          V n        VR,          V n        VP                  R4      '       d   VR,          V n        VP                  RR4      V n        VP                  R4      '       d   VR,          V n        V P                  P                  P                  RRV P                    2R	V P                  /4       R
# )ticket	sessionIduserIdusernamerS   Z0rememberMeTicketr
   rR   r   N)
r   r   r   getr   r   r   r   r   r   )r   datar   r   rT   Z(UbisoftConnectClient.restore_credentials   s    (^
{+H~88J!*-DN HH]C888&''!%&8!9D$$o4::,7OQ`bfbqbq%rsr   c           
     s    R V P                   RV P                  RV P                  RV P                  RV P                  /pV P
                  '       d   V P
                  VR&   V# )rV   rW   rZ   rX   rS   rY   )r   r   r   r   r   r   )r   Zcredsr   r   rB   Z$UbisoftConnectClient.get_credentials   sX    djj 2 2dll4,,
 >>> $E*r   c                s8   V P                  V4       V P                  '       d   V P                  '       g   V P                  4       pMR V P                  RV P                  /pV P	                  4        V P
                  P                  V P                  4       4       V# )rY   rX   )rT   r   r   get_user_datapost_sessionsr   rA   rB   )r   Zcredentials	user_datarU   r   !authorise_with_stored_credentialsZ6UbisoftConnectClient.authorise_with_stored_credentials   sr      -~~~T\\\**,I#T^^Xt||LI''(<(<(>?r   c                sR   / p. ROpV F(  pV'       g   K  V F  pWS9   g   K  WE,          W%&   K  	  K*  	  VP                  R 4      VR &   VP                  R4      VR&   V P                  V4       V P                  4        V P                  P	                  V P                  4       4       V# )rX   nameOnPlatformrY   )rX   ra   rV   rZ   rW   )r.   rT   r^   r   rA   rB   )r   Zstorage_jsonsr_   Ztasty_storage_valuesZjson_Zkeys   &&    r   authorise_with_local_storageZ1UbisoftConnectClient.authorise_with_local_storage   s    	f"Eu C2).	 ! # (mmH5	( ).> ?	*  +''(<(<(>?r   c                s@    V P                  R RV P                   24      # )r[   z,https://public-ubiservices.ubi.com/v3/users/)r9   r   r!   r"   r   r]   Z"UbisoftConnectClient.get_user_data   s%    $$U.Z[_[g[gZh,ijjr   c                s&    V P                  R R4      # )r[   z6https://api-ubiservices.ubi.com/v2/profiles/me/friendsr9   r!   r"   r   get_friendsZ UbisoftConnectClient.get_friends   s    $$U,deer   c                st    R RRRR/RR/p\         P                  ! V4      pRR/pV P                  R	R
VVR7      # )ZoperationNameZAllGamesZ	variablesZownedTZquerya  query AllGames {viewer {    id    ...ownedGamesList  }}fragment gameProps on Game {  id  spaceId  name  coverUrl  backgroundUrl  bannerUrl}fragment ownedGameProps on Game {  ...gameProps  viewer {    meta {      id      ownedPlatformGroups {        id        name        type      }    }  }}fragment ownedGamesList on User {  ownedGames: games(filterBy: {isOwned: true}) {    totalCount    nodes {      ...ownedGameProps    }  }}rK   rL   rD   z?https://public-ubiservices.ubi.com/v1/profiles/me/uplay/graphql)r-   r\   )r/   Zdumpsr9   )r   Zpayloadr   s   &  r   get_club_titlesZ$UbisoftConnectClient.get_club_titles   s_    Z'4 "&
N **W%!#56$$M"	 % 
 	
r   c                s    R V P                    RV 2pRRRR/p V P                  RW#R7      #   \         d#   p\        P                  ! T4       / u Rp?# Rp?ii ; i)	z/https://public-ubiservices.ubi.com/v1/profiles/z/statscard?spaceId=zUbi-RequestedPlatformTypeZuplayzUbi-LocaleCodezen-GBr[   r-   N)r   r4   r%   r   r7   )r   Zspace_idr'   r   r*   s   &&   r   get_game_statsZ#UbisoftConnectClient.get_game_stats  sf    ?~M`ai`jk.9I7S	##E3#GG 	LLI	s   - AAAAc                s\    R P                  R V 4       4      pV P                  RRV 24      # )Z,c              3   s2   "   T F  qR ,          x  K  	  R# 5i)ZspaceIdN )Z.0Zspacer   r   Z	<genexpr>Z8UbisoftConnectClient.get_applications.<locals>.<genexpr>#  s     EfUi 0 0fs   r[   z9https://api-ubiservices.ubi.com/v2/applications?spaceIds=)Zjoinr9   )r   ZspacesZspace_stringrU   r   get_applicationsZ%UbisoftConnectClient.get_applications"  s3    xxEfEE$$U.ghtgu,vwwr   c                sF    V P                  R R4      pVP                  4       # )r[   z/https://uplaywebcenter.ubi.com/v1/configuration)r9   r/   )r   r1   r   r   get_configurationZ&UbisoftConnectClient.get_configuration&  s!    ((0ab}}r   c                s2    R R/pV P                  RRVR7      # )rK   rL   rD   z7https://public-ubiservices.ubi.com/v2/profiles/sessionsrf   rc   )r   r   r   r   r^   Z"UbisoftConnectClient.post_sessions*  s.    !#56$$M^e % 
 	
r   c                s|     V P                  R R4      pV#   \         d    \        P                  ! R4        R# i ; i)r[   z+https://api-uplayplusvault.ubi.com/v1/gamesz"Uplay plus Subscription not activeN)r4   r%   r   Zinfo)r   Z	sub_gamesr   r   get_subscriptionZ%UbisoftConnectClient.get_subscription0  sC    	((0]^I   	KK<=	s    !;;c                s6    V P                  R RV 24      pRV9   # )rD   z5https://api-uplayplusvault.ubi.com/v1/games/activate/Zgamesrc   )r   Zactivation_idr1   rU   r   activate_gameZ"UbisoftConnectClient.activate_game8  s,    ((KM?[
 (""r   )
Z__refresh_in_progressr   r   r   r   r   r   r   r   r   N)Z__name__Z
__module__Z__qualname__Z__firstlineno__r   r    r$   r+   r,   r4   r9   r?   r6   rC   r@   rO   rT   rB   r`   rb   r]   rd   re   rg   ri   rj   r^   rk   rl   Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r   r	   r	      s     
!,&<	
3 /*/((
t$kf/
bx
# #r   r	   )r/   r   r    r   r8   r   Zlutris.util.logr   Zlutris.util.ubisoft.constsr   r   r   r	   rh   r   r   <module>rm      s.          " CT
h# h#r   