Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
xtekky
GitHub Repository: xtekky/tiktok-viewbot
Path: blob/main/old/v3/main.py
619 views
1
# xtekky @ 2022
2
3
from re import findall, compile
4
from time import time, sleep
5
from json import loads
6
from random import random, choices
7
from base64 import b64encode, b64decode
8
from requests import Session, get, head, post
9
from urllib.parse import unquote
10
from pystyle import *
11
from os import system, name, execv
12
from sys import executable, argv
13
from hashlib import sha256
14
from threading import Thread
15
from PIL import Image
16
from io import BytesIO
17
18
config = {
19
'cloudflare': 'kAMtbsTqP9nr2zH.dUqsGIlq60hFfRCsoy1WX.bPhiE-1669637072-0-150',
20
'mode' : 'views'
21
}
22
23
item_id = None
24
proxies = None # experimental
25
26
endpoints = {
27
"views" : "c2VuZC9mb2xeb3dlcnNfdGlrdG9V",
28
"hearts" : "c2VuZE9nb2xsb3dlcnNfdGlrdG9r",
29
"followers" : "c2VuZF9mb2xsb3dlcnNfdGlrdG9r",
30
"favorites" : "c2VuZF9mb2xsb3dlcnNfdGlrdG9L",
31
"shares" : "c2VuZC9mb2xsb3dlcnNfdGlrdG9s",
32
}
33
34
__keys__ = {
35
'key_1': None,
36
'key_2': None
37
}
38
39
class livecounts:
40
41
@staticmethod
42
def video_info(video_id: (int or str)) -> dict:
43
44
headers = {
45
'authority' : 'tiktok.livecounts.io',
46
'origin' : 'https://livecounts.io',
47
'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',
48
}
49
50
req = get(f'https://tiktok.livecounts.io/video/stats/{video_id}', headers=headers)
51
52
return req.json()
53
54
@staticmethod
55
def link_to_id(video_link: (int or str)) -> str:
56
return str(
57
findall(r"(\d{18,19})", video_link)[0] if len(findall(r"(\d{18,19})", video_link)) == 1
58
else findall(r"(\d{18,19})", head(video_link, allow_redirects=True, timeout=5).url)[0]
59
)
60
61
def __decrypt__(data: str) -> str:
62
# print(data)
63
a = unquote(data[::-1])
64
65
return b64decode(a).decode()
66
67
def __sprint__(x: str, num: int, msg: str, colour: str = Col.purple) -> None:
68
return ' %s{%s%s%s}%s %s %s[%s%s%s]%s' % (
69
colour, Col.reset,
70
x,
71
colour, Col.reset,
72
num,
73
colour, Col.blue,
74
msg,
75
colour, Col.reset
76
)
77
78
def __format__(string: str) -> str:
79
t = ""
80
81
for i in string:
82
if i in t : pass
83
else : t = t + i
84
85
return t
86
87
def __init__(__session__: Session) -> tuple:
88
__html__ = str(__session__.get('http://zefoy.com').text).replace('&', '&')
89
90
captcha_token = None
91
results = findall(r'name="([A-Za-z0-9]{31,32})">', __html__)
92
if results:
93
captcha_token = results[0]
94
95
captcha_url = findall(r'img src="([^"]*)"', __html__)[0]
96
sessid = __session__.cookies.get('PHPSESSID')
97
98
return captcha_token, captcha_url, sessid
99
100
def __solve__(__session__: Session, captcha_token: str, captcha_url: str) -> True or False:
101
try:
102
captcha_image = __session__.get('https://zefoy.com' + captcha_url).content
103
response = __session__.post('https://captcha.xtekky.repl.co/', json = {
104
'captcha': b64encode(captcha_image).decode('utf-8'),
105
})
106
107
if response.json()['status_code'] == 0:
108
captcha_answer = __format__(response.json()['captcha_answer'])
109
110
else:
111
print(' ' + __sprint__('x', 'error -', 'need manual solving'))
112
image = Image.open(BytesIO(captcha_image))
113
image.show()
114
captcha_answer = input(' ' + __sprint__('?', 'input -', 'captcha') + ' > '); print('\n')
115
116
response = __session__.post('https://zefoy.com', data = {
117
"captcha_secure": captcha_answer,
118
captcha_token : ""
119
})
120
121
print(response.text)
122
123
__keys__["key_1"] = findall('(?<=")[a-z0-9]{16}', response.text)[0]
124
125
return True
126
127
except Exception as e:
128
129
print(' ' + __sprint__('x', 'error -', str(e)))
130
__solve__(__session__, captcha_token, captcha_url)
131
132
def __search__(__session__: Session, __tiktok_link: str) -> None:
133
try:
134
135
req_token = ''.join(choices('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', k=16))
136
sessionid = __session__.cookies.get('PHPSESSID')
137
token = __keys__["key_1"]
138
139
headers = {
140
'authority': 'zefoy.com',
141
'accept': '*/*',
142
'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
143
'content-type': f'multipart/form-data; boundary=----WebKitFormBoundary{req_token}',
144
'cookie': f'PHPSESSID={sessionid}',
145
'origin': 'https://zefoy.com',
146
'sec-ch-ua': '"Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"',
147
'sec-ch-ua-mobile': '?0',
148
'sec-ch-ua-platform': '"Windows"',
149
'sec-fetch-dest': 'empty',
150
'sec-fetch-mode': 'cors',
151
'sec-fetch-site': 'same-origin',
152
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
153
'x-requested-with': 'XMLHttpRequest',
154
}
155
156
data = f'------WebKitFormBoundary{req_token}\r\nContent-Disposition: form-data; name="{token}"\r\n\r\nhttps://www.tiktok.com/@ninia355/video/7183719544077225222\r\n------WebKitFormBoundary{req_token}--\r\n'
157
158
__search_link = post(f'https://zefoy.com/{endpoints[config["mode"]]}', headers=headers, data=data)
159
160
__search_link_response = __decrypt__(__search_link.content)
161
162
if "Session expired. Please re-login." in __search_link_response:
163
print(' ' + __sprint__('x', 'error -', 'session expired input your own sessionid'))
164
__session__.cookies['PHPSESSID'] = input(' ' + __sprint__('?', 'input -', 'sessionid') + ' > '); print('\n')
165
__search__(__session__, __tiktok_link)
166
167
if 'Please try again later. Server too busy' in __search_link_response or 'currently not working' in __search_link_response:
168
print(' ' + __sprint__('x', 'error -', 'server busy / or currently disabled'))
169
sleep(60)
170
__search__(__tiktok_link)
171
172
__keys__['key_2'], _= findall(r'name="(.*)" value="(.*)" hidden', __search_link_response)[0]
173
174
except Exception as e:
175
try:
176
timer = findall(r'ltm=(\d*);', __search_link_response)[0]
177
if int(timer) == 0:
178
return
179
180
print(' ' + __sprint__('*', 'sleeping -', 'for ' + Col.white + str(timer) + Col.blue +' seconds'), end="\r")
181
182
start = time()
183
while time() < start + int(timer):
184
time_left = str(round((start + int(timer)) - time()))
185
186
if len(time_left) == 2:
187
time_left = time_left + ' '
188
if len(time_left) == 1:
189
time_left = time_left + ' '
190
191
print(' ' + __sprint__('*', 'sleeping -', 'for ' + Col.white + time_left + Col.blue +' seconds'), end="\r"); sleep(1)
192
print(' ' + __sprint__('*', 'sending -', f'{config["mode"]}... '), end="\r")
193
print('')
194
__search__(__session__, __tiktok_link)
195
196
except Exception as e:
197
print(' ' + __sprint__('x', 'error -', str(e)))
198
input(' ' + __sprint__('*', 'restart -', 'press ' + Col.white + 'enter'))
199
execv(executable, ['python'] + argv)
200
201
def __send__(__session__: Session) -> None:
202
203
headers = {
204
'authority' : 'zefoy.com',
205
'accept' : '*/*',
206
'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
207
'content-type' : 'multipart/form-data; boundary=----WebKitFormBoundary',
208
'origin' : 'https://zefoy.com',
209
'sec-ch-ua' : '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
210
'sec-ch-ua-mobile' : '?0',
211
'sec-ch-ua-platform': '"Windows"',
212
'sec-fetch-dest' : 'empty',
213
'sec-fetch-mode' : 'cors',
214
'sec-fetch-site' : 'same-origin',
215
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
216
'x-requested-with' : 'XMLHttpRequest',
217
}
218
219
__send_req = post(f'https://zefoy.com/{endpoints[config["mode"]]}', headers = headers,
220
data = f'------WebKitFormBoundary\r\nContent-Disposition: form-data; name="{__keys__["key_2"]}"\r\n\r\n{item_id}\r\n------WebKitFormBoundary--\r\n',
221
cookies = {
222
# 'cf_clearance': config["cloudflare"],
223
'PHPSESSID' : __session__.cookies.get_dict()["PHPSESSID"]
224
})
225
226
# print(__decrypt__(__send_req.content))
227
228
print(' ' + __sprint__('*', 'success -', 'sent ' + Col.white + config['mode'] + Col.blue + ' !'))
229
sleep(5)
230
231
if __name__ == '__main__':
232
with Session() as __session__:
233
# __session__.cookies.set('cf_clearance', config['cloudflare'])
234
__session__.headers.update({
235
'authority' : 'zefoy.com',
236
# 'accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
237
'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
238
'cp-extension-installed': 'Yes',
239
'sec-ch-ua' : '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
240
'sec-ch-ua-mobile' : '?0',
241
'sec-ch-ua-platform' : '"Windows"',
242
'sec-fetch-dest' : 'document',
243
'sec-fetch-mode' : 'navigate',
244
'sec-fetch-site' : 'none',
245
'sec-fetch-user' : '?1',
246
'upgrade-insecure-requests' : '1',
247
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
248
'x-requested-with' : 'XMLHttpRequest',
249
})
250
251
# print(__session__.headers)
252
a, b, c = __init__(__session__)
253
254
__start = time()
255
256
if __solve__(__session__, a, b) == True:
257
print(' ' + __sprint__('*', 'success -', f'solved captcha: {Col.white}{round(time() - __start, 1)}{Col.blue}s'))
258
video_link = input(' ' + __sprint__('?', 'input -', 'video link') + ' > '); print('\n')
259
260
item_id = livecounts.link_to_id(video_link)
261
# Thread(target=__title_loop).start()
262
# print(__keys__)
263
# sleep(4)
264
while True:
265
__search__(__session__, video_link); sleep(0.5)
266
__send__(__session__); sleep(1)
267
268
else:
269
print(' ' + __sprint__('x', 'error -', 'failed to solve captcha'))
270
input(' ' + __sprint__('*', 'restart -', 'press ' + Col.white + 'enter'))
271
execv(executable, ['python'] + argv)
272