
    i#                     B   S r SSKrSSKrSSKrSSKJr  \R                  " S5      r0 r	/ r
\R                  (       a  / SQrO'S\R                  R                  S5      (       a  S	OS
S/r\R                  (       aN  \R!                  \R"                  R%                  \R"                  R'                  \R(                  5      S5      5        S rS rS rS rSS\R2                  \	4S jrS rS\	4S jrS\	4S jrS\	4S jr\	4S jr\	4S jr\	4S jr \	4S jr! " S S5      r"g)zGlobal configuration module    N   )utilconfig)z %APPDATA%\gallery-dl\config.jsonz$%USERPROFILE%\gallery-dl\config.jsonz%USERPROFILE%\gallery-dl.confz/etc/gallery-dl.confXDG_CONFIG_HOMEz)${XDG_CONFIG_HOME}/gallery-dl/config.jsonz&${HOME}/.config/gallery-dl/config.jsonz${HOME}/.gallery-dl.confzgallery-dl.confc                     [        [        [        R                  [        5      5      n U  HV  n[
        R                  " U[
        R                  [
        R                  -  5      (       d  M@  [        R                  SU5          g   U  H[  n [
        R                  " [
        R                  R                  U5      SS9  [        USSS9 nUR                  S5        S S S 5          O   [        R                  S
5        g[        R)                  SU5        g! , (       d  f       N?= f! [          a6  n[        R#                  S	UR$                  R&                  U5         S nAM  S nAff = f)Nz-There is already a configuration file at '%s'r   T)exist_okxutf-8encodingzq{
    "extractor": {

    },
    "downloader": {

    },
    "output": {

    },
    "postprocessor": {

    }
}
z%s: %szEUnable to create a new configuration file at any of the default pathsz*Created a basic configuration file at '%s'r   )listmapr   expand_path_default_configsosaccessR_OKW_OKlogerrormakedirspathdirnameopenwriteOSErrordebug	__class____name__info)pathsr   fpexcs       >/app/mltbenv/lib/python3.13/site-packages/gallery_dl/config.py
initializer%   5   s   T%%'789E99T277RWW,--IIEtL 
 	=KK-=dC'2b   3" ) 0 			 0 	1HH94@5 32$  	=IIh 6 6<<	=s0   
=D#DD#
D 	D##
E#-+EE#c                     [          HV  n [        R                  " U 5      n [        R                  " U [        R
                  [        R                  -  5      (       d  MV    O   [        R                  S5        g[        R                  (       a  SnO.Sn[        R                  R                  S5      =n(       a  U4U-   nSS KnU H  nUR                  U5      =n(       d  M    O   [        R                  SU 5        g[        R                  SX@5        [        R                  " X@45      R!                  5       nU(       d:   [#        U S	S
9 n[        R$                  " UR'                  5       5        S S S 5        U$ U$ ! , (       d  f       U$ = f! [(         a5  n[        R                  SUR*                  R,                  X5         S nAgS nAff = f)Nz.Unable to find any writable configuration filer   )explorernotepad)zxdg-openr   EDITORr   z*Unable to find a program to open '%s' withzRunning '%s %s'r
   r   z%s when parsing '%s': %s   )r   r   r   r   r   r   r   r   warningWINDOWSenvirongetshutilwhichr    Popenwaitr   
json_loadsread	Exceptionr   r   )r   openerseditorr/   openerretcoder"   r#   s           r$   open_externr:   ]   s\    %99T277RWW,-- !
 	DE||)&ZZ^^H--6-i')G\\&))6)  	@$GHH-jj&(--/G	dW-	* . N7N .- N  	KK2..;	s6   >
F %E9-F 9
FF F 
G
+GG
c                  0   SSK Jn   / n[         He  n[        R                  " U5      n [        USS9 n[        R                  " UR                  5       5        S S S 5        SnUR                  X$45        Mg     S
[        S U 5       5       S3R                   nU H  u  p$U " U" X$5      5        M     g ! , (       d  f       N`= f! [         a    Sn No[         a    Sn N|[         a    Sn N[         a!  n[        R                  U5        S	n S nANS nAff = f)Nr   )stdout_writer
   r   OKzNot PresentInaccessiblezInvalid JSONUnknownz{:<c              3   >   #    U  H  n[        US    5      v   M     g7f)r   N)len).0ps     r$   	<genexpr>status.<locals>.<genexpr>   s     .1S1YYs   z} : {}
)outputr<   r   r   r   r   r3   r4   FileNotFoundErrorr   
ValueErrorr5   r   r   appendmaxformat)r<   r!   r   r"   statusr#   fmts          r$   rL   rL      s    $E %	dW-	* . Fd^$% !( .../{
;
B
BCS&' % .-  	#"F 	$#F 	$#F 	IIcNF	s@   
C%B2C2
C 	<CDDD+	D4DDc                     [         R                  S5      n U (       d  g U R                  S5      nUc  SnO-U(       d  g [        U[        5      (       a  UR	                  5       nU H  u  p#X ;   d  M  X0;  d  M  X   X'   M     g )N	extractorz
config-map)	)coomerpartycoomer)kemonopartykemono)giantessbooru	sizebooru)koharuschalenetwork)naverz
naver-blog)chzzkznaver-chzzk)naverwebtoonznaver-webtoon)pixivzpixiv-novel)saintturbo)_configr.   
isinstancedictitems)optscmapoldnews       r$   remap_categoriesrf      sn    ;;{#D88L!D|

 	D$		zz|;3?	DI     Fc                    U =(       d    [          H  n[        R                  " U5      n [        USS9 nU" UR	                  5       5      nSSS5        U(       d  UR                  W5        O[        R                  " UW5        [        R                  U5        SU;   a4  US   =n(       a&  [        U[        5      (       a  U4n[        XX#5        M  M  M     g! , (       d  f       N= f! [         a3  n	U(       a   [        R                  U	5        [        S5      e Sn	A	GM  Sn	A	f[          aI  n	[        R                  SU	R"                  R$                  XY5        U(       a  [        S5      e Sn	A	GMa  Sn	A	ff = f)zLoad JSON configuration filesr
   r   N
subconfigsr   z%s when loading '%s': %sr*   )r   r   r   r   r4   updatecombine_dict_filesrI   r_   strloadr   r   r   
SystemExitr5   r   r   )
filesstrictloadsconfpathfmtr   r"   r   ri   r#   s
             r$   rn   rn      s(   ,,,(	:dW-rwwy) . F#!!$/MM'"v%!'!55:5!*c22&0]
U9 6 &+ - .- 	$		# m#   	$II0mm,,d9 m# 	$s:   
C(CC(
C%	!C((
E62'D  E6-=E11E6c                  ,    [         R                  5         g)z%Reset configuration to an empty stateN)r^   clear rg   r$   rv   rv      s    MMOrg   c                 J     U  H  nX4   nM	     X1   $ ! [          a    Us $ f = f)z2Get the value of property 'key' or a default valuer5   r   keydefaultrs   rC   s        r$   r.   r.      s4    A7D y s    ""c                 l    X;   a  X1   $  U  H  nX4   nX;   d  M  X1   nM     U$ ! [          a     U$ f = f)zInterpolate the value of 'key'ry   rz   s        r$   interpolater~      sQ    
{yA7D{)  N  Ns   % % 
33c                 $   X$;   a  XB   $  U  H  nXE   nX$;   d  M  XB   nM     [        R                  nU H5  nUn U H  nX   nX(;   d  M  X   nM     U[        R                  Ld  M3  Us  $    U$ ! [          a    Us $ f = f! [          a     N;f = f)zPInterpolate the value of 'key'
using multiple 'paths' along a 'common' ancestor
)r5   r   SENTINEL)	commonr!   r{   r|   rs   rC   valuer   cs	            r$   interpolate_commonr      s     {yA7D{)  MME	D8FE  %L  N!    		s-   A0 A0 BB0A?>A?
BBc                 Z   / n X;   aC  X!   =n(       a8  [        U[        5      (       a  UR                  U5        OUR                  U5        U  HH  nX%   nX;   d  M  X!   =n(       d  M  [        U[        5      (       a  XCSS& M6  UR	                  SU5        MJ     U$ ! [
         a     U$ f = f)z+Accumulate the values of 'key' along 'path'Nr   )r_   r   extendrI   insertr5   )r   r{   rs   resultr   rC   s         r$   
accumulater     s    F;	!u!eT**MM%(MM%(A7D{ I%5%!%..%*r
a/  M  Ms   AB 	B )1B 
B*)B*c                 V    U  H  n X4   nM
     X#U'   g! [          a
    0 =X4'   n M$  f = f)z0Set the value of property 'key' for this sessionN)KeyErrorr   r{   r   rs   rC   s        r$   setr   0  s>    	 7D 
 I  	 DGd	 s   ((c                 n    U  H  n X4   nM
     UR                  X5      $ ! [          a
    0 =X4'   n M0  f = f)z3Set the value of property 'key' if it doesn't exist)r   
setdefaultr   s        r$   r   r   :  sF    	 7D 
 ??3&&  	 DGd	 s    44c                 D     U  H  nX#   nM	     X!	 g! [          a     gf = f)z!Unset the value of property 'key'Nry   )r   r{   rs   rC   s       r$   unsetr   D  s/    A7D I s    
c                   *    \ rS rSrSrS rS rS rSrg)applyiN  z6Context Manager: apply a collection of key-value pairsc                     / U l         Xl        g N)originalkvlist)selfr   s     r$   __init__apply.__init__Q  s    rg   c           
          U R                    HG  u  pnU R                  R                  X[        X[        R
                  5      45        [        XU5        MI     g r   )r   r   rI   r.   r   r   r   )r   r   r{   r   s       r$   	__enter__apply.__enter__U  sA     $DuMM  $SDMM-J!KL5! !,rg   c                     U R                   R                  5         U R                    H2  u  pEnU[        R                  L a  [	        XE5        M&  [        XEU5        M4     g r   )r   reverser   r   r   r   )r   exc_type	exc_value	tracebackr   r{   r   s          r$   __exit__apply.__exit__Z  sC     $Du%d Du%	 !.rg   )r   r   N)	r   
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__rw   rg   r$   r   r   N  s    @"
&rg   r   )#r   sysos.pathr   logging r   	getLoggerr   r^   rl   r,   r   r-   r.   
EXECUTABLErI   r   joinr   
executabler%   r:   rL   rf   r3   rn   rv   r~   r   r   r   r   r   r   rw   rg   r$   <module>r      s0   " 
   ! 	<< 	::>>+,, 	40" ??BGGLL
' %P$N(<"8 Ew :<
  g  $(g  48g @  ' .  '  '. ' " & &rg   