Skip to content

Commit

Permalink
resolved issue #256, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MShawon committed Oct 27, 2021
1 parent 5f08c55 commit 4c03191
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
5 changes: 4 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ def create_config():
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 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
61 changes: 30 additions & 31 deletions youtube_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class bcolors:
[ GitHub : https://github.com/MShawon/YouTube-Viewer ]
""" + bcolors.ENDC)

SCRIPT_VERSION = '1.6.1'
SCRIPT_VERSION = '1.6.2'

proxy = None
driver = None
Expand Down Expand Up @@ -132,7 +132,7 @@ class bcolors:
REFERERS = ['https://search.yahoo.com/', 'https://duckduckgo.com/', 'https://www.google.com/',
'https://www.bing.com/', 'https://t.co/', '']

COMMANDS = [Keys.UP, Keys.DOWN, 'k', 'j', 'l', 'm', 't', 'c']
COMMANDS = [Keys.UP, Keys.DOWN, 'k', 'j', 'l', 't', 'c']

website.console = console
website.database = DATABASE
Expand Down Expand Up @@ -336,15 +336,10 @@ def create_html(text_dict):


def load_url():
links = []
print(bcolors.WARNING + 'Loading urls...' + bcolors.ENDC)
filename = 'urls.txt'
load = open(filename)
loaded = [items.rstrip().strip() for items in load]
load.close()

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

print(bcolors.OKGREEN +
f'{len(links)} url loaded from urls.txt' + bcolors.ENDC)
Expand All @@ -353,16 +348,11 @@ def load_url():


def load_search():
search = []
print(bcolors.WARNING + 'Loading queries...' + bcolors.ENDC)
filename = 'search.txt'
load = open(filename, encoding="utf-8")
loaded = [items.rstrip().strip() for items in load]
loaded = [[i.strip() for i in items.split('::::')] for items in loaded]
load.close()

for lines in loaded:
search.append(lines)
with open('search.txt', encoding="utf-8") as fh:
search = [[y.strip() for y in x.strip().split('::::')]
for x in fh if x.strip() != '' and '::::' in x]

print(bcolors.OKGREEN +
f'{len(search)} query loaded from search.txt' + bcolors.ENDC)
Expand All @@ -388,23 +378,28 @@ def gather_proxy():
proxies = proxies + proxy
print(bcolors.OKGREEN +
f'{len(proxy)} proxies gathered from {link}' + bcolors.ENDC)

proxies = list(filter(None, proxies))
shuffle(proxies)

return proxies


def load_proxy(filename):
proxies = []

load = open(filename)
loaded = [items.rstrip().strip() for items in load]
load.close()
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:
split = lines.split(':')
lines = f'{split[2]}:{split[-1]}@{split[0]}:{split[1]}'
proxies.append(lines)

proxies = list(filter(None, proxies))
shuffle(proxies)

return proxies


Expand All @@ -424,6 +419,9 @@ def scrape_api(link):
lines = f'{split[2]}:{split[-1]}@{split[0]}:{split[1]}'
proxies.append(lines)

proxies = list(filter(None, proxies))
shuffle(proxies)

return proxies


Expand Down Expand Up @@ -806,10 +804,11 @@ def random_command(driver):
if command in ['m', 't', 'c']:
driver.find_element_by_id('movie_player').send_keys(command)
elif command == 'k':
driver.find_element_by_id('movie_player').send_keys(command)
if randint(1, 2) == 1:
driver.find_element_by_id('movie_player').send_keys(command)
driver.execute_script(
f'document.querySelector("#comments"){choices(["scrollIntoView", "scrollIntoViewIfNeeded"])}();')
sleep(randint(4, 10))
sleep(uniform(4, 10))
driver.execute_script(
'document.querySelector("#movie_player").scrollIntoViewIfNeeded();')
else:
Expand All @@ -819,15 +818,16 @@ def random_command(driver):

def quit_driver(driver, pluginfile):
try:
os.remove(pluginfile)
driver_list.remove(driver)
except:
pass
driver.quit()

try:
driver_list.remove(driver)
os.remove(pluginfile)
except:
pass
driver.quit()

status = 400
return status

Expand Down Expand Up @@ -908,6 +908,10 @@ def main_viewer(proxy_type, proxy, position):
pluginfile = os.path.join(
'extension', f'proxy_auth_plugin{position}.zip')

factor = int(threads/6)
sleep_time = int((str(position)[-1])) * factor
sleep(sleep_time)

driver = get_driver(patched_driver, agent,
proxy, proxy_type, pluginfile)

Expand Down Expand Up @@ -1230,7 +1234,7 @@ def main():
stop_server()
break

elif category != 'r':
elif refresh != 0:

if (time() - start_time) > refresh*60:

Expand All @@ -1242,9 +1246,6 @@ def main():
else:
proxy_list = gather_proxy()

# removing empty lines
proxy_list = list(filter(None, proxy_list))

print(bcolors.WARNING +
f'Proxy reloaded from : {filename}' + bcolors.ENDC)

Expand Down Expand Up @@ -1347,8 +1348,6 @@ def main():
else:
proxy_list = gather_proxy()

proxy_list = list(filter(None, proxy_list)) # removing empty lines

total_proxies = len(proxy_list)
if category != 'r':
print(bcolors.OKCYAN +
Expand Down

0 comments on commit 4c03191

Please sign in to comment.