4040
4141import requests
4242import undetected_chromedriver as uc
43- from fake_headers import Headers
43+ from fake_headers import Headers , browsers
4444from selenium import webdriver
4545from selenium .common .exceptions import NoSuchElementException
4646from selenium .webdriver .common .by import By
@@ -86,7 +86,7 @@ class bcolors:
8686 [ GitHub : https://github.com/MShawon/YouTube-Viewer ]
8787""" + bcolors .ENDC )
8888
89- SCRIPT_VERSION = '1.4.2 '
89+ SCRIPT_VERSION = '1.4.3 '
9090
9191proxy = None
9292driver = None
@@ -111,6 +111,13 @@ class bcolors:
111111website .console = console
112112website .database = DATABASE
113113
114+ link = 'https://gist.githubusercontent.com/MShawon/29e185038f22e6ac5eac822a1e422e9d/raw/85c1e74ea5f958f952f0a88a836c437949d8b4e9/versions.txt'
115+
116+ output = requests .get (link , timeout = 60 ).text
117+ chrome_versions = output .split ('\n ' )
118+
119+ browsers .chrome_ver += chrome_versions
120+
114121
115122class UrlsError (Exception ):
116123 pass
@@ -415,8 +422,7 @@ def bypass_consent(driver):
415422 driver .execute_script ("arguments[0].scrollIntoView();" , consent )
416423 consent .click ()
417424 except :
418- consent = WebDriverWait (driver , 15 ).until (EC .element_to_be_clickable (
419- (By .XPATH , "//input[@type='submit' and @value='I agree']" )))
425+ consent = driver .find_element_by_xpath ("//input[@type='submit' and @value='I agree']" )
420426 driver .execute_script ("arguments[0].scrollIntoView();" , consent )
421427 consent .submit ()
422428
@@ -443,20 +449,22 @@ def bypass_signin(driver):
443449 pass
444450
445451
446- def skip_initial_ad (driver , position ):
452+ def skip_initial_ad (driver , position , video ):
447453 try :
448- skip_ad = WebDriverWait (driver , 20 ).until (EC .element_to_be_clickable (
449- (By .CLASS_NAME , "ytp-ad-skip-button-container" )))
450- if skip_ad :
454+ video_len = duration_dict [video ]
455+ if video_len > 60 :
456+ skip_ad = WebDriverWait (driver , 20 ).until (EC .element_to_be_clickable (
457+ (By .CLASS_NAME , "ytp-ad-skip-button-container" )))
458+
451459 print (timestamp () + bcolors .OKBLUE +
452- f"Tried { position + 1 } | Skipping Ads..." + bcolors .ENDC )
460+ f"Tried { position + 1 } | Skipping Ads..." + bcolors .ENDC )
453461
454462 create_html ({"#23d18b" : f"Tried { position + 1 } | Skipping Ads..." })
455463
456464 ad_duration = driver .find_element_by_class_name (
457465 'ytp-time-duration' ).get_attribute ('innerText' )
458466 ad_duration = sum (x * int (t )
459- for x , t in zip ([60 , 1 ], ad_duration .split (":" )))
467+ for x , t in zip ([60 , 1 ], ad_duration .split (":" )))
460468 ad_duration = ad_duration * uniform (.01 , .1 )
461469 sleep (ad_duration )
462470 skip_ad .click ()
@@ -495,10 +503,10 @@ def search_video(driver, keyword, video_title):
495503 find_video .click ()
496504 break
497505 except NoSuchElementException :
506+ sleep (5 )
498507 WebDriverWait (driver , 30 ).until (EC .element_to_be_clickable (
499508 (By .TAG_NAME , 'body' ))).send_keys (Keys .CONTROL , Keys .END )
500- sleep (5 )
501-
509+
502510 return i
503511
504512
@@ -618,19 +626,19 @@ def main_viewer(proxy_type, proxy, position):
618626
619627 bypass_consent (driver )
620628
621- bypass_signin (driver )
622-
623629 if method == 1 :
624- skip_initial_ad (driver , position )
630+ skip_initial_ad (driver , position , output )
625631
626632 else :
627633 scroll = search_video (driver , keyword , video_title )
628634 if scroll == 0 :
629635 raise CaptchaError
630636 elif scroll == 10 :
631637 raise QueryError
638+ else :
639+ pass
632640
633- skip_initial_ad (driver , position )
641+ skip_initial_ad (driver , position , output )
634642
635643 try :
636644 driver .find_element_by_xpath (
@@ -641,14 +649,14 @@ def main_viewer(proxy_type, proxy, position):
641649 check_state (driver )
642650
643651 try :
644- video_len = duration_dict [url ]
652+ video_len = duration_dict [output ]
645653 except KeyError :
646654 video_len = 0
647655 while video_len == 0 :
648656 video_len = driver .execute_script (
649657 "return document.getElementById('movie_player').getDuration()" )
650658
651- duration_dict [url ] = video_len
659+ duration_dict [output ] = video_len
652660
653661 video_len = video_len * uniform (.85 , .95 )
654662
@@ -755,26 +763,32 @@ def main_viewer(proxy_type, proxy, position):
755763 pass
756764
757765
766+ def call_viewer (position ):
767+ proxy = proxy_list [position ]
768+
769+ if proxy_type :
770+ main_viewer (proxy_type , proxy , position )
771+ else :
772+ main_viewer ('http' , proxy , position )
773+ if checked [position ] == 'http' :
774+ main_viewer ('socks4' , proxy , position )
775+ if checked [position ] == 'socks4' :
776+ main_viewer ('socks5' , proxy , position )
777+
778+
758779def view_video (position ):
759780 global server_running
760781
761- proxy = proxy_list [position ]
762-
763782 if position != 0 :
764- if proxy_type :
765- main_viewer (proxy_type , proxy , position )
766- else :
767- main_viewer ('http' , proxy , position )
768- if checked [position ] == 'http' :
769- main_viewer ('socks4' , proxy , position )
770- if checked [position ] == 'socks4' :
771- main_viewer ('socks5' , proxy , position )
783+ call_viewer (position )
772784
773785 else :
774786 if api and not server_running :
775787 server_running = True
776788 website .start_server (host = host , port = port )
777-
789+ else :
790+ call_viewer (position )
791+
778792
779793def main ():
780794 pool_number = [i for i in range (total_proxies )]
@@ -807,6 +821,10 @@ def main():
807821 queries = load_search ()
808822
809823 if os .path .isfile ('config.json' ):
824+ with open ('config.json' , 'r' ) as openfile :
825+ config = json .load (openfile )
826+ print (json .dumps (config , indent = 4 ))
827+
810828 previous = str (input (
811829 bcolors .OKBLUE + 'Config file exists! Do you want to continue with previous saved preferences ? [Yes/No] : ' + bcolors .ENDC )).lower ()
812830 if previous == 'n' or previous == 'no' :
0 commit comments