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