Skip to content

Commit b7ecbd3

Browse files
committed
script stuck fixes, bug fixes
1 parent 5d57bb6 commit b7ecbd3

File tree

2 files changed

+68
-36
lines changed

2 files changed

+68
-36
lines changed

website.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
console = []
1313
database = 'database.db'
1414

15-
def create_graph_data(dropdown_text):
1615

16+
def create_graph_data(dropdown_text):
1717
now = datetime.now()
1818
day = now.day
1919
month = now.month
@@ -87,6 +87,13 @@ def create_dropdown_data():
8787
return dropdown
8888

8989

90+
def shutdown_server():
91+
func = request.environ.get('werkzeug.server.shutdown')
92+
if func is None:
93+
raise RuntimeError('Not running with the Werkzeug Server')
94+
func()
95+
96+
9097
def start_server(host, port):
9198
app = Flask(__name__,
9299
static_url_path='',
@@ -116,9 +123,13 @@ def graph():
116123
'last': last_date
117124
})
118125

126+
@app.route('/shutdown', methods=['POST'])
127+
def shutdown():
128+
shutdown_server()
129+
return 'Server shutting down...'
119130

120131
app.run(host=host, port=port)
121132

122133

123-
if __name__ == '__main__':
134+
if __name__ == '__main__':
124135
start_server(host='0.0.0.0', port=5000)

