
    	h6&                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ	 d dl
mZmZmZmZ d dlZd dlmZ 	 d dlmZ n# e$ r dZY nw xY wddedz  fd	Zddedz  fd
Zddedz  fdZedk    r ed           dS dS )    N)By)WebDriverWait)expected_conditions)TimeoutExceptionNoSuchElementExceptionWebDriverException ElementClickInterceptedException)
app_logger)	ConsoleUIuic                 (   t          j                    j        }t          j        d| d           |                    ddd          }d}	 t          j        d| d| d	           t          | |          }|                    t          j
        t          j        |f                    }t          j        d| d
           	 |                     d|           t          j        d           |                     d|           t          j        d| d           dS # t           $ r}t          j        d| d| d           	 |                                 t          j        d| d           Y d}~dS # t&          $ r)}	t          j        d| d|	            Y d}	~	Y d}~dS d}	~	wt           $ r+}
t          j        d| d|
 d           Y d}
~
Y d}~dS d}
~
ww xY wd}~ww xY w# t*          $ r t          j        d| d| d           Y nt,          $ r t          j        d| d|            Y n`t.          $ r&}	t          j        d| d|	 d           Y d}	~	n6d}	~	wt           $ r&}	t          j        d| d|	 d           Y d}	~	nd}	~	ww xY wdS )z%Handles download from pixeldrain.com.[z!] Executing Pixeldrain handler...Seleniumpixeldrain_button_waitg     F@fallbackz://button[span[text()='Download' or text()='DL all files']]z*] Waiting for Pixeldrain download button (s)...z/] Pixeldrain download button found. Clicking.../arguments[0].scrollIntoView({block: 'center'});      ?arguments[0].click();z,] Clicked Pixeldrain download button via JS.Tz] JavaScript click failed (z), attempting direct click...z.] Clicked Pixeldrain download button directly.Nz2] Direct click intercepted for Pixeldrain button: Fz-] Direct click failed for Pixeldrain button: exc_infoz9] Timed out waiting for Pixeldrain download button after s.z9] Could not find Pixeldrain download button using XPath: z1] WebDriver error during Pixeldrain interaction: z*] Unexpected error in Pixeldrain handler: )	threadingcurrent_threadnamer
   infogetfloatdebugr   untilECelement_to_be_clickabler   XPATHexecute_scripttimesleep	Exceptionwarningclickr	   errorr   r   r   )driverconfigr   thread_name	wait_timedownload_button_xpathwaitdownload_buttonjs_click_erredirect_click_errs              ;c:\Users\brownies\Downloads\rentrytest\selenium_handlers.pyhandle_pixeldrainr6      s   *,,1KOFFFFGGG
,DtTTI Y=
WWWyWWW	
 	
 	
 VY//**&2G'HII
 
 	LLLL	
 	
 	
	!!A?   JsOOO!!"9?KKKOMKMMM   4 	 	 	gKggLggg  %%'''SSSS   ttttt3    ZZZWXZZ   uuuuuuuuu    dddRbdd!    uuuuuuuuu	,  
 
 
cccV_ccc	
 	
 	
 	
 	
 " 
 
 
mmmVkmm	
 	
 	
 	
 	
  
 
 
QQQaQQ	
 	
 	
 	
 	
 	
 	
 	
 	
  
 
 
JJJqJJ	
 	
 	
 	
 	
 	
 	
 	
 	


 5s   A6G& AD 
G#'G,E5/G& 5
G?F#GG& #G0GGG& GGG##G& &%J#J2	J;IJ)J

Jc                    t          j                    j        }t          j        d| d           |                    ddd          }d}d}d	}	 	 t          | d
          }t          j        d| d           |                    t          j
        t          j        |f                    }	t          j        d| d           |                     d|	           t          j        d           nT# t           $ r t          j        d| d           Y n0t"          $ r$}
t          j        d| d|
            Y d}
~
nd}
~
ww xY wt          j        d| d| d           t          | |          }|                    t          j        t          j        |f                     |                    t          j
        t          j        |f                    }t          j        d| d           |                     d|           t          j        d           |                     d|           t          j        d| d           	 t          | d                              t          j        t          j        |f                     t          j        d| d           n(# t           $ r t          j        d| d           Y nw xY wdS # t           $ r t          j        d| d| d           Y nt,          $ r t          j        d| d|            Y n`t.          $ r&}
t          j        d| d|
 d            Y d}
~
n6d}
~
wt"          $ r&}
t          j        d| d!|
 d            Y d}
