3333
3434import requests
3535import undetected_chromedriver as uc
36- from fake_useragent import UserAgent , UserAgentError
36+ from fake_headers import Headers
3737from selenium .common .exceptions import (ElementClickInterceptedException ,
3838 ElementNotInteractableException )
3939from selenium .webdriver .common .by import By
@@ -74,21 +74,18 @@ class bcolors:
7474 [ GitHub : https://github.com/MShawon/YouTube-Viewer ]
7575""" + bcolors .ENDC )
7676
77- print (bcolors .WARNING + 'Collecting User-Agent...' + bcolors .ENDC )
78-
79- try :
80- ua = UserAgent (use_cache_server = False , verify_ssl = False )
81- except UserAgentError :
82- ua = UserAgent (path = 'fake_useragent_0.1.11.json' )
83-
84-
85- PROXY = None
77+ proxy = None
8678driver = None
8779status = None
8880
8981view = []
9082duration_dict = {}
9183checked = {}
84+ REFERER = ['https://www.youtube.com/' , 'https://github.com/' , 'https://www.facebook.com/' , 'https://www.google.com/' ,
85+ 'https://m.facebook.com/' , 'https://yandex.com/' , 'https://www.yahoo.com/' , 'https://www.bing.com/' , 'https://duckduckgo.com/' ]
86+
87+ VIEWPORT = ['2560,1440' , '1920,1080' , '1440,900' ,
88+ '1536,864' , '1366,768' , '1280,1024' , '1024,768' ]
9289
9390print (bcolors .WARNING + 'Getting Chrome Driver...' + bcolors .ENDC )
9491
@@ -100,15 +97,17 @@ class bcolors:
10097Thanks goes to him.
10198"""
10299if OSNAME == 'Linux' :
100+ OSNAME = 'lin'
103101 with subprocess .Popen (['google-chrome' , '--version' ], stdout = subprocess .PIPE ) as proc :
104102 version = proc .stdout .read ().decode ('utf-8' ).replace ('Google Chrome' , '' ).strip ()
105103elif OSNAME == 'Darwin' :
106- OSNAME = 'Macintosh '
104+ OSNAME = 'mac '
107105 process = subprocess .Popen (
108106 ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' , '--version' ], stdout = subprocess .PIPE )
109107 version = process .communicate ()[0 ].decode (
110108 'UTF-8' ).replace ('Google Chrome' , '' ).strip ()
111109elif OSNAME == 'Windows' :
110+ OSNAME = 'win'
112111 process = subprocess .Popen (
113112 ['reg' , 'query' , 'HKEY_CURRENT_USER\\ Software\\ Google\\ Chrome\\ BLBeacon' , '/v' , 'version' ],
114113 stdout = subprocess .PIPE , stderr = subprocess .DEVNULL , stdin = subprocess .DEVNULL
@@ -197,20 +196,20 @@ def load_proxy():
197196 return proxies
198197
199198
200- def check_proxy (agent , PROXY , proxy_type ):
199+ def check_proxy (agent , proxy , proxy_type ):
201200 if category == 'f' :
202201 headers = {
203202 'User-Agent' : f'{ agent } ' ,
204203 }
205204 if proxy_type == 'https' :
206205 proxyDict = {
207- "http" : f"http://{ PROXY } " ,
208- "https" : f"https://{ PROXY } " ,
206+ "http" : f"http://{ proxy } " ,
207+ "https" : f"https://{ proxy } " ,
209208 }
210209 else :
211210 proxyDict = {
212- "http" : f"{ proxy_type } ://{ PROXY } " ,
213- "https" : f"{ proxy_type } ://{ PROXY } " ,
211+ "http" : f"{ proxy_type } ://{ proxy } " ,
212+ "https" : f"{ proxy_type } ://{ proxy } " ,
214213 }
215214 response = requests .get (
216215 'https://www.youtube.com/' , headers = headers , proxies = proxyDict , timeout = 30 )
@@ -222,12 +221,10 @@ def check_proxy(agent, PROXY, proxy_type):
222221 return status
223222
224223
225- def get_driver (agent , PROXY , proxy_type ):
224+ def get_driver (agent , proxy , proxy_type ):
226225 options = webdriver .ChromeOptions ()
227226 options .headless = background
228- viewport = ['2560,1440' , '1920,1080' , '1440,900' ,
229- '1536,864' , '1366,768' , '1280,1024' , '1024,768' ]
230- options .add_argument (f"--window-size={ choice (viewport )} " )
227+ options .add_argument (f"--window-size={ choice (VIEWPORT )} " )
231228 options .add_argument ("--log-level=3" )
232229 options .add_experimental_option (
233230 "excludeSwitches" , ["enable-automation" , "enable-logging" ])
@@ -242,15 +239,15 @@ def get_driver(agent, PROXY, proxy_type):
242239 if proxy_type == 'https' :
243240 sw_options = {
244241 'proxy' : {
245- 'http' : f'http://{ PROXY } ' ,
246- 'https' : f'https://{ PROXY } ' ,
242+ 'http' : f'http://{ proxy } ' ,
243+ 'https' : f'https://{ proxy } ' ,
247244 }
248245 }
249246 else :
250247 sw_options = {
251248 'proxy' : {
252- 'http' : f'{ proxy_type } ://{ PROXY } ' ,
253- 'https' : f'{ proxy_type } ://{ PROXY } ' ,
249+ 'http' : f'{ proxy_type } ://{ proxy } ' ,
250+ 'https' : f'{ proxy_type } ://{ proxy } ' ,
254251 }
255252 }
256253
@@ -312,32 +309,41 @@ def sleeping():
312309 sleep (30 )
313310
314311
315- def main_viewer (proxy_type , PROXY , position ):
312+ def main_viewer (proxy_type , proxy , position ):
316313 try :
317314
318315 checked [position ] = None
319316
320- agent = ua .chrome
321- while OSNAME not in agent :
322- agent = ua .chrome
317+ header = Headers (
318+ browser = "chrome" ,
319+ os = OSNAME ,
320+ headers = False
321+ ).generate ()
322+ agent = header ['User-Agent' ]
323323
324- status = check_proxy (agent , PROXY , proxy_type )
324+ status = check_proxy (agent , proxy , proxy_type )
325325
326326 if status == 200 :
327327 try :
328328 print (bcolors .OKBLUE + f"Tried { position + 1 } |" +
329- bcolors .OKGREEN + f'{ PROXY } | { proxy_type } --> Good Proxy | Searching for videos...' + bcolors .ENDC )
329+ bcolors .OKGREEN + f'{ proxy } | { proxy_type } --> Good Proxy | Searching for videos...' + bcolors .ENDC )
330+
331+ driver = get_driver (agent , proxy , proxy_type )
330332
331333 if position % 2 :
332334 method = 1
333335 url = choice (urls )
336+ if 'youtu' in url :
337+ def interceptor (request ):
338+ del request .headers ['Referer' ]
339+ request .headers ['Referer' ] = choice (REFERER )
340+
341+ driver .request_interceptor = interceptor
334342 else :
335343 method = 2
336344 query = choice (queries )
337345 url = f"https://www.youtube.com/results?search_query={ query [0 ].replace (' ' , '%20' )} "
338346
339- driver = get_driver (agent , PROXY , proxy_type )
340-
341347 driver .get (url )
342348
343349 bypass_consent (driver )
@@ -390,7 +396,7 @@ def main_viewer(proxy_type, PROXY, position):
390396
391397 duration = strftime ("%Hh:%Mm:%Ss" , gmtime (video_len ))
392398 print (bcolors .OKBLUE + f"Tried { position + 1 } |" + bcolors .OKGREEN +
393- f' { PROXY } --> Video Found : { url } | Watch Duration : { duration } ' + bcolors .ENDC )
399+ f' { proxy } --> Video Found : { url } | Watch Duration : { duration } ' + bcolors .ENDC )
394400
395401 check_state (driver )
396402
@@ -413,23 +419,23 @@ def main_viewer(proxy_type, PROXY, position):
413419
414420 except :
415421 print (bcolors .OKBLUE + f"Tried { position + 1 } |" + bcolors .FAIL +
416- f' { PROXY } | { proxy_type } --> Bad proxy ' + bcolors .ENDC )
422+ f' { proxy } | { proxy_type } --> Bad proxy ' + bcolors .ENDC )
417423 checked [position ] = proxy_type
418424 pass
419425
420426
421427def view_video (position ):
422- PROXY = proxy_list [position ]
428+ proxy = proxy_list [position ]
423429
424430 if category == 'f' :
425- main_viewer ('https' , PROXY , position )
431+ main_viewer ('https' , proxy , position )
426432 if checked [position ] == 'https' :
427- main_viewer ('socks4' , PROXY , position )
433+ main_viewer ('socks4' , proxy , position )
428434 if checked [position ] == 'socks4' :
429- main_viewer ('socks5' , PROXY , position )
435+ main_viewer ('socks5' , proxy , position )
430436
431437 else :
432- main_viewer (proxy_type , PROXY , position )
438+ main_viewer (proxy_type , proxy , position )
433439
434440
435441def main ():
@@ -462,7 +468,7 @@ def main():
462468 views = int (input (bcolors .OKBLUE + 'Amount of views : ' + bcolors .ENDC ))
463469
464470 category = input (bcolors .WARNING +
465- "What's your proxy category? [F = Free Proxy , P = Premium Proxy , R = Rotating Proxy] : " + bcolors .ENDC ).lower ()
471+ "What's your proxy category? [F = Free (without user:pass) , P = Premium (with user:pass) , R = Rotating Proxy] : " + bcolors .ENDC ).lower ()
466472
467473 if category == 'f' :
468474 handle_proxy = str (input (
@@ -488,9 +494,9 @@ def main():
488494 sys .exit ()
489495
490496 if category == 'r' :
491- PROXY = input (bcolors .OKBLUE +
497+ proxy = input (bcolors .OKBLUE +
492498 'Enter your Rotating Proxy service Main Gateway : ' + bcolors .ENDC )
493- proxy_list = [PROXY ]
499+ proxy_list = [proxy ]
494500 proxy_list = proxy_list * 100000
495501 else :
496502 proxy_list = load_proxy ()
0 commit comments