forked from kellaJL/douyin-script
-
Notifications
You must be signed in to change notification settings - Fork 1
/
douyin-main.py
264 lines (208 loc) · 6.93 KB
/
douyin-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
# -*- coding: utf-8 -*-
import sys
import random
import time
import os
import base64
from PIL import Image
if sys.version_info.major != 3:
print('Please run under Python3')
exit(1)
try:
from common import debug, config, screenshot, UnicodeStreamFilter
from common.auto_adb import auto_adb
from common import apiutil
from common import apiutilFACEPP
from common.compression import resize_image
except Exception as ex:
print(ex)
print('请将脚本放在项目根目录中运行')
print('请检查项目根目录中的 common 文件夹是否存在')
exit(1)
VERSION = "0.0.1"
DEBUG_SWITCH = True
FACE_PATH = 'face/'
adb = auto_adb()
adb.test_device()
config = config.open_accordant_config()
# 审美标准
BEAUTY_THRESHOLD = 80
# 最小年龄
GIRL_MIN_AGE = 12
#源图
source_image_data="D:/compare.jpg"
#断点续存
ts=0
if not os.path.isdir('screenshot_backups'):
os.mkdir('screenshot_backups')
if not os.path.exists('screenshot_backups/ts.txt'):
f=open('screenshot_backups/ts.txt','w')
f.write('0')
f.close()
with open('screenshot_backups/ts.txt','r') as f:
ts=int(f.readline())
f.close()
def yes_or_no():
"""
检查是否已经为启动程序做好了准备
"""
while True:
yes_or_no = str(input('请确保手机打开了 ADB 并连接了电脑,'
'然后打开手机软件,确定开始?[y/n]:'))
if yes_or_no == 'y':
break
elif yes_or_no == 'n':
print('谢谢使用', end='')
exit(0)
else:
print('请重新输入')
def _random_bias(num):
"""
random bias
:param num:
:return:
"""
print('num = ', num)
return random.randint(-num, num)
def next_page():
"""
翻到下一页
:return:
"""
cmd = 'shell input swipe {x1} {y1} {x2} {y2} {duration}'.format(
x1=config['center_point']['x'],
y1=config['center_point']['y']+config['center_point']['ry'],
x2=config['center_point']['x'],
y2=config['center_point']['y'],
duration=200
)
adb.run(cmd)
time.sleep(1.5)
def follow_user():
"""
关注用户
:return:
"""
cmd = 'shell input tap {x} {y}'.format(
x=config['follow_bottom']['x'] + _random_bias(10),
y=config['follow_bottom']['y'] + _random_bias(10)
)
adb.run(cmd)
time.sleep(0.5)
def thumbs_up():
"""
点赞
:return:
"""
cmd = 'shell input tap {x} {y}'.format(
x=config['star_bottom']['x'] + _random_bias(10),
y=config['star_bottom']['y'] + _random_bias(10)
)
adb.run(cmd)
time.sleep(0.5)
def source_image(image_path):
f=open(image_path,'rb')
image_data=f.read()
image=base64.b64encode(image_data)
f.close()
return image
def TencentRun():
global ts
while True:
next_page()
time.sleep(1)
screenshot.pull_screenshot()
resize_image('autojump.png', 'optimized.png', 1024*1024)
with open('optimized.png', 'rb') as bin_data:
image_data = bin_data.read()
#存储图片
# 申请地址 http://ai.qq.com
AppID='2108770140'
AppKey='JWZYO7SuPcsURp04'
ai_obj = apiutil.AiPlat(AppID, AppKey)
rsp = ai_obj.face_detectface(image_data, 0)
major_total = 0
minor_total = 0
if rsp['ret'] == 0:
beauty = 0
for face in rsp['data']['face_list']:
print(face)
face_area = (face['x'], face['y'], face['x']+face['width'], face['y']+face['height'])
print(face_area)
img = Image.open("optimized.png")
cropped_img = img.crop(face_area).convert('RGB')
cropped_img.save(FACE_PATH + face['face_id'] + '.png')
# 性别判断
if face['beauty'] > beauty and face['gender'] < 50:
beauty = face['beauty']
if face['age'] > GIRL_MIN_AGE:
major_total += 1
else:
minor_total += 1
# 是个美人儿~关注点赞走一波
if beauty > BEAUTY_THRESHOLD and major_total > minor_total:
print('发现漂亮妹子!!!')
thumbs_up()
follow_user()
#存储截图
debug.save_debug_screenshot_font(ts,face['age'],face['beauty'])
ts+=1
else:
print(rsp)
continue
def FacePPRun():
global ts
global source_image_data
while True:
next_page()
#time.sleep(1)
screenshot.pull_screenshot()
resize_image('autojump.png', 'optimized.png', 1024*1024)
with open('optimized.png', 'rb') as bin_data:
image_data = bin_data.read()
bin_data.close()
AppID='kyvvWu38YdLNSElYJ474dZeqaxuom2pe'
AppKey='gBivbqKgUVZOKKMYbfCWSIpBfOnqR8W0'
ai_obj = apiutilFACEPP.AiPlatFACEPP(AppID, AppKey)
rsp = ai_obj.face_detectfacePP(image_data, 1)
print(rsp)
im_s=source_image(source_image_data)
confidence = ai_obj.compare_body(im_s,image_data)
print('相似度:'+str(confidence))
if ('female_score' in rsp.keys()) and ('male_score' in rsp.keys()) and ('age' in rsp.keys()) and ('gender' in rsp.keys()):
# 是个美人儿~关注点赞走一波
if rsp['female_score'] > BEAUTY_THRESHOLD and rsp['male_score'] > BEAUTY_THRESHOLD and rsp['age']>GIRL_MIN_AGE and rsp['gender']=='Female':
print('发现漂亮妹子!!!')
thumbs_up()
follow_user()
#存储截图
rspk=ai_obj.body_segment(image_data)
if confidence>75:
print("发现高度相似,已抠像")
with open(os.path.join('screenshot_backups','#segment-'+str(ts)+'.png'),'wb') as bin_data:
bin_data.write(rspk)
bin_data.close()
debug.save_debug_screenshot_font(ts,rsp['age'],rsp['male_score'])
ts+=1
else:
print(rsp)
continue
def main():
"""
main
:return:
"""
print('程序版本号:{}'.format(VERSION))
print('激活窗口并按 CONTROL + C 组合键退出')
debug.dump_device_info()
screenshot.check_screenshot()
#TencentRun()
FacePPRun()
if __name__ == '__main__':
try:
# yes_or_no()
main()
except KeyboardInterrupt:
adb.run('kill-server')
print('谢谢使用')
exit(0)