Skip to content

Commit

Permalink
fixed #404, #406, #409, #413, #432
Browse files Browse the repository at this point in the history
  • Loading branch information
MShawon committed Sep 25, 2022
1 parent 9e9fd35 commit f0fe93d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
Binary file modified requirements.txt
Binary file not shown.
42 changes: 33 additions & 9 deletions youtube_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
log = logging.getLogger('werkzeug')
log.disabled = True

SCRIPT_VERSION = '1.7.4'
SCRIPT_VERSION = '1.7.5'

print(bcolors.OKGREEN + """
Expand Down Expand Up @@ -85,6 +85,7 @@
driver_dict = {}
duration_dict = {}
checked = {}
summary = {}
video_statistics = {}
view = []
bad_proxies = []
Expand All @@ -103,7 +104,9 @@
DATABASE = os.path.join(cwd, 'database.db')
DATABASE_BACKUP = os.path.join(cwd, 'database_backup.db')

headers = ['Index', 'Video Title', 'Views']
animation = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"]
headers_1 = ['Worker', 'Video Title', 'Watch / Actual Duration']
headers_2 = ['Index', 'Video Title', 'Views']

width = 0
viewports = ['2560,1440', '1920,1080', '1440,900',
Expand Down Expand Up @@ -385,9 +388,15 @@ def control_player(driver, output, position, proxy, youtube, collect_id=True):
if video_len == 0:
raise Exception('Video player is not loading...')

actual_duration = strftime(
"%Hh:%Mm:%Ss", gmtime(video_len)).lstrip("0h:0m:")
video_len = video_len*uniform(minimum, maximum)
duration = strftime("%Hh:%Mm:%Ss", gmtime(video_len)).lstrip("0h:0m:")

summary[position] = [position, output, f'{duration} / {actual_duration}']
website.summary_table = tabulate(
summary.values(), headers=headers_1, numalign='center', stralign='center', tablefmt="html")

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

Expand Down Expand Up @@ -435,10 +444,15 @@ def control_player(driver, output, position, proxy, youtube, collect_id=True):
elif current_time > video_len or driver.current_url != current_url:
break

summary.pop(position, None)
website.summary_table = tabulate(
summary.values(), headers=headers_1, numalign='center', stralign='center', tablefmt="html")

output = textwrap.fill(text=output, width=75, break_on_hyphens=False)
video_statistics[output] = video_statistics.get(output, 0) + 1
website.html_table = tabulate(video_statistics.items(), headers=headers,
website.html_table = tabulate(video_statistics.items(), headers=headers_2,
showindex=True, numalign='center', stralign='center', tablefmt="html")

return current_url, current_channel


Expand Down Expand Up @@ -557,11 +571,12 @@ def windows_kill_drivers():
for process in constructor.Win32_Process(["CommandLine", "ProcessId"]):
try:
if 'UserAgentClientHint' in process.CommandLine:
# print(f'Killing PID : {process.ProcessId}')
print(f'Killing PID : {process.ProcessId}', end="\r")
subprocess.Popen(['taskkill', '/F', '/PID', f'{process.ProcessId}'],
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL)
except Exception:
pass
print('\n')


def quit_driver(driver, data_dir):
Expand Down Expand Up @@ -868,7 +883,7 @@ def main():

if loop % 40 == 0:
print(tabulate(video_statistics.items(),
headers=headers, showindex=True, tablefmt="pretty"))
headers=headers_2, showindex=True, tablefmt="pretty"))

if category == 'r' and proxy_api:
proxies_from_api = scrape_api(link=filename)
Expand Down Expand Up @@ -946,9 +961,18 @@ def main():

if len(config) == 11:
print(json.dumps(config, indent=4))
previous = str(input(
bcolors.OKBLUE + 'Config file exists! Do you want to continue with previous saved preferences ? [Yes/No] : ' + bcolors.ENDC)).lower()
if previous == 'n' or previous == 'no':
print(bcolors.OKCYAN + 'Config file exists! Program will start automatically after 20 seconds...' + bcolors.ENDC)
print(bcolors.FAIL + 'If you want to create a new config file PRESS CTRL+C within 20 seconds!' + bcolors.ENDC)
start = time()
try:
i = 0
while i < 96:
print(bcolors.OKBLUE + f"{time() - start:.0f} seconds remaining " +
animation[i % len(animation)] + bcolors.ENDC, end="\r")
i += 1
sleep(0.2)
print('\n')
except KeyboardInterrupt:
create_config(config_path=config_path)
else:
print(bcolors.FAIL + 'Previous config file is not compatible with the latest script! Create a new one...' + bcolors.ENDC)
Expand Down
6 changes: 3 additions & 3 deletions youtubeviewer/bypass.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def personalization(driver):

def bypass_consent(driver):
try:
consent = driver.find_element(By.XPATH, "//button[@jsname='higCR']")
consent = driver.find_element(By.XPATH, "//button[@jsname='b3VHJd']")
driver.execute_script("arguments[0].scrollIntoView();", consent)
consent.click()
consent.submit()
if 'consent' in driver.current_url:
personalization(driver)
except WebDriverException:
consent = driver.find_element(
By.XPATH, "//input[@type='submit' and @value='I agree']")
By.XPATH, "//button[@aria-label='Accept all']")
driver.execute_script("arguments[0].scrollIntoView();", consent)
consent.submit()
if 'consent' in driver.current_url:
Expand Down
2 changes: 1 addition & 1 deletion youtubeviewer/download_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def download_driver(patched_drivers):
if osname == 'Linux':
osname = 'lin'
exe_name = ""
with subprocess.Popen(['google-chrome', '--version'], stdout=subprocess.PIPE) as proc:
with subprocess.Popen(['google-chrome-stable', '--version'], stdout=subprocess.PIPE) as proc:
version = proc.stdout.read().decode('utf-8').replace('Google Chrome', '').strip()
elif osname == 'Darwin':
osname = 'mac'
Expand Down
1 change: 1 addition & 0 deletions youtubeviewer/web/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function queryLogs() {
for (i = 1; i < 201; i++) {
$('#logs-' + i).html(data.console[i - 1]);
}
$('#summary_table').html(data.summary);
$('#video_statistics').html(data.table);
});
}
Expand Down
14 changes: 12 additions & 2 deletions youtubeviewer/web/templates/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,26 @@ <h3>Live Logs</h3>
</div>
</div>

<nav class="navbar navbar-light mx-auto justify-content-center mt-5 bg-dark">
<span class="navbar-brand mb-0 h1 text-white">Summary</span>
</nav>

<table class="table table-striped table-bordered table-hover table-success mx-auto mb-3 mt-3" style="width: 95%"
id="summary_table">

</table>


<nav class="navbar navbar-light mx-auto justify-content-center mt-5 bg-dark" style="width: 95%">
<nav class="navbar navbar-light mx-auto justify-content-center mt-5 bg-dark">
<span class="navbar-brand mb-0 h1 text-white">Statistics</span>
</nav>

<table class="table table-striped table-bordered table-hover table-dark mx-auto mb-3 mt-3" style="width: 95%"
<table class="table table-striped table-bordered table-hover table-success mx-auto mb-3 mt-3" style="width: 95%"
id="video_statistics">

</table>


<div class="container-fluid d-flex justify-content-center mt-3">
<div class="dropdown">
<button class="btn btn-success dropdown-toggle" type="button" id="dropdownMenuButton"
Expand Down
3 changes: 2 additions & 1 deletion youtubeviewer/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'July', 'August', 'September', 'October', 'November', 'December']

console = []
summary_table = ''
html_table = ''
database = 'database.db'

Expand Down Expand Up @@ -132,7 +133,7 @@ def home():

@app.route('/update', methods=['POST'])
def update():
return jsonify({'result': 'success', 'console': console[:200], 'table': html_table[8:-9]})
return jsonify({'result': 'success', 'console': console[:200], 'summary': summary_table[8:-9], 'table': html_table[8:-9]})

@app.route('/graph', methods=['GET', 'POST'])
def graph():
Expand Down

0 comments on commit f0fe93d

Please sign in to comment.