~
nd}
~
ww xY wd"S )#zHandles download from mega.nz.r   z] Executing Mega.nz handler...r   mega_button_waitg      N@r   z//button[contains(@class, 'js-download-button') or contains(@class, 'mega-button') or contains(@class, 'download-file')][.//span[contains(translate(., 'DOWNLOAD', 'download'), 'download')] or contains(translate(., 'DOWNLOAD', 'download'), 'download')]z//button[contains(@class, 'js-accept-cookies') or contains(translate(normalize-space(.), 'ACCEPT', 'accept'), 'accept')][not(ancestor::*[contains(@style,'display: none')])]zq//div[contains(@class, 'transfer-dialog') or contains(@class,'mega-dialog') or contains(@class,'transfer-panel')]
   z$] Checking for Mega cookie banner...z)] Cookie banner found. Clicking accept...r      z'] Cookie banner not found or timed out.z*] Non-fatal error handling cookie banner: Nz$] Waiting for Mega download button (r   z)] Mega download button found. Clicking...r   r   z] Clicked Mega download button.   z)] Mega internal transfer dialog detected.zJ] Mega internal transfer dialog did not appear quickly, proceeding anyway.Tz3] Timed out waiting for Mega download button after r   z3] Could not find Mega download button using XPath: z+] WebDriver error during Mega interaction: r   z$] Unexpected error in Mega handler: F)r   r   r   r
   r   r   r   r   r    r!   r"   r   r#   r$   r%   r&   r   r'   r(   presence_of_element_locatedvisibility_of_element_locatedr*   r   r   )r+   r,   r   r-   r.   r/   accept_cookies_xpathtransfer_dialog_xpath
wait_shortcookie_buttonr3   	wait_longr1   s                r5   handle_megarC   i   s   *,,1KOCCCCDDD
,>NNI Z J P?
	&vr22JRRRRSSS&,,*BH6J+KLL M OVVVVWWW!!"9=IIIJqMMMM 	W 	W 	WUUUUVVVVV 	 	 	NKNN1NN       	
 	QQQQQQ	
 	
 	
 "&)44	*BH6K+LMM	
 	
 	
 $//&2G'HII
 
 	S[SSSTTT=	
 	
 	
 	
35GGGHKHHHIII	&"%%++0"(<Q1RSS   OVVVVWWWW 	 	 	kKkkk    	 t 
 
 
]]]PY]]]	
 	
 	
 	
 	
 " 
 
 
gggPegg	
 	
 	
 	
 	
  
 
 
KKKKK	
 	
 	
 	
 	
 	
 	
 	
 	
  
 
 
DDDDDt	
 	
 	
 	
 	
 	
 	
 	
 	

 5s   BC/ .K	 /"E K	 	E D;6K	 ;E  DK	 AJ K	 "KK	 KK	 	%M20#M2	M2L??M2M--M2c           
         t          j                    j        }t          j        d| d           |                    ddd          }d}	 t          j        d| d| d	           t          | |          }|                    t          j
        t          j        |f                     |                    t          j        t          j        |f                    }t          j        d| d
           |                     d|           t          j        d           |                                 t          j        d| d           dS # t$          $ r! t          j        d| d| d| d           Y nt(          $ r t          j        d| d|            Y n`t*          $ r&}t          j        d| d| d           Y d}~n6d}~wt,          $ r&}t          j        d| d| d           Y d}~nd}~ww xY wdS )z$Handles download from mediafire.com.r   z ] Executing Mediafire handler...r   mediafire_button_waitg      .@r   zP//*[@id='downloadButton' and not(ancestor::*[contains(@style,'display: none')])]z)] Waiting for Mediafire download button (r   z<] Mediafire download button found and clickable. Clicking...r   r   z$] Clicked Mediafire download button.Tz:] Timed out waiting for Mediafire download button (XPath: z) after r   z8] Could not find Mediafire download button using XPath: z0] WebDriver error during Mediafire interaction: r   Nz)] Unexpected error in Mediafire handler: F)r   r   r   r
   r   r   r   r   r    r!   r<   r   r#   r"   r$   r%   r&   r)   r   r*   r   r   r'   )	r+   r,   r   r-   r.   r/   r0   r1   r3   s	            r5   handle_mediafirerF      s   *,,1KOEEEEFFF
,CdSSIn$
VVViVVV	
 	
 	
 VY//

2128=R2STTUUU**&2G'HII
 
 	YYYY	
 	
 	
 	=	
 	
 	
 	
3MKMMMNNNt 
 
 
 D  D  DWl  D  Dv  D  D  D	
 	
 	
 	
 	
 " 
 
 
lllUjll	
 	
 	
 	
 	
  
 
 
PPPQPP	
 	
 	
 	
 	
 	
 	
 	
 	
  
 
 
IIIaIITX	
 	
 	
 	
 	
 	
 	
 	
 	

 5s1   C?E (G97#G9	G9%GG9G44G9__main__zKThis module contains Selenium handlers and is not meant to be run directly.)N)r%   sysr   selenium.webdriver.common.byr   selenium.webdriver.support.uir   selenium.webdriver.supportr   r!   selenium.common.exceptionsr   r   r   r	   loggingloggerr
   
console_uir   ImportErrorr6   rC   rF   __name__print     r5   <module>rU      s    



     + + + + + + 7 7 7 7 7 7 @ @ @ @ @ @                  $$$$$$$   IIIG G)d*: G G G GTI II$4 I I I IX, ,T)9 , , , ,^ z	E
WXXXXX s   = AA