+
    KiLf  c                   s   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIHt ^ RIHt ^ RIHtHtHt ^ RIHtHtHt ^ RIt^ RIHt ^ RIHtHt ^ RIHt ^ R	IH t  ^ R
I!H"t" ^ RI#H$t$H%t% ^ RI&H't' ^ RI(H)t) ^ RI*H+t+ ^ RI,H-t-H.t.H/t/H0t0 ^ RI1H2t2H3t3 ^ RI4H5t5 ^ RI6H7t7  ! R R])4      t8 ! R R]'4      t9 ! R R]%4      t:R# )z&Module for handling the Amazon serviceN)defaultdict)gettext)AnyDictOptional)parse_qs	urlencodeurlparse)settings)AuthenticationErrorUnavailableGameError)AUTO_WIN32_EXE)InstallerFile)InstallerFileCollection)SERVICE_LOGINOnlineService)ServiceGame)ServiceMedia)system)CompressionAlgorithmHashAlgorithmManifestManifestHeader)	HTTPErrorRequest)logger)slugifyc                   s   a  ] tR t^#t o RtRtRt]P                  P                  ]
P                  R4      tR.tRtRtV 3R lR ltR	tV tR
# )AmazonBannerz	Game logoamazonzamazon/bannersz%s.jpgZimagez%sc                sL   < V ^8  d   QhRS[ S[S[3,          RS[S[,          /# )   detailsreturn)r   strr   r   Zformat__classdict__   ";/usr/lib/python3.14/site-packages/lutris/services/amazon.py__annotate__ZAmazonBanner.__annotate__-   s+     I IT#s(^ I I    c                s>    VR ,          R,          R,          R,          # )productZproductDetailr   ZlogoUrl )selfr      &&r$   get_media_urlZAmazonBanner.get_media_url-   s    y!/29=iHHr&   r(   N)i   ip   )__name__
__module____qualname____firstlineno____doc__servicesizeospathjoinr   	CACHE_DIRZ	dest_pathZfile_patternsZ	api_fieldZurl_patternr+   __static_attributes____classdictcell__r"      @r$   r   r   #   sJ     GDX//1ABIJMIKI Ir&   r   c                   s8   a  ] tR t^1t o RtRt]R 4       tRtV t	R# )
AmazonGamezRepresentation of a Amazon gamer   c                s    \        4       p\        VR,          4      Vn        \        VR,          R,          4      Vn        VR,          R,          Vn        \        P                  ! V4      Vn        V# )z/Return a Amazon game instance from the API infoidr'   title)	r;   r    Zappidr   slugnamejsondumpsr   )ZclsZamazon_gameZservice_game   && r$   new_from_amazon_gameZAmazonGame.new_from_amazon_game6   s]     "| T!23#K	$:7$CD'	27;#zz+6r&   r(   N)
r,   r-   r.   r/   r0   r1   ZclassmethodrC   r7   r8   r9   r:   r$   r;   r;   1   s     )G r&   r;   c                   s  a  ] tR t^At o RtRt]! R4      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]P:                  P=                  ]P@                  R4      t!]P:                  P=                  ]P@                  R4      t"]P:                  P=                  ]P@                  R4      t#Rt$]%R 4       t&]%R 4       t'R t(R t)R t*R t+R t,V 3R lR lt-V 3R lR  lt.V 3R! lR" lt/V 3R# lR$ lt0R% t1R& t2R' t3R( t4R) t5R* t6R+ t7R<R, lt8R- t9R. t:R/ t;R0 t<R1 t=R2 t>R3 t?R4 t@R5 tAR6 tBR7 tCR8 tDR9 tER: tFR;tGV tHR# )=AmazonServicezService class for Amazonr   ZAmazonZwineFZbanneri  i  ZATVPDKIKX0DER%com.amazon.agslauncher.win/3.0.9202.1zhttps://api.amazon.comzhttps://sds.amazon.comz!https://gaming.amazon.com/graphqlz4https://gaming.amazon.com/api/distribution/v2/publicz7https://gaming.amazon.com/api/distribution/entitlementsNzhttps://www.amazon.com/?z.amazon.authz.amazon.userzamazon-library.jsonzen-USc                s2    V P                   V P                  .# N)	user_pathcookies_pathr)      &r$   credential_filesZAmazonService.credential_filese   s     1 122r&   c                s   V P                  4       V n        V P                  V P                  4      pV P                  4       V n        V P                  V P                  4      V n        / RRbRRbRRbRRbRR	bR
RbRRbRRbRRV P                   2bRRbRV P                  bRRbR^ bRRbRRbRVbpR\        V4      ,           # )zReturn authentication URLz	openid.nsz http://specs.openid.net/auth/2.0zopenid.claimed_idz2http://specs.openid.net/auth/2.0/identifier_selectzopenid.identityzopenid.modeZcheckid_setupzopenid.oa2.scopeZdevice_auth_accesszopenid.ns.oa2z$http://www.amazon.com/ap/ext/oauth/2zopenid.oa2.response_typecodez openid.oa2.code_challenge_methodZS256zopenid.oa2.client_idzdevice:Zlanguageen_USZmarketPlaceIdzopenid.return_tozhttps://www.amazon.comzopenid.pape.max_auth_agezopenid.assoc_handleZamzn_sonic_games_launcherZpageIdzopenid.oa2.code_challengezhttps://amazon.com/ap/signin?)	generate_code_verifierverifiergenerate_challangegenerate_device_serialserialgenerate_client_id	client_idmarketplace_idr   )r)   	challengeZ	arguments   &  r$   	login_urlZAmazonService.login_urli   s=    335++DMM:	11300=
;
!U
 S
 ?	

  4
 C
 '
 /
 #gdnn-=$>
 
 T00
  8
 '
 "#>
 1
  (!
	& /91EEEr&   c                sb   VP                  R4      ^ 8  d   \        P                  ! R4       \        V4      p\	        VP
                  4      pVR,          ^ ,          pV P                  V4      p\        P                  ! 4       VR&   V P                  V4       \        P                  ! V 4       R# R# )z$Get authentication token from Amazonzopenid.oa2.authorization_codezGot authorization codetoken_obtain_timeN)Zfindr   infor   r   queryregister_devicetimesave_user_datar   Zfire)r)   urlZparsedr[   Z	auth_code	user_data   &&    r$   login_callbackZAmazonService.login_callback   s    8834q8KK01 c]FV\\*E=>qAI,,Y7I-1YY[I)*	*t$ 9r&   c                sR    V P                  4       '       g   R# V P                  4       # )zHReturn whether the user is authenticated and if the service is availableF)Zis_authenticatedcheck_connectionrI   rJ   r$   is_connectedZAmazonService.is_connected   s#    $$&&$$&&r&   c                s   V P                  4       '       g   \        P                  ! R4       R# V P                  4        Uu. uF  p\        P                  V4      NK  	  ppV F  pVP                  4        K  	  V# u upi )z.Load the user game library from the Amazon APIzUser not connected to AmazonN)rd   r   errorget_libraryr;   rC   Zsave)r)   gamegamesrW   r$   loadZAmazonService.load   si      ""LL78CGCSCSCUVCU4006CUVDIIK  Ws   A<c                s    \        V P                  RRR7      ;_uu_ 4       pVP                  \        P                  ! V4      4       RRR4       R#   + '       g   i     R# ; i)zSave the user data filewutf-8ZencodingN)openrG   Zwriter@   rA   r)   r`   Z	user_filerB   r$   r^   ZAmazonService.save_user_data   s;    $..#88IOODJJy12 9888s   &AA"	c                s6   Rp\         P                  P                  V P                  4      '       g   \	        \        R4      4      h\        V P                  RRR7      ;_uu_ 4       p\        P                  ! V4      pRRR4       V#   + '       g   i     T# ; i)zLoad the user data fileNz2No Amazon user data available, please log in againrrk   rl   )	r3   r4   ZexistsrG   r	   _rm   r@   ri   rn   rW   r$   load_user_dataZAmazonService.load_user_data   sp    	ww~~dnn--%a(\&]^^$..#88I		),I 9  98 s   &BB	c                    < V ^8  d   QhRS[ /# r   r   Zbytesr!   r#   r$   r%   AmazonService.__annotate__   s       r&   c                s    \         P                  ! ^ 4      p\        P                  ! V4      P	                  R4      p\
        P                  ! RV4       V# )i       =zGenerated code_verifier: %s)secretsZtoken_bytesbase64urlsafe_b64encoderstripr   rZ   )r)   code_verifier   & r$   rN   Z$AmazonService.generate_code_verifier   sB    ++B/00?FFtL1=Ar&   c                s&   < V ^8  d   QhRS[ RS[ /# )r   r{   r   rt   r!   r#   r$   r%   ru      s       % r&   c                s    \         P                  ! V4      p\        P                  ! VP	                  4       4      P                  R 4      p\        P                  ! RV4       V# )rv   zGenerated challange: %s)hashlibsha256rx   ry   Zdigestrz   r   rZ   )r)   r{   Zchallenge_hashrV      &&  r$   rP   Z AmazonService.generate_challange   sI     6,,^-B-B-DELLTR	-y9r&   c                rr   rs   r    r!   r#   r$   r%   ru      s       r&   c                s    \         P                  ! \         P                  ! 4       R 7      P                  P	                  4       p\
        P                  ! RV4       V# ))intzGenerated serial: %s)uuidZUUIDZgetnodehexupperr   rZ   )r)   rR   r|   r$   rQ   Z$AmazonService.generate_device_serial   s9    t||~.2288:*F3r&   c                rr   rs   r   r!   r#   r$   r%   ru      s      C r&   c                s    V R 2pVP                  R4      pVP                  4       p\        P                  ! RV4       V# )z#A2UMVHOX7UP4V7ZasciizGenerated client_id: %s)encoder   r   rZ   )r)   rR   ZserialExclientIdZclientIdHexs   &&   r$   rS   Z AmazonService.generate_client_id   s<    X_-??7+lln-{;r&   c                sx   \         P                  ! RV P                  4       RRVRRRV P                  RRR	V P                  P	                  R
4      RR/RRRRRRRRRRV P
                  RRRRRR/RRR.R R!R".R#/ /pV P                   R$2p\        V4      p VP                  \        P                  ! V4      P                  4       4       TP                  p\         P                  ! R'4       TR(,          R),          pT#   \         d2   p\         P                  ! R%Y54       \        \        R&4      4      ThRp?ii ; i)*z0Register current device and return the user datazRegisterring a device. ID: %sZ	auth_dataZauthorization_codeZclient_domainZDeviceLegacyrT   Zcode_algorithmzSHA-256r{   rk   Zuse_global_authenticationFZregistration_dataapp_nameAGSLauncher for Windowsapp_version1.0.0Zdevice_modelZWindowsZdevice_nameNZdevice_serialZdevice_typeZA2UMVHOX7UP4V7ZdomainZDeviceZ
os_versionz10.0.19044.0Zrequested_extensionsZcustomer_infodevice_inforequested_token_typebearerZmac_dmsZuser_context_mapz/auth/registerFailed http request %s: %sz.Unable to register device, please log in againz Successfully registered a deviceresponseZsuccess)r   rZ   rT   rO   decoderR   
amazon_apir   postr@   rA   r   r   	exceptionr	   rp   )r)   rL   Zdatar_   requestexres_jsonr`   s   &&      r$   r\   ZAmazonService.register_device   sN   3T^^D$dT^^ )!5!5g!>+U  5w	t/(n	" #_m$D"Xy$9+
0 !0#,	cLLD)0023
 <<67Z(3	  	c93C%a(X&YZ`bb	cs   3C= =D9,D44D9c                s    V P                  4       pVR,          pVR,          R,          R,          pV'       d	   V'       g   \        \        R4      4      h\        P                  ! 4       V\	        V4      ,           8  # )z$Check if the stored token is expiredrY   tokensr   
