+
    Ki$  c                   s\   ^ RI t ^ RIt^ RIHt ^ RIHtHtHtHtH	t	 ^ RI
Ht ^ RIHt ^ RIHtHtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHtHtHtH t H!t!H"t" ^ RI#H$t$ ^ RI%H&t& ^ RI'H(t( ^ RI)H*t*  ! R R]$4      t+ ! R R]"4      t,R t-RR R llt.R R lt/R R lt0R R lt1R# )i    N)gettext)AnyDictIterableListOptional)Gio)settings)get_api_gamesget_game_installersread_api_key)	get_games)ServiceGameCollectionGame)dialogs)download_media)SERVICE_LOGINLutrisBannerLutrisCoverartLutrisCoverartMedium
LutrisIconOnlineService)ServiceGame)http)BusyAsyncCall)loggerc                   s8   a  ] tR t^t o RtRt]R 4       tRtV t	R# )
LutrisGamez(Service game created from the Lutris APIlutrisc                s    \        4       pVR,          Vn        VR,          Vn        VR,          Vn        \        P
                  ! V4      Vn        V# )z6Create an instance of LutrisGame from the API responseslugname)r   appidr   r   jsonZdumpsdetails)ZclsZapi_payloadZservice_game   && ;/usr/lib/python3.14/site-packages/lutris/services/lutris.pynew_from_apiZLutrisGame.new_from_api"   sI     "|(0'/'/#zz+6     N)
__name__
__module____qualname____firstlineno____doc__serviceZclassmethodr$   __static_attributes____classdictcell__)__classdict__s   @r#   r   r      s     2G r%   r   c                   s  a a ] tR t^-t oRtRt]! R4      tRtRt	R]
R]R]R	]/tRt]P"                  R
,           t]P"                  R,           t]P*                  P-                  ]P.                  R4      t]P*                  P-                  ]P.                  R4      t]R 4       tR tR tRR ltR tR t R t!V 3R lt"R t#R t$R t%R t&V3R lR lt'V3R lR lt(Rt)Vt*V ;t+# )LutrisServicezService for Lutris gamesr   ZLutrisznet.lutris.LutrisTiconbannerZcoverart_medZcoverart_bigz/apiz/api/accounts/tokenz
auth-tokenc                s    V P                   .# )z2Return a list of all files used for authentication)
token_pathself   &r#   credential_filesZLutrisService.credential_filesA   s       r%   c                s   \         P                  ! V P                  4       Uu/ uF  p\        VR,          4      VbK  	  pp\	        4        F+  pV P                  VP                  VR,          4      V4       K-  	  R# u upi )z<Matching lutris games is much simpler... No API call needed.r   r   N)r   Zget_for_serviceidstrr   Z
match_gameget)r5   gameZservice_gameslutris_game   &   r#   match_gamesZLutrisService.match_gamesF   sh    >S>c>cdhdkdk>lm>ldT']+T1>lm$;KOOM--k&.ABKP ' ns   A<c                s"    V P                  4       # )zIs the service connected?)Zis_authenticatedr4   r6   r#   is_connectedZLutrisService.is_connectedL   s    $$&&r%   c                sl    \         P                  ! VR7      pVP                  RV P                  4       R# )zConnect to Lutris)parentZ	connectedN)r   ZClientLoginDialogZconnecton_connect_success)r5   r@   Zlogin_dialogr"   r#   loginZLutrisService.loginP   s(    00?[$*A*ABr%   c                s2    \         P                  ! V 4       R# )zHandles connection successN)r   Zfire)r5   Z_widgetZ	_usernames   &&&r#   rA   Z LutrisService.on_connect_successU   s    4 r%   c                sX   \        4       pV'       g   . # \        P                  R,           p\        P                  ! VRRVR,          ,           /R7      p VP                  4       pVP                  #   \        P                   d$   p\        P                  ! RT4       . u Rp?# Rp?ii ; i)z-Return the remote library as a list of dicts.z/api/users/libraryZAuthorizationzToken Ztoken)ZheaderszUnable to load library: %sN)
r
   r   SITE_URLr   Requestr:   	HTTPErrorr   errorr    )r5   Zcredentialsurlrequestresponseexs   &     r#   get_libraryZLutrisService.get_libraryY   s    "nI"66,,s_hU\I]>],^_	{{}H }} ~~ 	LL5r:I	s   A1 1B)B$B)$B)c                s:   V P                  4       p\        P                  ! R \        V4      4       V F(  p\        P                  V4      pVP                  4        K*  	  \        P                  ! R4       V P                  4        \        P                  ! R4       V# )z#Loaded %s games from Lutris libraryz%Matching with already installed gameszLutris games loaded)rK   r   debuglenr   r$   Zsaver>   )r5   Zlutris_gamesr;   r<   r=   r#   loadZLutrisService.loadg   sx    ''):C<MN D$11$7K ! 	<=*+r%   c                s8   < \         SV `  4        \        4        R # N)Zsuper
