Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
xtekky
GitHub Repository: xtekky/tiktok-viewbot
Path: blob/main/old/v2/main.py
619 views
1
from re import findall, compile
2
from time import time, sleep
3
from json import loads
4
from random import random
5
from base64 import b64encode, b64decode
6
from requests import Session, get, head
7
from urllib.parse import unquote
8
from pystyle import *
9
from os import system, name, execv
10
from sys import executable, argv
11
from hashlib import sha256
12
from threading import Thread
13
from PIL import Image
14
from io import BytesIO
15
16
cf_clearance = "kAMtbsTqP9nr2zH.dUqsGIlq60hFfRCsoy1WX.bPhiE-1669637072-0-150"
17
proxies = None # experimental
18
endpoints = {
19
"views" : "c2VuZC9mb2xsb3dlcnNfdGlrdG9V",
20
"hearts" : "c2VuZE9nb2xsb3dlcnNfdGlrdG9r",
21
"followers" : "c2VuZF9mb2xsb3dlcnNfdGlrdG9r",
22
"favorites" : "c2VuZF9mb2xsb3dlcnNfdGlrdG9L",
23
"shares" : "c2VuZC9mb2xsb3dlcnNfdGlrdG9s",
24
}
25
26
class livecounts:
27
@staticmethod
28
def __signature(timestamp: int) -> dict:
29
30
return {
31
'x-aurora' : str(3 * timestamp),
32
'x-joey' : str(timestamp),
33
'x-maven' : sha256(f"0AVwElhWi1IfwcZKSNzq7E^84hFQ4ykenNAxeY7r@6ho1oTd6Ug*!WC&p$2aGY8MLHEkH0i8XCwnj3#JqI1NzCb91$gNzLYCbbG@NqvQMbcf8W9v3%s#uzjP@z*!e9a41JNWBqRIMJ*ULuav5k8z4kBj2^BCC%!3q@N0zZOS^TL#GzVz@9fhjg&^mSWi&oU5GMoCu9{timestamp}".encode()).hexdigest(),
34
'x-mayhem' : "553246736447566b58312f7a4f72413653425342717a6e4231596f7a4d59686564764842324b396478544443756669734d56706f4346334633456366724b6732",
35
'x-midas' : sha256(str(timestamp + 64).encode()).hexdigest()
36
}
37
38
@staticmethod
39
def video_info(video_id: (int or str)) -> dict:
40
timestamp = int(time() * 1000)
41
42
headers = {
43
**livecounts.__signature(timestamp),
44
'authority' : 'tiktok.livecounts.io',
45
'origin' : 'https://livecounts.io',
46
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
47
}
48
49
req = get(f'https://tiktok.livecounts.io/video/stats/{video_id}', headers=headers)
50
51
return req.json()
52
53
@staticmethod
54
def link_to_id(video_link: (int or str)) -> str:
55
return str(
56
findall(r"(\d{18,19})", video_link)[0] if len(findall(r"(\d{18,19})", video_link)) == 1
57
else findall(r"(\d{18,19})", head(video_link, allow_redirects=True, timeout=5).url)[0]
58
)
59
60
61
class zefoy:
62
def __init__(self, *args, **kwargs) -> None:
63
self.__session = Session(); self.__init_session(); self.__ad_cookies()
64
self.__aweme_id = None
65
self.__item_id = None
66
self.__keys = {
67
'key_1': None,
68
'key_2': None
69
}
70
71
def __title_loop(self):
72
if name == 'nt':
73
while True:
74
stats = livecounts.video_info(self.__item_id)
75
system('title Zefoy Bot by @xtekky ^| Likes: %s Views: %s Shares: %s ^| %s ^| mode: hearts' % (
76
stats['likeCount'], stats['viewCount'], stats['shareCount'], str(self.__item_id)
77
))
78
79
sleep(0.5)
80
81
def __base_headers(self, addon: dict = {}) -> dict:
82
83
return {
84
**addon,
85
"host" : "zefoy.com",
86
"connection" : "keep-alive",
87
"sec-ch-ua" : "\"Chromium\";v=\"106\", \"Google Chrome\";v=\"106\", \"Not;A=Brand\";v=\"99\"",
88
"accept" : "*/*",
89
"x-requested-with" : "XMLHttpRequest",
90
"sec-ch-ua-mobile" : "?0",
91
"user-agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36",
92
"sec-ch-ua-platform" : "\"Windows\"",
93
"origin" : "https://zefoy.com",
94
"sec-fetch-site" : "same-origin",
95
"sec-fetch-mode" : "cors",
96
"sec-fetch-dest" : "empty",
97
"accept-language" : "en-US,en;q=0.9",
98
}
99
100
101
def __get_captcha(self) -> str:
102
103
__captcha_image = self.__session.get("https://zefoy.com/a1ef290a2636bf553f39817628b6ca49.php",
104
headers = self.__base_headers(),
105
proxies = proxies,
106
params = {
107
"_CAPTCHA": "",
108
"t": f"{round(random(), 8)} {int(time())}"
109
})
110
111
return str(b64encode(__captcha_image.content).decode())
112
#return __captcha_image.content
113
114
def __solve_captcha(self, __image_data: str or bytes) -> None:
115
response = self.__session.post('https://captcha.xtekky.repl.co/', json = {
116
'captcha': __image_data
117
})
118
119
if response.json()['status_code'] == 0:
120
captcha_answer = response.json()['captcha_answer']
121
122
123
else:
124
print(' ' + zefoy.sprint('x', 'error -', str(response.json())))
125
input(' ' + zefoy.sprint('*', 'restart -', 'press ' + Col.white + 'enter'))
126
execv(executable, ['python'] + argv)
127
128
# image = Image.open(BytesIO(__image_data))
129
# image.show()
130
# captcha_answer = input(' ' + zefoy.sprint('*', 'captcha -', 'enter captcha > '))
131
132
try:
133
response = self.__session.post("https://zefoy.com/",
134
headers = self.__base_headers(),
135
proxies = proxies,
136
data = {
137
"captcha_secure": captcha_answer,
138
"r75619cf53f5a5d7ba6af82edfec3bf0": ""
139
})
140
141
self.__keys["key_1"] = findall('(?<=")[a-z0-9]{16}', response.text)[0]
142
143
return True
144
145
except Exception:
146
return False
147
148
def __init_session(self) -> None:
149
self.__session.cookies.set("cf_clearance", cf_clearance)
150
test = self.__session.get('https://zefoy.com/',
151
proxies = proxies,
152
headers = self.__base_headers()
153
)
154
if test.status_code == 503:
155
print(' ' + zefoy.sprint('x', 'error -', "cloudflare block, replace cf_clearance cookie"))
156
exit()
157
158
def __ad_cookies(self) -> None:
159
160
__ad_cookies = self.__session.get("https://partner.googleadservices.com/gampad/cookie.js",
161
headers = {'host':'partner.googleadservices.com','connection':'keep-alive','sec-ch-ua':'"Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99"','sec-ch-ua-mobile':'?0','user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36','sec-ch-ua-platform':'"Windows"','accept':'*/*','sec-fetch-site':'cross-site','sec-fetch-mode':'no-cors','sec-fetch-dest':'script','accept-encoding':'gzip, deflate, br','accept-language':'en-US,en;q=0.9'},
162
params = {
163
"domain" : "zefoy.com",
164
"callback" : "_gfp_s_",
165
"client" : "ca-pub-3192305768699763",
166
"gpid_exp" : 1
167
})
168
169
__json_data = loads(findall(r'_gfp_s_\((.*)\);', __ad_cookies.text)[0])
170
171
self.__session.cookies.set("_gads", __json_data['_cookies_'][0]['_value_'], domain='zefoy.com')
172
self.__session.cookies.set("__gpi", __json_data['_cookies_'][1]['_value_'], domain='zefoy.com')
173
174
def __zefoy_decrypt(self, data):
175
return b64decode(unquote(data[::-1])).decode()
176
177
def __search_link(self, __tiktok_link: str) -> None:
178
try:
179
180
__search_link = self.__session.post('https://zefoy.com/' + endpoints['hearts'],
181
headers = self.__base_headers(),
182
proxies = proxies,
183
data = {
184
self.__keys['key_1']: __tiktok_link
185
})
186
187
__search_link_response = self.__zefoy_decrypt(__search_link.text)
188
# print(__search_link_response)
189
if 'Please try again later. Server too busy' in __search_link_response or 'currently not working' in __search_link_response:
190
print(' ' + zefoy.sprint('x', 'error -', 'server busy'))
191
sleep(60)
192
self.__search_link(__tiktok_link)
193
194
self.__keys['key_2'], self.__aweme_id = findall(r'name="(.*)" value="(.*)" hidden', __search_link_response)[0]
195
196
except Exception:
197
try:
198
timer = findall(r'ltm=(\d*);', __search_link_response)[0]
199
if int(timer) == 0:
200
return
201
202
print(' ' + zefoy.sprint('*', 'sleeping -', 'for ' + Col.white + str(timer) + Col.blue +' seconds'), end="\r")
203
204
start = time()
205
while time() < start + int(timer):
206
time_left = str(round((start + int(timer)) - time()))
207
208
if len(time_left) == 2:
209
time_left = time_left + ' '
210
if len(time_left) == 1:
211
time_left = time_left + ' '
212
213
print(' ' + zefoy.sprint('*', 'sleeping -', 'for ' + Col.white + time_left + Col.blue +' seconds'), end="\r"); sleep(1)
214
print(' ' + zefoy.sprint('*', 'sending -', 'hearts... '), end="\r")
215
print('')
216
self.__search_link(__tiktok_link)
217
218
except Exception as e:
219
print(' ' + zefoy.sprint('x', 'error -', str(e)))
220
input(' ' + zefoy.sprint('*', 'restart -', 'press ' + Col.white + 'enter'))
221
execv(executable, ['python'] + argv)
222
223
def __send_req(self) -> None:
224
self.__session.post('https://zefoy.com/' + endpoints['hearts'],
225
headers = self.__base_headers(),
226
proxies = proxies,
227
data = {
228
self.__keys['key_2']: self.__aweme_id,
229
})
230
231
print(' ' + zefoy.sprint('*', 'success -', 'sent ' + Col.white + 'hearts' + Col.blue + ' !'))
232
sleep(5)
233
234
def mainloop(self) -> None:
235
__start = time()
236
__captcha_image = self.__get_captcha()
237
238
if self.__solve_captcha(__captcha_image) is True:
239
print(' ' + zefoy.sprint('*', 'success -', f'solved captcha: {Col.white}{round(time() - __start, 1)}{Col.blue}s'))
240
video_link = input(' ' + zefoy.sprint('?', 'input -', 'video link') + ' > '); print('\n')
241
self.__item_id = livecounts.link_to_id(video_link)
242
Thread(target=self.__title_loop).start()
243
244
while True:
245
self.__search_link(video_link); sleep(0.5)
246
self.__send_req(); sleep(1)
247
248
else:
249
print(' ' + zefoy.sprint('x', 'error -', 'failed to solve captcha'))
250
input(' ' + zefoy.sprint('*', 'restart -', 'press ' + Col.white + 'enter'))
251
execv(executable, ['python'] + argv)
252
253
@staticmethod
254
def sprint(x: str, num: int, msg: str) -> None:
255
return ' %s{%s%s%s}%s %s %s[%s%s%s]%s' % (
256
Col.purple, Col.reset,
257
x,
258
Col.purple, Col.reset,
259
num,
260
Col.purple, Col.blue,
261
msg,
262
Col.purple, Col.reset
263
)
264
265
@staticmethod
266
def startup():
267
system('cls' if name == 'nt' else ''); system('title Like Bot by @xtekky ^| starting...')
268
print(Col.purple + Center.XCenter('''\n ______ _______ _______ _____ __ __ ______ _____ _______\n ____/ |______ |______ | | \_/ |_____] | | | \n /_____ |______ | |_____| | |_____] |_____| | \n made with <3 by tekky ''') + Col.reset); print("\n\n")
269
270
if __name__ == "__main__":
271
zefoy.startup()
272
zefoy(None).mainloop()
273
274