Skip to content

Commit

Permalink
important bug fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MShawon committed Feb 27, 2022
1 parent 7b8805f commit a0fea73
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 39 deletions.
44 changes: 30 additions & 14 deletions proxy_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import concurrent.futures.thread
import os
import shutil
import sys
from concurrent.futures import ThreadPoolExecutor, as_completed
from glob import glob

import requests
from fake_headers import Headers
Expand Down Expand Up @@ -61,32 +63,44 @@ class bcolors:
[ GitHub : https://github.com/MShawon/YouTube-Viewer ]
""" + bcolors.ENDC)

'''
Backup previous checked goodproxies
'''

try:
os.remove('ProxyBackup.txt')
except:
pass

try:
shutil.copy('GoodProxy.txt', 'ProxyBackup.txt')
print(bcolors.WARNING + 'GoodProxy backed up in ProxyBackup' + bcolors.ENDC)
print(bcolors.WARNING + 'GoodProxy.txt backed up in ProxyBackup.txt' + bcolors.ENDC)
os.remove('GoodProxy.txt')
except:
pass

checked = {}


def clean_exe_temp(folder):
try:
temp_name = sys._MEIPASS.split('\\')[-1]
except:
temp_name = None

for f in glob(os.path.join('temp', folder, '*')):
if temp_name not in f:
shutil.rmtree(f, ignore_errors=True)


def load_proxy():
proxies = []

filename = input(bcolors.OKBLUE +
'Enter your proxy file name: ' + bcolors.ENDC)
load = open(filename)
loaded = [items.rstrip().strip() for items in load]
load.close()

if not os.path.isfile(filename) and filename[-4:] != '.txt':
filename = f'{filename}.txt'

with open(filename, encoding="utf-8") as fh:
loaded = [x.strip() for x in fh if x.strip() != '']

for lines in loaded:
if lines.count(':') == 3:
Expand All @@ -97,7 +111,7 @@ def load_proxy():
return proxies


def mainChecker(proxy_type, proxy, position):
def main_checker(proxy_type, proxy, position):

checked[position] = None

Expand Down Expand Up @@ -131,27 +145,27 @@ def mainChecker(proxy_type, proxy, position):

except:
print(bcolors.OKBLUE + f"Tried {position+1} |" + bcolors.FAIL +
f' {proxy} | {proxy_type} |BAD ' + bcolors.ENDC)
f' {proxy} | {proxy_type} | BAD ' + bcolors.ENDC)
checked[position] = proxy_type
pass


def proxyCheck(position):
def proxy_check(position):

proxy = proxy_list[position]

mainChecker('http', proxy, position)
main_checker('http', proxy, position)
if checked[position] == 'http':
mainChecker('socks4', proxy, position)
main_checker('socks4', proxy, position)
if checked[position] == 'socks4':
mainChecker('socks5', proxy, position)
main_checker('socks5', proxy, position)


def main():
pool_number = [i for i in range(total_proxies)]

with ThreadPoolExecutor(max_workers=threads) as executor:
futures = [executor.submit(proxyCheck, position)
futures = [executor.submit(proxy_check, position)
for position in pool_number]

try:
Expand All @@ -166,6 +180,8 @@ def main():


if __name__ == '__main__':

clean_exe_temp(folder='proxy_check')
threads = int(
input(bcolors.OKBLUE+'Threads (recommended = 100): ' + bcolors.ENDC))

Expand Down
Binary file modified requirements.txt
Binary file not shown.
35 changes: 21 additions & 14 deletions youtube_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@
from undetected_chromedriver.patcher import Patcher

from youtubeviewer import website
from youtubeviewer.basics import *
from youtubeviewer.config import create_config
from youtubeviewer.database import *
from youtubeviewer.download_driver import *
from youtubeviewer.basics import *
from youtubeviewer.load_files import *
from youtubeviewer.proxies import *

log = logging.getLogger('werkzeug')
log.disabled = True

os.system("")

print(bcolors.OKGREEN + """
Expand All @@ -62,7 +61,7 @@
[ GitHub : https://github.com/MShawon/YouTube-Viewer ]
""" + bcolors.ENDC)

SCRIPT_VERSION = '1.7.0'
SCRIPT_VERSION = '1.7.1'

proxy = None
driver = None
Expand Down Expand Up @@ -140,6 +139,17 @@ def timestamp():
return bcolors.OKGREEN + f'[{date_fmt}] '


def clean_exe_temp(folder):
try:
temp_name = sys._MEIPASS.split('\\')[-1]
except:
temp_name = None

for f in glob(os.path.join('temp', folder, '*')):
if temp_name not in f:
shutil.rmtree(f, ignore_errors=True)


def update_chrome_version():
link = 'https://gist.githubusercontent.com/MShawon/29e185038f22e6ac5eac822a1e422e9d/raw/versions.txt'

Expand Down Expand Up @@ -382,17 +392,13 @@ def main_viewer(proxy_type, proxy, position):
if method == 2 and 't.co/' in referer:
driver.get(url)
else:
driver.get(referer)
if 'consent.yahoo.com' in driver.current_url:
try:
consent = driver.find_element(
By.XPATH, "//button[@name='agree']")
driver.execute_script(
"arguments[0].scrollIntoView();", consent)
consent.click()
driver.get(referer)
except:
pass
if 'search.yahoo.com' in referer:
driver.get('https://duckduckgo.com/')
driver.execute_script(
"window.history.pushState('page2', 'Title', arguments[0]);", referer)
else:
driver.get(referer)

driver.execute_script(
"window.location.href = '{}';".format(url))

Expand Down Expand Up @@ -713,6 +719,7 @@ def main():

if __name__ == '__main__':

clean_exe_temp(folder='youtube_viewer')
update_chrome_version()
check_update()
osname, exe_name = download_driver(patched_drivers=patched_drivers)
Expand Down
1 change: 1 addition & 0 deletions youtubeviewer/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def get_driver(background, viewports, agent, auth_required, path, proxy, proxy_t
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-features=UserAgentClientHint')
options.add_argument("--disable-web-security")
webdriver.DesiredCapabilities.CHROME['loggingPrefs'] = {
'driver': 'OFF', 'server': 'OFF', 'browser': 'OFF'}

Expand Down
6 changes: 5 additions & 1 deletion youtubeviewer/colors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import os

os.system("")

class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
Expand All @@ -7,4 +11,4 @@ class bcolors:
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
UNDERLINE = '\033[4m'
10 changes: 5 additions & 5 deletions youtubeviewer/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import json
import os
import sys

from .colors import bcolors
from .colors import *


def create_config(config_path):
Expand Down Expand Up @@ -153,8 +152,11 @@ def create_config(config_path):
input('\nPlease input F for Free, P for Premium and R for Rotating proxy ')
sys.exit()

refresh = -1
refresh = 0.0
if category != 'r':
print(bcolors.WARNING + '\nRefresh interval means after every X minutes, program will reload proxies from your File or API' + bcolors.ENDC)
print(bcolors.WARNING + 'You should use this if and only if there will be new proxies in your File or API after every X minutes.' + bcolors.ENDC)
print(bcolors.WARNING + 'Otherwise just enter 0 as the interval' + bcolors.ENDC)
refresh = float(input(
bcolors.OKCYAN+'\nEnter a interval to reload proxies from File or API (in minute) : ' + bcolors.ENDC))

Expand Down Expand Up @@ -223,6 +225,4 @@ def create_config(config_path):


if __name__ == '__main__':
os.system("")

create_config(config_path='config.json')
5 changes: 2 additions & 3 deletions youtubeviewer/download_driver.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

import os
import platform
import shutil
import subprocess
import sys

import undetected_chromedriver._compat as uc

from .colors import bcolors
from .colors import *

CHROME = ['{8A69D345-D564-463c-AFF1-A69D9E530F96}',
'{8237E44A-0054-442C-B6B6-EA0509993955}',
Expand Down Expand Up @@ -102,4 +101,4 @@ def copy_drivers(cwd, patched_drivers, exe, total):
shutil.copy(current, destination)
except Exception as e:
print(e)
pass
pass
2 changes: 1 addition & 1 deletion youtubeviewer/load_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hashlib

from .colors import bcolors
from .colors import *


def load_url():
Expand Down
5 changes: 4 additions & 1 deletion youtubeviewer/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import requests

from .colors import bcolors
from .colors import *


def gather_proxy():
Expand Down Expand Up @@ -33,6 +33,9 @@ def gather_proxy():
def load_proxy(filename):
proxies = []

if not os.path.isfile(filename) and filename[-4:] != '.txt':
filename = f'{filename}.txt'

with open(filename, encoding="utf-8") as fh:
loaded = [x.strip() for x in fh if x.strip() != '']

Expand Down

0 comments on commit a0fea73

Please sign in to comment.