forked from platipus9999/Tiktok-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
277 lines (197 loc) · 10.7 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
from os import system, name as os_name, get_terminal_size
system('title Tiktok Zefoy Bot ~ Using Selenium ▏ Status: Loading [Heavy Package]' if os_name == 'nt' else '')
from re import findall
from requests import post, get
from io import BytesIO
from enchant import Dict
from base64 import b64decode, b64encode
from time import sleep
from ctypes import windll
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from undetected_chromedriver import ChromeOptions, Chrome
from PIL import ImageGrab, Image
from threading import Thread
class Zefoy:
def __init__(self) -> None:
self.captcha_box = '/html/body/div[5]/div[2]/form/div/div'
self.captcha_res = '/html/body/div[5]/div[2]/form/div/div/div/input'
self.captcha_button = '/html/body/div[5]/div[2]/form/div/div/div/div/button'
self.video_url_box = '/html/body/div[-]/div/form/div/input'
self.search_box = '/html/body/div[-]/div/form/div/div/button'
self.sent = 0
self.paths = {
1 : ('/html/body/div[6]/div/div[2]/div/div/div[2]/div/button', 'c2VuZF9mb2xsb3dlcnNfdGlrdG9r'),
2 : ('/html/body/div[6]/div/div[2]/div/div/div[3]/div/button', 'c2VuZE9nb2xsb3dlcnNfdGlrdG9r'),
3 : ('/html/body/div[6]/div/div[2]/div/div/div[4]/div/button', 'c2VuZC9mb2xsb3dlcnNfdGlrdG9r'),
4 : ('/html/body/div[6]/div/div[2]/div/div/div[5]/div/button', 'c2VuZC9mb2xeb3dlcnNfdGlrdG9V'),
5 : ('/html/body/div[6]/div/div[2]/div/div/div[6]/div/button', 'c2VuZC9mb2xsb3dlcnNfdGlrdG9s'),
6 : ('/html/body/div[6]/div/div[2]/div/div/div[7]/div/button', 'c2VuZF9mb2xsb3dlcnNfdGlrdG9L')
}
self.banner = """
███████╗███████╗███████╗ ██████╗ ██╗ ██╗
╚══███╔╝██╔════╝██╔════╝██╔═══██╗╚██╗ ██╔╝
███╔╝ █████╗ █████╗ ██║ ██║ ╚████╔╝
███╔╝ ██╔══╝ ██╔══╝ ██║ ██║ ╚██╔╝
███████╗███████╗██║ ╚██████╔╝ ██║
╚══════╝╚══════╝╚═╝ ╚═════╝ ╚═╝
"""
def clear(self) -> int:
return system('cls' if os_name == 'nt' else 'clear')
def title(self, content: str) -> int:
return system(f'title {content}') if os_name == 'nt' else windll.kernel32.SetConsoleTitleW(content)
def _print(self, thing: str or int, content: str or int, new_line: bool = True, input: bool = False) -> None or str:
print('\033[?25l', end='')
size = get_terminal_size().columns - 10
col = "\033[38;2;0;-;255m"
first_part = f"[{thing}] | {content}"
new_part = ""
counter = 0
for caracter in first_part:
new_part += col.replace('-', str(225 - counter * int(255/len(first_part)))) + caracter
counter += 1
if input:
return f"{new_part}"
if not new_line:
print(f"{new_part}{' '*(size - len(first_part))}\033[38;2;255;255;255m", end="\r")
else:
print(f"{new_part}{' '*(size - len(first_part))}\033[38;2;255;255;255m")
def display_banner(self) -> str:
first_color, second_color = '\033[38;2;170;180;255m', '\033[38;2;255;255;255m'
display_banner = ""
for caracter in self.banner:
if caracter in ['╚', '═', '╝', '╔', '║', '╗']:
display_banner += second_color + caracter
elif caracter in ' ':
display_banner += caracter
else:
display_banner += first_color + caracter
return display_banner + f'\n {second_color}Plati ~ discord.gg/onplx\n'
def setup_driver(self) -> Chrome:
return Chrome(ChromeOptions().add_argument('detach'))
def convert(self, minutes: int, seconds: int) -> int:
return minutes * 60 + seconds + 3
def get_stats(self, video_id: str) -> list:
res = get(f'https://tikstats.io/video/{video_id}').text
return findall(r'\d+', findall(r'.innerText=(.*), 1' , res)[0])
def display_stats(self, video_id: str) -> None:
print(self.display_banner())
while True:
try:
sleep(1)
views, shares, likes, comments, saves = self.get_stats(video_id)
self._print('➕', f'Stats: [Views: {views} | Shares: {shares} | Likes: {likes} | Comments: {comments} | Saves: {saves}]', new_line=False)
except: continue
def get_id(self, video_url: str) -> str:
return video_url.split('?')[0].split('/')[-1]
def wait_for_path(self, xpath: str) -> WebElement:
while True:
try: return self.driver.find_element(By.XPATH, xpath)
except: continue
def load_zefoy(self) -> None:
self.driver = self.setup_driver()
self.driver.set_window_size(500, 800)
sleep(2)
self.driver.execute_script('window.open("https://zefoy.com");')
#self.driver.get('https://zefoy.com')
res = ''
while not 'Enter the word' in res:
with BytesIO() as bytes_array:
ImageGrab.grab().save(bytes_array, format='PNG')
res = post('https://platipus9999.pythonanywhere.com', json={'image': b64encode(bytes_array.getvalue()).decode()}).text
self.driver.close()
self.driver.switch_to.window(self.driver.window_handles[0])
def solve(self) -> None:
image_xpath = self.captcha_box + '/img'
failed = False
while True:
if failed:
image_xpath, self.captcha_res, self.captcha_button = f"{image_xpath}:{self.captcha_res}:{self.captcha_button}".replace('5', '6').split(':')
img = self.wait_for_path(image_xpath).screenshot_as_base64
captcha_answer = post('https://platipus9999.pythonanywhere.com', json={'image': img}).text.split('\n')[0]
self._print('!', f'{captcha_answer}')
try:
if not Dict("en_US").check(captcha_answer):
captcha_answer = Dict("en_US").suggest(captcha_answer)[0]
self._print('!', f'Trying {captcha_answer}')
except: pass
self.driver.find_element(By.XPATH, self.captcha_res).send_keys(captcha_answer)
self.driver.find_element(By.XPATH, self.captcha_button).click()
try:
sleep(1)
self.driver.find_element(By.XPATH, self.paths[4][0])
break
except:
self.wait_for_path('//*[@id="errorcapthcaclose"]/div/div/div[3]/button').click()
failed = True
def choice_service(self) -> None:
display_dict = {
True : '✅',
False : '❌'
}
print(self.display_banner())
for number, xpath in self.paths.items():
is_enabled = self.driver.find_element(By.XPATH, xpath[0]).is_enabled()
name = self.driver.find_element(By.XPATH, xpath[0].replace('button', 'h5')).text
self._print(number, f'{name}{" " * (len("Comments Hearts ") - len(name))} | Status: {display_dict[is_enabled]}')
print()
self.choice = int(input(self._print('?', 'Choice a service > ', input=True)))
def wait(self, seconds: int) -> None:
for second in range(seconds):
self.title(f'Tiktok Zefoy Bot ~ Using Selenium ▏ Sent: {self.sent} ▏ Cooldown: {seconds - (second + 1)}')
sleep(1)
def get_jsfunc(self, xpath: str) -> str:
return "function find_element(path) {return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } find_element('" + xpath + "').click();"
def task(self) -> None:
self.driver.execute_script(self.get_jsfunc(self.search_box.replace('-', f'{self.div}')))
sleep(3)
seconds = self.check_submit()
if type(seconds) == int:
self.wait(seconds)
sleep(2)
self.driver.execute_script(self.get_jsfunc(self.search_box.replace('-', f'{self.div}')))
sleep(2)
self.driver.execute_script(self.get_jsfunc(f'//*[@id="{self.paths[self.choice][1]}"]/div[1]/div/form/button'))
while True:
source = self.driver.page_source
if 'sent' in source:
self.sent += 1
self.title(f'Tiktok Zefoy Bot ~ Using Selenium ▏ Sent: {self.sent} ▏ Cooldown: 0')
break
if 'Too many requests' in source:
sleep(3)
break
def check_submit(self):
try:
timer_response = self.driver.find_element(By.XPATH, f'//*[@id="{self.paths[self.choice][1]}"]/span').text
if 'READY' in timer_response:
return True
elif "seconds for your next submit" in timer_response:
minutes, seconds = findall(r'\d+', timer_response)
return self.convert(int(minutes), int(seconds))
except:
return False
def main(self) -> None:
self.clear()
print(self.display_banner())
self.title('Tiktok Zefoy Bot ~ Using Selenium ▏ Status: Loading')
video_url = input(self._print('?', 'Video Url > ', input=True))
video_id = self.get_id(video_url)
self._print('!', 'Browser is loading\n')
self.load_zefoy()
self.wait_for_path(self.captcha_box)
self.title('Tiktok Zefoy Bot ~ Using Selenium ▏ Status: Solving')
self._print('*', 'Solving The Captcha')
self.solve()
self.clear()
self.title('Tiktok Zefoy Bot ~ Using Selenium ▏ Status: N/A')
self.choice_service()
self.driver.find_element(By.XPATH, self.paths[self.choice][0]).click()
self.div = int(findall(r'\d+', self.paths[self.choice][0])[-1]) + 5
self.clear()
Thread(target = self.display_stats, args = [video_id,]).start()
self.driver.find_element(By.XPATH, self.video_url_box.replace('-', f'{self.div}')).send_keys(video_url)
while True:
self.task()
if __name__ == '__main__':
Zefoy().main()