from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from colorama import Fore
from pystyle import Center, Colors, Colorate
import os
import time


program = True
ProxyCount = 0

def proxy_checker():
    global ProxyCount
    ProxyCount += 1
    print(Colorate.Vertical(Colors.cyan_to_blue, Center.XCenter(f"Viewer {ProxyCount} Sent")))
    time.sleep(1)



def start():

    chrome_path = 'chrome-win64/chrome.exe'
    driver_path = 'chromedriver.exe'

    vodclip = input(Colorate.Vertical(Colors.green_to_blue, Center.XCenter ("Enter vod or clip: ")))
    print()
    twitch_clip_id = input(Colorate.Vertical(Colors.green_to_blue, Center.XCenter ("Enter your Vod/Clip id: ")))
    print()
    twitch_user_name = input(Colorate.Vertical(Colors.green_to_blue, Center.XCenter("Enter your username: ")))
    print()

    proxy_count = int(input(Colorate.Vertical(Colors.cyan_to_blue, Center.XCenter ("How many Clip/Vod Views do you want to open?: "))))


    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--disable-logging')
    chrome_options.add_argument('--log-level=3')
    chrome_options.add_argument('--disable-extensions')
    chrome_options.add_argument("--mute-audio")
    chrome_options.add_argument("--hardware-acceleration-enabled")
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_argument('--headless=new')
    user_agents = [
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36",
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0"
    ]
    chrome_options.add_argument(f'user-agent={random.choice(user_agents)}')
    driver = webdriver.Chrome(options=chrome_options)

    driver.get('https://www.blockaway.net')

    text_box = driver.find_element(By.ID, 'url')


    text_box.send_keys(f'www.twitch.tv/{twitch_user_name}/{vodclip}/{twitch_clip_id}')


    text_box.send_keys(Keys.RETURN)

    time.sleep(15)
    proxy_checker()
    for i in range(proxy_count):
        driver.execute_script("window.open('https://www.blockaway.net/')")
        driver.switch_to.window(driver.window_handles[-1])
        text_box = driver.find_element(By.ID, 'url')
        text_box.send_keys(f'www.twitch.tv/{twitch_user_name}/{vodclip}/{twitch_clip_id}')
        text_box.send_keys(Keys.RETURN)
        proxy_checker()
        time.sleep(30)

    print(Colorate.Vertical(Colors.blue_to_cyan, Center.XCenter("---------------------------------------------------")))
    print(Colorate.Horizontal(Colors.red_to_blue, Center.XCenter("Viewers have all been sent.")))
    print(Colorate.Horizontal(Colors.red_to_blue, Center.XCenter("Press enter to continue.")))
    print(Colorate.Vertical(Colors.blue_to_cyan, Center.XCenter("---------------------------------------------------")))
    QUIT = input(Colorate.Vertical(Colors.cyan_to_blue, Center.XCenter("Type Quit to close program: ")))
    print(Colorate.Vertical(Colors.blue_to_cyan, Center.XCenter("---------------------------------------------------")))
    if QUIT == "Quit":
        program = False
    else:
        print(Colorate.Diagonal(Colors.red, Center.XCenter("...")))
while program:
    start() 
    
    COnvertis en multi thread