load_icons
sync_media)r5   	__class__s   &r#   rP   ZLutrisService.load_iconsr   s     	r%   c                s    VR ,          # r   r&   )r5   db_game   &&r#   get_installed_slugZ LutrisService.get_installed_slugx   s    vr%   c                s6    VR ,          pV P                  V4      # rS   )install_by_id)r5   rT   r   r"   r#   installZLutrisService.install{   s    v!!$''r%   c                s6   a V3R  lp\        \        VS4       R# )c                 s   < V'       d   VhV '       g   \        \        R 4      S,          4      h\        P                  P	                  4       pVP                  V 4       R# )zGLutris has no installers for %s. Try using a different service instead.N)ZRuntimeError_r   ZApplicationZget_defaultZshow_installer_window)Z
installersrF   Zapplicationr   s   && r#   on_installers_readyZ8LutrisService.install_by_id.<locals>.on_installers_ready   sE    "1%n#orw#wxx//557K--j9r%   N)r   r	   )r5   r   rZ   s   &f r#   rW   ZLutrisService.install_by_id   s    	: 	)+>Fr%   c                s    V P                  V4      pV'       dC   \        V4      ^8X  d3   V^ ,          P                  4       pVR8X  d   R# VR8X  d   R# VR8X  d   R# R# )i   ZwindowsZwineZlinuxzms-dosZdosbox )get_game_platformsrM   Zcasefold)r5   rT   	platformsZplatforms   &&  r#   get_installed_runner_nameZ'LutrisService.get_installed_runner_name   sV    ++G4	Y1, |,,.H9$7"8#r%   c                s6   < V ^8  d   QhRS[ RS[S[,          /# )   rT   return)Zdictr   r9   formatr/      "r#   __annotate__LutrisService.__annotate__   s      $ 49 r%   c                s    VP                  R 4      pV'       dJ   \        P                  ! V4      P                  R4      pVe!   V Uu. uF  qDP                  R4      NK  	  up# . # u upi )r!   r]   r   )r:   r    Zloads)r5   rT   r!   r]   Zps   &&   r#   r\   Z LutrisService.get_game_platforms   sW    ++i(