youtube_viewer.py

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class bcolors:
8686
[ GitHub : https://github.com/MShawon/YouTube-Viewer ]
8787
""" + bcolors.ENDC)
8888

89-
SCRIPT_VERSION = '1.4.6'
89+
SCRIPT_VERSION = '1.4.7'
9090

9191
proxy = None
9292
driver = None
@@ -97,6 +97,7 @@ class bcolors:
9797
duration_dict = {}
9898
checked = {}
9999
console = []
100+
completed = 0
100101

101102
WEBRTC = os.path.join('extension', 'webrtc_control.zip')
102103
ACTIVE = os.path.join('extension', 'always_active.zip')
@@ -369,6 +370,7 @@ def get_driver(agent, proxy, proxy_type, pluginfile):
369370
options.add_experimental_option(
370371
"excludeSwitches", ["enable-automation", "enable-logging"])
371372
options.add_experimental_option('useAutomationExtension', False)
373+
options.add_argument("--lang=en-US")
372374
options.add_argument(f"user-agent={agent}")
373375
options.add_argument("--mute-audio")
374376
options.add_argument('--disable-features=UserAgentClientHint')
@@ -516,9 +518,9 @@ def skip_initial_ad(driver, position, video):
516518
(By.CLASS_NAME, "ytp-ad-skip-button-container")))
517519

518520
print(timestamp() + bcolors.OKBLUE +
519-
f"Tried {position+1} | Skipping Ads..." + bcolors.ENDC)
521+
f"Tried {position} | Skipping Ads..." + bcolors.ENDC)
520522

521-
create_html({"#23d18b": f"Tried {position+1} | Skipping Ads..."})
523+
create_html({"#23d18b": f"Tried {position} | Skipping Ads..."})
522524

523525
ad_duration = driver.find_element_by_class_name(
524526
'ytp-time-duration').get_attribute('innerText')
@@ -544,8 +546,12 @@ def search_video(driver, keyword, video_title):
544546
if method == 1:
545547
input_keyword.send_keys(Keys.ENTER)
546548
else:
547-
driver.find_element_by_xpath(
548-
'//*[@id="search-icon-legacy"]').click()
549+
try:
550+
driver.find_element_by_xpath(
551+
'//*[@id="search-icon-legacy"]').click()
552+
except:
553+
driver.execute_script(
554+
'document.querySelector("#search-icon-legacy").click()')
549555

550556
except:
551557
return i
@@ -633,7 +639,7 @@ def quit_driver(driver, pluginfile):
633639

634640

635641
def sleeping():
636-
sleep(30)
642+
sleep(5)
637643

638644

639645
def main_viewer(proxy_type, proxy, position):
@@ -654,10 +660,10 @@ def main_viewer(proxy_type, proxy, position):
654660

655661
if status == 200:
656662
try:
657-
print(timestamp() + bcolors.OKBLUE + f"Tried {position+1} | " + bcolors.OKGREEN +
663+
print(timestamp() + bcolors.OKBLUE + f"Tried {position} | " + bcolors.OKGREEN +
658664
f"{proxy} | {proxy_type} --> Good Proxy | Opening a new driver..." + bcolors.ENDC)
659665

660-
create_html({"#3b8eea": f"Tried {position+1} | ",
666+
create_html({"#3b8eea": f"Tried {position} | ",
661667
"#23d18b": f"{proxy} | {proxy_type} --> Good Proxy | Opening a new driver..."})
662668

663669
pluginfile = os.path.join(
@@ -704,10 +710,10 @@ def main_viewer(proxy_type, proxy, position):
704710

705711
if 'consent' in driver.current_url:
706712
print(timestamp() + bcolors.OKBLUE +
707-
f"Tried {position+1} | Bypassing consent..." + bcolors.ENDC)
713+
f"Tried {position} | Bypassing consent..." + bcolors.ENDC)
708714

709715
create_html(
710-
{"#3b8eea": f"Tried {position+1} | Bypassing consent..."})
716+
{"#3b8eea": f"Tried {position} | Bypassing consent..."})
711717

712718
bypass_consent(driver)
713719

@@ -763,10 +769,10 @@ def main_viewer(proxy_type, proxy, position):
763769
view_stat = driver.find_element_by_xpath(
764770
'//span[@class="view-count style-scope ytd-video-view-count-renderer"]').text
765771
if 'watching' in view_stat:
766-
print(timestamp() + bcolors.OKBLUE + f"Tried {position+1} | " + bcolors.OKGREEN +
772+
print(timestamp() + bcolors.OKBLUE + f"Tried {position} | " + bcolors.OKGREEN +
767773
f"{proxy} | {output} | " + bcolors.OKCYAN + f"{view_stat} " + bcolors.ENDC)
768774

769-
create_html({"#3b8eea": f"Tried {position+1} | ",
775+
create_html({"#3b8eea": f"Tried {position} | ",
770776
"#23d18b": f"{proxy} | {output} | ", "#29b2d3": f"{view_stat} "})
771777
else:
772778
error += 1
@@ -788,10 +794,10 @@ def main_viewer(proxy_type, proxy, position):
788794
video_len = video_len*uniform(minimum, maximum)
789795

790796
duration = strftime("%Hh:%Mm:%Ss", gmtime(video_len))
791-
print(timestamp() + bcolors.OKBLUE + f"Tried {position+1} | " + bcolors.OKGREEN +
797+
print(timestamp() + bcolors.OKBLUE + f"Tried {position} | " + bcolors.OKGREEN +
792798
f"{proxy} --> {youtube} Found : {output} | Watch Duration : {duration} " + bcolors.ENDC)
793799

794-
create_html({"#3b8eea": f"Tried {position+1} | ",
800+
create_html({"#3b8eea": f"Tried {position} | ",
795801
"#23d18b": f"{proxy} --> {youtube} Found : {output} | Watch Duration : {duration} "})
796802

797803
loop = int(video_len/4)
@@ -820,70 +826,85 @@ def main_viewer(proxy_type, proxy, position):
820826

821827
except UrlsError:
822828
print(timestamp() + bcolors.FAIL +
823-
f"Tried {position+1} | Your urls.txt is empty!" + bcolors.ENDC)
829+
f"Tried {position} | Your urls.txt is empty!" + bcolors.ENDC)
824830

825831
create_html(
826-
{"#f14c4c": f"Tried {position+1} | Your urls.txt is empty!"})
832+
{"#f14c4c": f"Tried {position} | Your urls.txt is empty!"})
827833

828834
status = 400
829835
pass
830836

831837
except SearchError:
832838
print(timestamp() + bcolors.FAIL +
833-
f"Tried {position+1} | Your search.txt is empty!" + bcolors.ENDC)
839+
f"Tried {position} | Your search.txt is empty!" + bcolors.ENDC)
834840

835841
create_html(
836-
{"#f14c4c": f"Tried {position+1} | Your search.txt is empty!"})
842+
{"#f14c4c": f"Tried {position} | Your search.txt is empty!"})
837843

838844
status = 400
839845
pass
840846

841847
except CaptchaError:
842848
print(timestamp() + bcolors.FAIL +
843-
f"Tried {position+1} | Slow internet speed or Stuck at recaptcha! Can't load YouTube..." + bcolors.ENDC)
849+
f"Tried {position} | Slow internet speed or Stuck at recaptcha! Can't load YouTube..." + bcolors.ENDC)
844850

845851
create_html(
846-
{"#f14c4c": f"Tried {position+1} | Slow internet speed or Stuck at recaptcha! Can't load YouTube..."})
852+
{"#f14c4c": f"Tried {position} | Slow internet speed or Stuck at recaptcha! Can't load YouTube..."})
847853

848854
status = quit_driver(driver, pluginfile)
849855
pass
850856

851857
except QueryError:
852858
print(timestamp() + bcolors.FAIL +
853-
f"Tried {position+1} | Can't find this [{video_title}] video with this keyword [{keyword}]" + bcolors.ENDC)
859+
f"Tried {position} | Can't find this [{video_title}] video with this keyword [{keyword}]" + bcolors.ENDC)
854860

855861
create_html(
856-
{"#f14c4c": f"Tried {position+1} | Can't find this [{video_title}] video with this keyword [{keyword}]"})
862+
{"#f14c4c": f"Tried {position} | Can't find this [{video_title}] video with this keyword [{keyword}]"})
857863

858864
status = quit_driver(driver, pluginfile)
859865
pass
860866

861867
except Exception as e:
862868
*_, exc_tb = sys.exc_info()
863869
print(timestamp() + bcolors.FAIL +
864-
f"Tried {position+1} | Line : {exc_tb.tb_lineno} | " + str(e) + bcolors.ENDC)
870+
f"Tried {position} | Line : {exc_tb.tb_lineno} | " + str(e) + bcolors.ENDC)
865871

866872
create_html(
867-
{"#f14c4c": f"Tried {position+1} | Line : {exc_tb.tb_lineno} | " + str(e)})
873+
{"#f14c4c": f"Tried {position} | Line : {exc_tb.tb_lineno} | " + str(e)})
868874

869875
status = quit_driver(driver, pluginfile)
870876
pass
871877

872878
except:
873-
print(timestamp() + bcolors.OKBLUE + f"Tried {position+1} | " +
879+
print(timestamp() + bcolors.OKBLUE + f"Tried {position} | " +
874880
bcolors.FAIL + f"{proxy} | {proxy_type} --> Bad proxy " + bcolors.ENDC)
875881

876-
create_html({"#3b8eea": f"Tried {position+1} | ",
882+
create_html({"#3b8eea": f"Tried {position} | ",
877883
"#f14c4c": f"{proxy} | {proxy_type} --> Bad proxy "})
878884

879885
checked[position] = proxy_type
880886
pass
881887

882888

883889
def view_video(position):
890+
global completed
884891
global server_running
885892

886-
if position != 0:
893+
if position == 0:
894+
if api and not server_running:
895+
server_running = True
896+
website.start_server(host=host, port=port)
897+
898+
elif position == total_proxies - 1:
899+
if api and server_running:
900+
while completed != total_proxies - 2:
901+
sleep(5)
902+
903+
completed = -2
904+
server_running = False
905+
requests.post(f'http://127.0.0.1:{port}/shutdown')
906+
907+
else:
887908
proxy = proxy_list[position]
888909

889910
if proxy_type:
@@ -895,13 +916,9 @@ def view_video(position):
895916
if checked[position] == 'socks4':
896917
main_viewer('socks5', proxy, position)
897918

898-
else:
899-
if api and not server_running:
900-
server_running = True
901-
website.start_server(host=host, port=port)
902-
903919

904920
def main():
921+
global completed
905922
pool_number = [i for i in range(total_proxies)]
906923

907924
with ThreadPoolExecutor(max_workers=threads) as executor:
@@ -910,6 +927,7 @@ def main():
910927

911928
try:
912929
for future in as_completed(futures):
930+
completed += 1
913931
if len(view) == views:
914932
print(
915933
bcolors.WARNING + f'Amount of views added : {views} | Stopping program...' + bcolors.ENDC)
@@ -983,6 +1001,11 @@ def main():
9831001
print(bcolors.OKCYAN +
9841002
f'Total proxies : {total_proxies}' + bcolors.ENDC)
9851003

1004+
proxy_list.insert(0, 'dummy')
1005+
proxy_list.append('dummy')
1006+
1007+
total_proxies += 2
1008+
9861009
check = -1
9871010
while len(view) < views:
9881011
try:
@@ -993,8 +1016,6 @@ def main():
9931016
sleeping()
9941017
print(bcolors.WARNING +
9951018
f'Total Checked : {check} times' + bcolors.ENDC)
996-
if api:
997-
threads -= 1
9981019
main()
9991020
except KeyboardInterrupt:
10001021
sys.exit()

0 commit comments

Comments
 (0)