This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
api.py
200 lines (174 loc) · 8.36 KB
/
api.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
import time
from time import sleep
import requests
import json
import os.path
from helper import Helper
class Api():
api_url = "https://api2.musical.ly/"
global_variable = {}
active_user = {}
helper = Helper()
def __init__(self):
pass
def login(self, username, password, capthcha=None):
username = self.helper.xor(username)
if os.path.exists(username + '.json'):
with open(username + '.json', encoding='utf-8') as json_file:
load = json.load(json_file)
if load.get('data')['user_id']:
self.active_user = load
return load
password = self.helper.xor(password)
url = self.api_url + "passport/user/login/?" + self.helper.query(
self.helper.default_variable(self.global_variable))
posts = {
'mix_mode': 1,
'username': username,
'password': password,
'email': None,
'mobile': None,
'account': None,
'captcha': capthcha
}
login = self.helper.request_post(url, posts)
print(login.json())
if (login.json().get('data').get('captcha')):
return {'error': 'captcha', 'code': login.json().get('data').get('captcha')}
try:
headers = {}
for c in login.cookies:
headers[c.name] = c.value
except KeyError:
headers = None
success = {}
if (login.status_code != 200):
return login.status_code
else:
data = login.json()
if (data.get('data') and (data.get('error_code') == None)):
success['data'] = self.helper.user_data_export(data.get('data'))
success['cookies'] = headers
with open(username + '.json', 'w') as outfile:
json.dump(success, outfile)
return success
else:
return login.json()
def home_list(self, user_data={}):
url = self.api_url + "aweme/v1/feed/?count=20&offset=0&max_cursor=0&type=0&is_cold_start=1&pull_type=1&" + self.helper.query(
self.helper.default_variable(self.global_variable))
if (user_data.__len__() > 0):
data = self.helper.request_get(self, url, session=self.active_user['cookies'])
else:
data = self.helper.request_get(self, url)
return data.json()
def search_user(self, text='teamtolga', session={}):
url = self.api_url + "aweme/v1/discover/search/?cursor=0&keyword=" + text + "&count=10&type=1&hot_search=0&" + self.helper.query(
self.helper.default_variable(self.global_variable))
if (session.__len__() > 0):
data = self.helper.request_get(self, url, session=session)
else:
data = self.helper.request_get(self, url)
return data.json()
def like_post(self, aweme_id=1, type='1', session={}):
url = self.api_url + "aweme/v1/commit/item/digg/?aweme_id=" + aweme_id + "&type=" + type + "&retry_type=no_retry&from=3&" + self.helper.query(
self.helper.default_variable(self.global_variable))
data = self.helper.request_get(self, url, session=session)
return data.json()
def view_post(self, aweme_id=1, session={}):
data = self.helper.default_variable()
data['aweme_type'] = 0
data['play_delta'] = 1
data['item_id'] = aweme_id
url = self.api_url + "aweme/v1/aweme/stats/?" + self.helper.query(
self.helper.default_variable(self.global_variable))
data = self.helper.request_post(url, posts=data, session=session)
return data.json()
def follow(self, user_id='6594722549190574086', type='1', session={}):
url = self.api_url + "aweme/v1/commit/follow/user/?user_id=" + str(user_id) + "&type=" + str(
type) + "&retry_type=no_retry&from=3&" + self.helper.query(
self.helper.default_variable(self.global_variable))
data = self.helper.request_get(self, url, session=session)
return data.json()
def user_info(self, user_id='6594722549190574086', session={}):
url = self.api_url + "aweme/v1/user/?user_id=" + str(user_id) + "&" + self.helper.query(
self.helper.default_variable(self.global_variable))
if (session.__len__() > 0):
data = self.helper.request_get(self, url, session=session)
else:
data = self.helper.request_get(self, url)
return data.json()
def user_video_list(self, user_id='6594722549190574086', session={}):
url = self.api_url + "aweme/v1/aweme/post/?user_id=" + str(
user_id) + "&max_cursor=0&type=0&count=20&pull_type=1&" + self.helper.query(
self.helper.default_variable(self.global_variable))
if (session.__len__() > 0):
data = self.helper.request_get(self, url, session=session)
else:
data = self.helper.request_get(self, url)
return data.json()
def register(self, user={}, extra={}):
data = self.helper.default_variable()
data['mix_mode'] = '1'
data['email'] = self.helper.xor(user['email'])
data['password'] = self.helper.xor(user['password'])
data['code'] = None
data['recaptcha_token'] = None
url = self.api_url + "passport/email/register/v2/?" + self.helper.query(
self.helper.default_variable(self.global_variable))
data = self.helper.request_post(url, posts=data)
headers = {}
for c in data.cookies:
headers[c.name] = c.value
send_data = {}
send_data['data'] = data.json().get('data')
send_data['cookies'] = headers
return send_data
def register_device(self):
'''
No Complate
:return:
'''
header = {}
data = open('./content.data', 'rb').read()
header['Content-Type'] = 'application/octet-stream;tt-data=a'
url = "http://applog.musical.ly/service/2/device_register/"
data = self.helper.request_post(url, posts=data, costum_headers=header)
print(data.content)
def follow_list(self, user_id='6594722549190574086', count=20, max_time=None, session={}):
if (max_time == None):
max_time = int(round(time.time() * 1000))
url = self.api_url + "aweme/v1/user/follower/list/?user_id=" + str(user_id) + "&count=" + str(
count) + "&max_time=" + str(max_time) + "&retry_type=no_retry&" + self.helper.query(
self.helper.default_variable(self.global_variable))
data = self.helper.request_get(self, url, session=session)
return data.json()
def following_list(self, user_id='6594722549190574086', count=20, max_time=None, session={}):
if (max_time == None):
max_time = int(round(time.time() * 1000))
url = self.api_url + "aweme/v1/user/following/list/?user_id=" + str(user_id) + "&count=" + str(
count) + "&max_time=" + str(max_time) + "&retry_type=no_retry&" + self.helper.query(
self.helper.default_variable(self.global_variable))
data = self.helper.request_get(self, url, session=session)
return data.json()
''' Halil İbrahim\'e Teşekkürler search_hashtag, list_hashtag '''
def search_hashtag(self, text):
url = self.api_url + "aweme/v1/challenge/search/?cursor=0&keyword=" + text + "&count=10&type=1&hot_search=0&" + self.helper.query(
self.helper.default_variable(self.global_variable))
data = self.helper.request_get(url)
return data.json()
def list_hashtag(self, cid):
url = self.api_url + "aweme/v1/challenge/aweme/?ch_id=" + cid + "&count=20&offset=0&max_cursor=0&type=5&query_type=0&is_cold_start=1&pull_type=1&" + self.helper.query(
self.helper.default_variable(self.global_variable))
data = self.helper.request_get(self, url)
return data.json()
def getQRCode(self, user_id='6594722549190574086', schemaType=4, session={}):
data = self.helper.default_variable()
data['schema_type'] = schemaType
data['object_id'] = user_id
costum_headers = {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
url = self.api_url + "aweme/v1/fancy/qrcode/info/"
data = self.helper.request_post(url, posts=data, costum_headers=costum_headers, session=session)
return data.json()