expires_inz-Invalid token info found, please log in again)rq   r	   rp   r]   r   )r)   r`   rY   r   s   &   r$   is_token_expiredZAmazonService.is_token_expired   sa    '')	%&9:x(2<@
 
%a(W&XYYyy{.Z@@@r&   c           
     s   V P                    R2p\        P                  ! R4       V P                  4       pRRRRRV P                  RRR	R
/pVR,          R,          R,          pRVRRRRRRRR/p\        WR7      p VP                  \        P                  ! V4      P                  4       4       TP                  pTR,          TR,          R,          R&   TR,          TR,          R,          R&   \        P                  ! 4       TR&   T P                  T4       R#   \         d2   p\        P                  ! RY4       \        \        R4      4      ThRp?ii ; i)zRefresh the tokenz/auth/tokenzRefreshing tokenAcceptapplication/jsonAccept-LanguagerM   
User-AgentContent-TypeZcharsetrk   r   r   refresh_tokenZsource_tokenZsource_token_typer   access_tokenr   r   r   r   headersr   z,Unable to refresh token, please log in againNr   rY   )r   r   rZ   rq   
user_agentr   r   r@   rA   r   r   r   r	   rp   r]   r^   )	r)   r_   r`   r   r   request_datar   r   r   s	   &        r$   r   ZAmazonService.refresh_token  sR   !-&''')	 (w$//.w
 "(+H5oFM"N17
 #/	aLLL188:;
 <<8@8P	(H%n56>|6L	(H%l3)-	%&I&  	a93C%a(V&WX^``	as   <3D E%,EEc                s    V P                  4       '       d   V P                  4        V P                  4       pVR,          R,          R,          pV# )z;Return the access token and refresh the session if requiredr   r   r   )r   r   rq   )r)   r`   r   rW   r$   get_access_tokenZAmazonService.get_access_token/  sE      "" '')	 *84^Dr&   c           	     s2    V P                  4       pRRRRRT P                  RRT 2/pT P                   R	2p\	        Y2R
7      p TP                  4        R#   \         d     R# i ; i  \         d#   p\        P                  ! RY54        Rp?R# Rp?ii ; i)z0Check if the connection with Amazon is availableFr   r   r   rM   r   ZAuthorizationzbearer z/user/profiler   r   NT)	r   	Exceptionr   r   r   getr   r   r   )r)   r   r   r_   r   r   s   &     r$   rc   ZAmazonService.check_connection9  s    	002L
 (w$//w|n5	
 !/#/	KKM )  		  	93C	s)   A A) A&%A&)B4BBc                sr   \         P                  ! V P                  4      '       dX   \        P                  ! R4       \        V P                  RRR7      ;_uu_ 4       p\        P                  ! V4      uuRRR4       # V P                  4       pV P                  4       pVR,          R,          R,          p\        \        4      pRp V P                  WF4      pV P                  R	VV4      pVR
,           F^  p	V	R,          p
RV
9  d   \        P                  ! RV	4       K,  V
P                  R4      ;'       g    RpW[,          P!                  V	4       K`  	  RV9  d   M!\        P"                  ! R4       VR,          pK  VP%                  R. 4      pVP'                  4        Uu. uF  p\)        VR R7      ^ ,          NK  	  ppW,           p\        V P                  RRR7      ;_uu_ 4       p\        P*                  ! W4       RRR4       V#   + '       g   i     EL; iu upi   + '       g   i     T# ; i)z)Return the user's library of Amazon gameszReturning cached Amazon libraryro   rk   rl   NZ
extensionsr   Zdevice_serial_numberzZcom.amazon.animusdistributionservice.entitlement.AnimusEntitlementsService.GetEntitlementsZentitlementsr'   r<   z0Amazon game encountered with no ID; skipping: %sasin 	nextTokenz/Got next token in response, making next requestc                 s    V R ,          # )r<   r(   )ZgrJ   r$   Z<lambda>Z+AmazonService.get_library.<locals>.<lambda>  s    QtWr&   )Zkeyrj   )r   Zpath_exists
cache_pathr   Zdebugrm   r@   ri   r   rq   r    listget_sync_request_datarequest_entitlementsre   r   appendrZ   ZpopZvaluesZsortedZdump)r)   Zamazon_cacher   r`   rR   Zgames_by_asin
next_tokenr   Z	json_dataZ	game_jsonr'   r   ZasinlessZglZdeduppedrh   s   &               r$   rf   ZAmazonService.get_libraryT  s   doo..LL:;doosW==yy. >= ,,.'')	<(78NO#D)
55fIL11lI '~66	#I.w&LL!SU^_ {{6*00b#**95 7 )+KKIJ";/J !$$R,CPCWCWCYZCYRF2#45a88CYZ#$//399\IIe* : _ >==R [ :9 s   H#H +H%H	%H6	c           
     s    R VRVRRRRRR/p\        V P                  VR7      pVP                  \        P                  ! V4      P                  4       4       VP                  # )	X-Amz-Targetx-amzn-tokenZ	UserAgentrE   r   r   Content-Encodingamz-1.0r   )r   amazon_gaming_distributionr   r@   rA   r   )r)   targettokenbodyr   r   s   &&&&  r$   request_distributionZ"AmazonService.request_distribution  s`    FE@.	
 $997KTZZ%,,./||r&   c                s    R RRRRVRVR^2RRR	R
R\         P                  ! VP                  4       4      P                  4       P	                  4       /pV# )	OperationZGetEntitlementsr   ZSonicZ	syncPointr   Z
maxResultsZproductIdFilterNZkeyIdz$d5dc8b8b-86c8-4fc4-ae93-18c0def5314dZhardwareHash)r}   r~   r   Z	hexdigestr   )r)   rR   r   Z
sync_pointr   s   &&&& r$   r   Z#AmazonService.get_sync_request_data  s\    *"t;GNN6==?;EEGMMO	
 r&   c           
     s    R VRVRV P                   RRRR/pV P                   R2p\        WTR7      pVP                  \        P
                  ! V4      P                  4       4       VP                  # )	r   r   r   r   r   r   r   z/amazon/r   )r   
amazon_sdsr   r   r@   rA   r   r)   r   r   r   r   r_   r      &&&&   r$   request_sdsZAmazonService.request_sds  sl    FE$//.	
 !*#/TZZ%,,./||r&   c           
     s    R VRVRV P                   RRRR/pV P                   p\        WTR7      pVP                  \        P
                  ! V4      P                  4       4       VP                  # )r   r   r   r   r   r   r   r   )r   amazon_gaming_entitlementsr   r   r@   rA   r   r   r   r$   r   Z"AmazonService.request_entitlements  si    FE$//.	
 001#/TZZ%,,./||r&   c                s    V P                  4       pRVRR/p V P                  RVV4      pV#   \         d2   p\        P                  ! RY4       \        \        R4      4      ThRp?ii ; i)zGet a game manifest informationZentitlementIdr   ZGetGameDownloadzWcom.amazon.animusdistributionservice.external.AnimusDistributionService.GetGameDownloadz1There was an error getting game '%s' manifest: %sz Unable to get game manifest infoN)r   r   r   r   r   r
   rp   )r)   game_idr   r   r   r   ra   r$   get_game_manifest_infoZ$AmazonService.get_game_manifest_info  s    ,,. W*

		V00iH   	VPRY^&q)K'LMSUU	Vs   - A),A$$A)c                s   RV P                   /pVR,          p\        P                  P                  V4      pVP	                  VP
                  R,           R7      p\        P                  P                  V4      p\        W2R7      p VP                  4        TP                  p\        P                   ! R	TR
,          4      ^ ,          p\#        4       pTP%                  T^^T,            4       TP&                  P(                  \*        P,                  8X  d   T^T,           R p	MtTP&                  P(                  \*        P.                  8X  d"   \.        P0                  ! T^T,           R 4      p	M*\        P2                  ! R4       \        \        R4      4      h\5        4       p
T
P%                  T	4       T
#   \         d2   p\        P                  ! RY54       \        \        R4      4      ThRp?ii ; i)zGet a game manifestr   downloadUrlz/manifest.protor4   r   r   zUnable to get game manifestNz>I:Ni   Nz/Unknown compression algorithm found in manifest)r   urllibparser   _replacer4   
urlunparser   r   r   r   r   r
   rp   contentstructZunpackr   r   Zcompression	algorithmr   ZnonelzmaZ
decompressre   r   )r)   manifest_infor   r_   r   r   r   Zheader_sizeZheaderZraw_manifestmanifests   &&         r$   get_game_manifestZAmazonService.get_game_manifest  s    $//
 M*ll##C(ll+< <l=ll%%c*#/	QKKM
 //mmD'"+6q9!ga!k/23''+?+D+DD"1{?#45L))-A-F-FF??71{?3D+EFLLLJK&q)Z'[\\:%-  	Q93C&q)F'GHbP	Qs   F3 3G/>,G**G/c           
     s    R RRVRVRRR.RV/p V P                  RVV4      #   \         d9   p\        P                  ! R	Y&4       \	        \        R
4      T,          4      ThRp?ii ; i)r   Z
GetPatchesZ	versionIdZ
fileHashesZdeltaEncodingsZ
FUEL_PATCHZNONEZ	adgGoodIdz_com.amazonaws.gearbox.softwaredistribution.service.model.SoftwareDistributionService.GetPatchesz+There was an error getting '%s' patches: %sz&Unable to get the patches of game '%s'N)r   r   r   r   r
   rp   )r)   r   r   versionZfile_hashesr   r   s   &&&&&  r$   get_file_patchZAmazonService.get_file_patch  s    +|V4
		f##q 
  	fJGX&q)Q'RU\'\]cee	fs   # A&3A!!A&c                s    V P                  4       pR pV! VR4      p. pV F$  pV P                  WAW(4      p	WyR,          ,          pK&  	  V# )zGet game filesc              3   s^   "   ^ pV\        V 4      8  d   WW!,            x  W!,          pK&  R# 5i)i    N)Zlen)Zto_batchZ
batch_sizeZirB   r$   get_batchesZ3AmazonService.get_game_patches.<locals>.get_batches  s/     Ac(m#1>22 $s   +-i  patches)r   r   )
r)   r   r   Z	file_listr   r   Zbatchesr   Zbatchr   s
   &&&&      r$   get_game_patchesZAmazonService.get_game_patches  sX    ,,.	  i-E**<'QH	**G  r&   c                s<   / p. p. p\        4       p\        VP                  4       EFo  w  rg\        VP                  4       F  w  rhVP                  P
                  P                  4       p	VP                  P                  4       P                  RR4      p
VP                  V
4       W9   d    W),          R,          P                  V
4       MRV
.RVP                  RR/W)&   VP                  RRRR	V	R
\        P                  ! VP                  P                  4      //4       K  	  \        VP                   4       FX  w  rkVP                  f   K  VP                  P                  4       P                  RR4      pW9  g   KG  VP                  V4       KZ  	  EKr  	  W#V3# )z9Transform the manifest to more convenient data structures\/pathsr2   r_   NZ
sourceHashZ
targetHashvaluer   )ZsetZ	enumerateZpackagesfilesZhashr   r   r4   r   replaceZaddr   r2   r   Zget_namer   Zdirs)r)   r   	file_dictdirectories	hashpairsZ
file_paths__Zpackagefile	file_hashZ	file_pathZ	directoryZdir_paths   &&           r$   structure_manifest_dataZ%AmazonService.structure_manifest_data#  sc   		U
$X%6%67KB%gmm4 IIOO//1	 II,,.66tSA	y))(188C  )		t,I(   $d$w	;H^H^_c_h_h_r_rHs&t 5( "+7<<!8>>-(~~446>>tSIH1#**84	 "9+ 86 y00r&   c                s   V P                  V4      pV P                  V4      pV P                  V4      w  rEpVP                  4        Fz  w  rxVR,          p	\        P
                  P                  V	4      p	V	P                  V	P                  R,           V,           R7      p	\        P
                  P                  V	4      p	WR&   K|  	  WE3# )zGet the game file listr   /files/r   r_   )
r   r   r   itemsr   r   r   r   r4   r   )
r)   r   r   r   r   r   r   r   r   r_   
   &&        r$   get_game_filesZAmazonService.get_game_filesG  s     33G<))-8,0,H,H,R)		(0OI.C,,'',C,,CHHy$89$D,EC,,))#.CK  1 %%r&   c                s"   RV P                   /p\        WR7      p VP                  4         TP                  p\        P                  ! T4      pTR,          e   TR,          R	,          f   R# TR,          R	,          P                  R
R4      pRpRTR,          9   dF   TR,          R,          '       d0   TR,          R,           F  p	YR8X  d   T	MRT	,           ,          pK  	  Yx3#   \         d2   p\        P
                  ! RY4       \        \        R4      4      ThRp?ii ; i  \         d_   p \        P                  ! RYX4       \        P                  ! T4      p Rp?EL  \         d    \        \        R4      4      Thi ; iRp?ii ; i)z Get and parse the fuel.json filer   r   r   zUnable to get fuel.json file.Nz(Unparseable yaml response from %s: %s
%sz!Invalid response from Amazon APIsZMainZCommandr   r   r   ZArgsZ NN)r   r   r   r   r   re   r
   rp   ZtextyamlZ	safe_loadr   r   r@   loadsr   )
r)   fuel_urlr   r   r   Zres_yaml_textr   game_cmd	game_argsZargr   r$   get_exe_and_game_argsZ#AmazonService.get_exe_and_game_argsX  sw    $//
 (4	SKKM
		[#LLM~~m4H F#x'7	'B'JF#I.66tSA	Xf%%(6*:6*B*B'//OSsB	 0 ""3  	SLL5xD&q)H'IJPRR	S  	[[  !Lh\ij::m4 [*1-P+QRXZZ[	[s:   C& "D% &D"1,DD"%F1.E%%!FF		Fc                s^    RpRpVe   V P                  V4      w  r#Vf   \        pVf   RpW#3# )z:Get the executable path and the arguments for run the gameNr   )r   r   )r)   r   r   r   r   r$   get_game_cmd_lineZAmazonService.get_game_cmd_line}  sD    	"&"<"<X"FH%HI""r&   c                s    V P                  VP                  4      w  rE. pTP                  4        Fl  w  r\        P                  P                  T	R,          ^ ,          4      p
TP                  \        TP                  TRT	R,          RT
RT	R,          /4      4       Kn  	  \        TP                  RT4      pT.. 3#   \         d   p\        \	        R 4      4      ThRp?ii ; i)z)Couldn't load the downloads for this gameNr   r_   Zfilenamer2   
amazongame)r   Zservice_appidr   r
   rp   r   r3   r4   Zbasenamer   r   	game_slugr   )r)   	installerZ_installer_file_idZ_selected_extrasr   r   Zerrr   r   r   Z	file_nameZfile_collections   &&&&        r$   get_installer_filesZ!AmazonService.get_installer_files  s    	` //	0G0GHMI (0OI((gq)9:ILL''UDKU^`fhlmsht4u  1 2)2E2E|UZ[ "$$  	`&q)T'UV\__	`s   B= =C"CC"c                sn    \         P                  ! VR ,          4      p\        VR,          R,          4      # )r   r'   r=   )r@   r   r   )r)   db_gamer   rB   r$   get_installed_slugZ AmazonService.get_installed_slug  s*    **WY/0wy)'233r&   c                s   \         P                  ! VR,          4      pVR,          pV P                  V4      pV P                  V4      pV P	                  V4      w  rgpRRR//RR/RR	VR
V//.p	VP                  4        U
Uu. uFQ  w  r\        ;QJ d#    R VR,           4       F  '       g   K   RM	  RM! R VR,           4       4      '       g   KO  V
NKS  	  pp
pRpV'       d   VR,          p\        P                  P                  V4      pVP                  VP                  R,           \        V4      ^ ,          ,           R7      p\        P                  P                  V4      pV P                  V4      w  r\        P                   ! RW4       RVR,          R,          R\#        R4      R\%        VR,          R,          4      R\%        VR,          R,          4      RV P'                  V4      RRRRV 2RVR R!R"R/R#/ R	R$R%/.R&V	//# u upp
i )'z(Generate a installer for the Amazon gamer   r<   Ztaskr?   Zcreate_prefixZmkdirz$GAMEDIR/drive_c/gameZautosetup_amazonr   r   c              3   s,   "   T F
  pR V9   x  K  	  R# 5i)z	fuel.jsonNr(   )Z.0Zpr|   r$   Z	<genexpr>Z3AmazonService.generate_installer.<locals>.<genexpr>  s     ;aV`QRK1<LV`s   r   TFNr   r   r   zgame cmd line: %s %sr'   r=   r   zAmazon Prime Gamingr>   r   runnerZscriptrg   Zexez$GAMEDIR/drive_c/game/ZargsZprefixz$GAMEDIRZworking_dirr   r   z*N/A:Select the installer from Amazon Gamesr   )r@   r   r   r   r   r   Zanyr   r   r   r   r4   r   r   r   r   rZ   rp   r   get_installed_runner_name)r)   r   r   r   r   r   r   r   r   r   ZkZvZ	fuel_filer   r   r   s   &&              r$   generate_installerZ AmazonService.generate_installer  s   **WY/0$-33G<))-8,0,H,H,R)		 fo./-.'9m[!QR
	 $-??#4b#441;aVWX_V`;a;aVWX_V`;a8aQQ#4	b$]3H||,,X6H((hmmi.G$y/Z[J\.\(]H||..x8H"44X>*H@ GI&w/q./GGI.w78!3G!<=d44W=3H:>Ij!#:	 "<)UVWY

 	
 cs   *H.HHc                s    V P                   # rF   )r   )r)   r   r*   r$   r   Z'AmazonService.get_installed_runner_name  s    {{r&   )rT   rR   rO   r   )Ir,   r-   r.   r/   r0   r<   rp   r?   Ziconr   Z
has_extrasZdrm_freer   ZmediasZdefault_formatZlogin_window_widthZlogin_window_heightrU   r   r   r   Zamazon_gaming_graphqlr   r   rT   rR   rO   Zredirect_urisr3   r4   r5   r   r6   rH   rG   r   ZlocaleZpropertyrK   rX   rb   rd   ri   r^   rq   rN   rP   rQ   rS   r\   r   r   r   rc   rf   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   r8   r9   r:   r$   rD   rD   A   s    "	BX;DDFJH%FN$N8J)J)J?!W!ZIFH/0M77<< 2 2NCLX//@Ih002GHJF3 3 F F:%"'3

   
 'R
A&'P63j
,%Nf(&"1H&"##J# %$4-
^ r&   rD   );r0   rx   r}   r@   r   r3   rw   r   r]   r   r   Zcollectionsr    r   rp   Ztypingr   r   r   Zurllib.parser   r   r   r   Zlutrisr   Zlutris.exceptionsr	   r
   Zlutris.installerr   Zlutris.installer.installer_filer   Z*lutris.installer.installer_file_collectionr   Zlutris.services.baser   r   Zlutris.services.service_gamer   Zlutris.services.service_mediar   Zlutris.utilr   Zlutris.util.amazon.sds_proto2r   r   r   r   Zlutris.util.httpr   r   Zlutris.util.logr   Zlutris.util.stringsr   r   r;   rD   r(   r&   r$   <module>r      s    ,     	      #   & & 6 6   G + 9 N = 4 6  g g / " 'I< I  R
M R
r&   