7+//<I$/89y!fy99	 :s   A%c                s    < V ^8  d   QhRS[ /# )r_   r;   r   ra   rc   r#   rd   re      s       r%   c                s    VP                   V P                  8X  d>   VP                  '       d,   \        P                  ! V P                  VP                  4      # R # rO   )r,   r8   r   r   Zget_game)r5   r;   rU   r#   get_service_db_gameZ!LutrisService.get_service_db_game   s8    <<477"tyyy(11$''499EEr%   r&   rO   ),r'   r(   r)   r*   r+   r8   rY   r   r1   Zonliner   r   r   r   ZmediasZdefault_formatr   rC   Zapi_urlZ	login_urlosZpathZjoinZ	CACHE_DIRZ
cache_pathr3   Zpropertyr7   r>   r?   rB   rA   rK   rN   rP   rV   rX   rW   r^   r\   rf   r-   r.   Z__classcell__)rR   r/   s   @@r#   r0   r0   -   s     "	BX;DDF
,,	F $N&(G!!$99Ih00(;Jh00,?J! !Q'C
!	(	G"   r%   r0   c                s   \         P                  RV ,          ,           p\        P                  ! V4      p VP	                  4       pTP                  p\        T4      pT'       d   \        Y/\        4       4       \        T4      pT'       d   \        Y/\        4       4       \        T4      pT'       d   \        Y/\        4       4       R# R#   \        P
                   d#   p\        P                  ! RY4        Rp?R# Rp?ii ; i)z1Download all media types for a single lutris gamez/api/games/%szUnable to load %s: %sN)r   rC   r   rD   r:   rE   r   rL   r    _get_response_game_iconr   r   _get_response_game_bannerr   _get_response_game_coverartr   )	r   rG   rH   rI   rJ   Zresponse_dataicon_url
banner_urlZcoverart_urls	   &        r#   download_lutris_mediarm      s    


o4
4Cll3G;;= MMM&}5H'6*=9J)<>:.}=L+^-=>  >> ,d7s   C D#D  Dc                s~    V ^8  d   QhR\         \        \        ,          ,          R\        \        \        3,          /# )r_   slugsr`   )r   r   r9   r   Zintrb      "r#   rd   rd      s+     < <hx}- <c3h <r%   c                s   V f!   \        4        Uu0 uF  qR,          kK  	  p pM\        R V  4       4      p V '       g   / # \        P                  ! \        P
                  4       Uu0 uF  q"P                  R4      ^ ,          kK  	  pp\        P                  ! \        P                  4       Uu0 uFC  q"P                  R4      '       g   K  VP                  R4      ^ ,          P                  RR4      kKE  	  pp\        P                  ! \        P                  4       Uu0 uF  q"P                  R4      ^ ,          kK  	  ppVP                  V4      P                  V4      pW,
          pV'       g   / # \        \        V4      4      p/ p	\        4       p
V FM  pV
P                  VR,          4       VR,           F%  pVR,          V9   g   K  VR,          WR,          &   K'  	  KO  	  \        V	P                  4       4      pW,
          pV FC  pV F:  pYR,           Uu. uF  qR,          NK  	  up9   g   K(  WR,          ,          VR&   K<  	  KE  	  V Uu/ uF9  pVR,          V9  g   K  \!        V4      '       g   K&  VR,          \!        V4      bK;  	  ppV Uu/ uF9  pVR,          V9  g   K  \#        V4      '       g   K&  VR,          \#        V4      bK;  	  ppV Uu/ uF9  pVR,          V9  g   K  \%        V4      '       g   K&  VR,          \%        V4      bK;  	  pp\&        P(                  ! R\+        V4      \+        V4      \+        V4      4       \-        V\/        4       4      p\-        V\1        4       4      p\-        V\3        4       4      pR\+        V4      R	\+        V4      R
\+        V4      /# u upi u upi u upi u upi u upi u upi u upi u upi )ztDownload missing media for Lutris games; if a set of slugs
is not provided, downloads them for all games in the PGA.r   c              3   s8   "   T F  q'       g   K  Vx  K  	  R # 5irO   r&   )Z.0Zss   & r#   Z	<genexpr>Zsync_media.<locals>.<genexpr>   s     *u!AAus   	
Z.Zlutris_r[   Zaliasesz*Syncing %s banners, %s icons and %s coversZbannersZiconsZcovers)r   Zsetrg   Zlistdirr   ZBANNER_PATHZsplitZ	ICON_PATHZ
startswithZreplaceZCOVERART_PATHZintersectionr   ZlistZaddZvaluesri   rh   rj   r   rL   rM   r   r   r   r   )rn   r;   ZfnZbanners_availableZicons_availableZcovers_availableZcomplete_gamesZslugs_to_downloadZgamesZ	alias_mapZ	api_slugsZaliasZalias_slugsZused_alias_slugsZ
alias_slugZbanner_urlsZ	icon_urlsZcoverart_urlsZdownloaded_bannersZdownloaded_iconsZdownloaded_coverss   &                    r#   rQ   rQ      s    }*3+6+$f+6*u**	46JJx?S?S4TU4Tb#q))4TU:<**XEWEW:X:XB\i\ijs\t/a  B/:X   46::h>T>T3UV3URa((3UV&33ODQQRbcN.	$012EIId6l#)__EV} 11*/-	v,' % 
 i&&()K".&
DiIFmmII(f6V  ' D<00 	65Nt5T 	6V/55   D<. 	43J43P 	4V-d33   D<// 	84OPT4U 	8V1$77  
 LL=s;?OQTU^Q_aderast'\^D%i>&}n6FG3)*%&#'( i 7 V W& J

sY   N3' N8/N=,N=  OO
O*O=OO/OOO4OOc                h    V ^8  d   QhR\         \        \        3,          R\        \        ,          /# r_   api_gamer`   r   r9   r   r   ro   rp   r#   rd   rd      s&     $ $$sCx. $Xc] $r%   c                 s$    V P                  R 4      # )Zcoverartr:   rs   r6   r#   rj   rj      s    <<
##r%   c                rq   rr   rt   ro   rp   r#   rd   rd     s*     @ @S#X @8C= @r%   c                 V    V P                  R 4      ;'       g    V P                  R4      # )rl   r2   ru   rv   r6   r#   ri   ri     s"    <<%??h)??r%   c                rq   rr   rt   ro   rp   r#   rd   rd     s&     < <d38n <# <r%   c                 rw   )rk   r1   ru   rv   r6   r#   rh   rh     s"    <<
#;;x||F';;r%   rO   )2r    rg   r    rY   Ztypingr   r   r   r   r   Zgi.repositoryr   r   r   Z
lutris.apir   r	   r
   Zlutris.database.gamesr   Zlutris.database.servicesr   Zlutris.gamer   Z
lutris.guir   Zlutris.gui.views.media_loaderr   Zlutris.services.baser   r   r   r   r   r   Zlutris.services.service_gamer   Zlutris.utilr   Zlutris.util.busyr   Zlutris.util.logr   r   r0   rm   rQ   rj   ri   rh   r&   r%   r#   <module>rx      s}     	   6 6   G G + :   8  5  * "  yM yx?.<~$@<r%   