├── README.md └── douyin.py /README.md: -------------------------------------------------------------------------------- 1 | # FaceIdentify 2 | 3 | 自动识别抖音上高颜值女性并自动关注或者点赞 4 | 5 | * 1、电脑安装雷电模拟器 6 | 7 | * 2、雷电模拟器安装抖音并打开抖音 8 | 9 | * 3、电脑上用python模拟鼠标自动刷抖音视频,截图保存共享到电脑 10 | 11 | * 4、注册百度云账号,开启 人工智能-人脸识别 服务,并创建一个应用 12 | 13 | * 5、通过写程序自动提交本地截图到百度云进行人脸识别 14 | 15 | * 6、解析结果JSON,提取颜值的评分,判断高于某个分值后模拟鼠标点击关注或者点赞用户 16 | -------------------------------------------------------------------------------- /douyin.py: -------------------------------------------------------------------------------- 1 | import win32api 2 | import win32con 3 | import win32gui 4 | from ctypes import * 5 | from pymouse import PyMouse 6 | from time import sleep 7 | import pyautogui as pag 8 | import os 9 | import time 10 | import requests 11 | import json 12 | import shutil 13 | import datetime 14 | from PIL import Image 15 | 16 | 17 | class POINT(Structure): 18 | _fields_ = [("x", c_ulong),("y", c_ulong)] 19 | def get_mouse_point(): 20 | po = POINT() 21 | windll.user32.GetCursorPos(byref(po)) 22 | return int(po.x), int(po.y) 23 | def mouse_click(x=None,y=None): 24 | if not x is None and not y is None: 25 | mouse_move(x,y) 26 | time.sleep(0.05) 27 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 28 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 29 | def mouse_dclick(x=None,y=None): 30 | if not x is None and not y is None: 31 | mouse_move(x,y) 32 | time.sleep(0.05) 33 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 34 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 35 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 36 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 37 | def mouse_move(x,y): 38 | windll.user32.SetCursorPos(x, y) 39 | 40 | 41 | 42 | class BaiduFaceIdentify(): 43 | #此函数用于获取access_token,返回access_token的值 44 | #此函数被parse_face_pic调用 45 | def get_access_token(self): 46 | client_id = "xxxxxxxxxxxxxxxxxxxxxxxxxx" #此变量赋值成自己API Key的值 47 | client_secret = "yyyyyyyyyyyyyyyyyyyyyyyyy" #此变量赋值成自己Secret Key的值 48 | auth_url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + client_id + "&client_secret=" + client_secret 49 | 50 | response_at = requests.get(auth_url) 51 | json_result = json.loads(response_at.text) 52 | access_token = json_result["access_token"] 53 | return access_token 54 | 55 | 56 | 57 | def imgdata(self,file1path): 58 | import base64 59 | f=open(r'%s' % file1path,'rb') 60 | pic1=base64.b64encode(f.read()) 61 | f.close() 62 | #将图片信息格式化为可提交信息,这里需要注意str参数设置,这里将图片信息转换为 base64 再提交 63 | #params = {"images":str(pic1,'utf-8')} 64 | return pic1 65 | 66 | 67 | #此函数进行人脸识别,返回识别到的人脸列表 68 | #此函数被parse_face_pic调用 69 | def identify_faces(self,url_pic,url_fi): 70 | headers = { 71 | "Content-Type" : "application/json; charset=UTF-8" 72 | } 73 | 74 | img_params = self.imgdata(url_pic) 75 | 76 | post_data = { 77 | "image": img_params, 78 | "image_type" : "BASE64", 79 | "face_field" : "beauty,gender", #expression,faceshape,landmark,race,quality,glasses 80 | "max_face_num": 1 81 | } 82 | 83 | response_fi = requests.post(url_fi,headers=headers,data=post_data) 84 | json_fi_result = json.loads(response_fi.text) 85 | return json_fi_result["result"] 86 | #下边的print也许是最直观,你最想要的 87 | #print(json_fi_result[‘result‘][‘face_list‘][0][‘age‘]) 88 | #print(json_fi_result[‘result‘][‘face_list‘][0][‘beauty‘]) 89 | 90 | #此函数用于解析进行人脸图片,输出图片上的人脸的性别、年龄、颜值 91 | #此函数调用get_access_token、identify_faces 92 | def parse_face_pic(self,url_pic): 93 | #调用get_access_token获取access_token 94 | access_token = self.get_access_token() 95 | url_fi = "https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=" + access_token 96 | #调用identify_faces,获取人脸列表 97 | json_faces = self.identify_faces(url_pic,url_fi) 98 | return json_faces 99 | 100 | 101 | 102 | 103 | if __name__ == "__main__": 104 | 105 | while True: 106 | print('>>>> 调用程序时间:%s <<<<' % datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) 107 | mouse_dclick(1620, 687) 108 | pag.mouseDown(x=1620, y=790, button='left') 109 | pag.mouseUp(x=1620, y=300, button='left') 110 | print(">> 切换抖音用户视频页面成功") 111 | 112 | 113 | # 截图 114 | mouse_click(1881, 247) 115 | sleep(3) 116 | paths = "H:\myshares\Screenshots" 117 | for root, dirs, files in os.walk(paths): 118 | filename=files[0] 119 | print(">> 截图成功,截图文件名:%s," % filename) 120 | file_dir = paths+"\\"+filename 121 | 122 | #file_dir="H:\myshares\Screenshots\Screenshot_2018-08-19-17-49-24.png 123 | 124 | # 分辨率整体缩小到原来的 0.3 ,可以加快上传速度 125 | to_scale = 0.3 126 | 127 | img = Image.open(file_dir) 128 | w,h = img.size 129 | tw = int(w * to_scale) 130 | th = int(h * to_scale) 131 | reImg = img.resize((tw,th),Image.ANTIALIAS) 132 | new_file_dir = file_dir + '.png' 133 | reImg.save( new_file_dir ) 134 | print(">> 转换图片大小成功,正调用颜值API识别接口: %s" % file_dir) 135 | # 转换大小后删除原图 136 | os.remove(file_dir) 137 | 138 | 139 | 140 | 141 | url_pic = new_file_dir 142 | bfi = BaiduFaceIdentify() 143 | results = bfi.parse_face_pic(url_pic) 144 | if results: 145 | print('返回结果: %s' % results ) 146 | results_tmp=json.dumps(results) 147 | results=json.loads(results_tmp) 148 | beauty=results['face_list'][0]['beauty'] 149 | sex=results['face_list'][0]['gender']['type'] 150 | if sex == 'female': 151 | print('>> 识别到视频中是一女性,颜值评分为: %s' % beauty ) 152 | if int(beauty) > 70: 153 | mouse_click(1811, 481) 154 | print('>> 认定为高颜值女性,已经关注了哟 !!!!!!!!!!!!!!!!!!!!!') 155 | shutil.move(new_file_dir,"H:\myshares\\bak-img") 156 | else: 157 | os.remove(new_file_dir) 158 | else: 159 | print('>> 识别到视频中是一男性') 160 | os.remove(new_file_dir) 161 | 162 | else: 163 | print(">> 识别不到人脸,可能是侧脸或者画面没有人。复审路径: %s" % new_file_dir) 164 | os.remove(new_file_dir) 165 | 166 | print('\n') 167 | sleep(2) 168 | 169 | 170 | """ 171 | 打印出当前鼠标所在位置 172 | m = PyMouse() 173 | print (m.position()) 174 | """ 175 | --------------------------------------------------------------------------------