forked from Armanihub/Youtube-Fast-View-Bot
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathview.py
95 lines (78 loc) · 3.14 KB
/
view.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import time
import random
from fake_useragent import UserAgent
from selenium_stealth import stealth
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
def get_random_user_agent():
"""Generate a random user agent."""
ua = UserAgent()
return ua.random
def create_driver(proxy=None):
"""Create a WebDriver instance with stealth settings and optional proxy."""
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument(f"--user-agent={get_random_user_agent()}")
options.add_argument('--headless') # Run Chrome in headless mode (remove to see the window)
if proxy:
options.add_argument(f'--proxy-server=http://{proxy}')
driver = webdriver.Chrome(options=options)
# Apply stealth mode to bypass detection
stealth(driver,
languages=["en-US", "en"],
vendor="Google Inc.",
platform="Win32",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True)
return driver
def load_session(url, proxy=None):
"""Load a YouTube session using the specified proxy."""
try:
driver = create_driver(proxy)
print(f"Opening YouTube URL with proxy: {proxy if proxy else 'No proxy'}")
driver.get(url)
# Simulate human-like actions with random sleep time
action = ActionChains(driver)
action.move_by_offset(0, 100).click().perform() # Simulate scrolling
time.sleep(random.uniform(10, 30)) # Simulate watching the video
print("Session completed successfully.")
driver.quit()
except Exception as e:
print(f"Error occurred with proxy {proxy if proxy else 'No proxy'}: {e}")
def load_proxies(file_path):
"""Load proxies from a file."""
try:
with open(file_path, 'r') as file:
proxies = [line.strip() for line in file if line.strip()]
if not proxies:
print("No proxies found in the file.")
return []
return proxies
except FileNotFoundError:
print(f"Proxy file not found: {file_path}")
return []
if __name__ == "__main__":
# Inputs from the user
youtube_url = input("Enter YouTube URL: ").strip()
refresh_rate = float(input("Enter refresh rate (seconds): ").strip())
view_count = int(input("Enter number of views: ").strip())
# Load proxies from the file
proxy_file = './proxies.txt'
proxies = load_proxies(proxy_file)
use_proxies = bool(proxies)
if use_proxies:
print(f"Loaded {len(proxies)} proxies.")
else:
print("No proxies available. Proceeding without proxies.")
# Start sessions
print("Starting YouTube view automation...")
counter = 0
while counter < view_count:
proxy = random.choice(proxies) if use_proxies else None
load_session(youtube_url, proxy)
counter += 1
time.sleep(refresh_rate)
print(f"Completed {view_count} views.")