Loading

抖音人脸识别Autojs脚本

用Autojs写的抖音人脸颜值检测脚本


​ 疫情期间宅家久了,昨天闲着没事(好吧,有事情,但是我不想做) ,消费之火熊熊燃烧。一咬牙把Autojs入正了。我去年接触过这个app:《家国梦》刚出来的时候,用它写了解放双手的脚本,尝到了快乐。

​ 既然入正了,总得干点啥吧。然后我想起了前几天在Github上看见的一个很有意思的项目:如何在抖音上找到漂亮小姐姐 。刚看到这个项目的时候,我就为作者的脑回路狠狠的点了个赞。

​ 所以,我想着自己也写一个玩玩吧,哈哈哈哈哈哈。

​ 于是,昨天晚上,把这个写完了,还贴心的开了个源。(虽然实现挺简单的。。原谅我的臭屁! 哈哈哈哈)


1. 思路来自wangshub的开源项目Douyin-Bot

  1. 打开抖音
  2. 截图
  3. 识别是否有人脸并检测颜值
  4. 颜值合格则点赞关注切换下一个视频

2. 人脸识别api用的百度智能云(因为免费)

链接:百度智能云

写代码的时候发现百度这个Api还能判断性别(还挺准的,至少我觉得比颜值准确),

所以除了识别小姐姐,我还加上了识别小哥哥的功能

3. 核心源码

var faceValue = 30;//默认30分
var pornValue = 2;//默认2位
var type = 'female';//默认小姐姐
if(files.read("yanzhi.dat")){
    faceValue = files.read("yanzhi.dat");
}else{
    faceValue = 30;//默认30分
}
if(files.read("shuliang.dat")){
    pornValue = files.read("shuliang.dat");
}else{
    pornValue = 2;//默认2位
}
if(files.read("xingbie.dat")){
    type = files.read("xingbie.dat");
}else{
    type = 'female';//默认2位
}


var countVid = 1;//滑动的视频数
var countAdd = 0;//关注的视频数
console.show();
log("颜值:"+faceValue);
log("数量:"+pornValue);
log("性别:"+type);

if(app.launch("com.ss.android.ugc.aweme")){
    log("抖音打开成功!");
    toast("抖音打开成功!");

    if(!requestScreenCapture(false)){
        log("请求截图失败");
        exit();
    }

    var addStar = id("b6s").desc("关注").findOne();
    var addStar_x = addStar.bounds().centerX();
    var addStar_y = addStar.bounds().centerY();
    log("获取关注控件成功!");

    var addHeart = id("alx").findOne();
    var addHeart_x = addHeart.bounds().centerX();
    var addHeart_y = addHeart.bounds().centerY();
    log("获取点赞控件成功!");

    while(countAdd < pornValue){
        var time = 1000;
        var allTime = 0.3 * 60 * 1000;
        
        for(var i = 0; allTime > 0; i++){
            var temAdd = countAdd;
            var img = captureScreen();
            var imgFile = i+".png";
            images.saveImage(img,imgFile);
            log("…………开始人脸识别!…………");
            toast("开始人脸识别!");
            var img1 = images.read(imgFile);
            var ak = 'KXIS86UejDFk9RzMxYp0DFMF';//你的人脸识别ak
            var sk = 'C93QyBiG346cTezoECXQsGcUsszaln4G';//你的人脸识别sk
            var access_token = http.get("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id="+ak+"&client_secret="+sk).body.json().access_token;
            var url = "https://aip.baidubce.com/rest/2.0/face/v3/detect" + "?access_token=" + access_token;
            var image64 = images.toBase64(img1);
            if(img1){
                       
                var res = http.post(url, {
                    headers: {
                        'Content-Type': 'application/json; charset=UTF-8'
                    },
                    'image': image64,
                    'image_type': 'BASE64',
                    'face_field': 'gender,age,beauty'
                });

                var str = JSON.parse(res.body.string());

                if(str['error_msg'] == 'pic not has face'){
                    log(countVid+".没有检测到人脸!");
                    toast("没有检测到人脸!");
                }else if(str['error_msg'] == 'SUCCESS'){
                    log(countVid+".检测到了"+str['result']['face_num']+"张人脸");
                    log(countVid+".人脸性别为:"+str['result']['face_list'][0]['gender']['type']);
                    log(countVid+".人脸年龄为:"+str['result']['face_list'][0]['age']);
                    log(countVid+".人脸颜值为:"+str['result']['face_list'][0]['beauty']);
                    toast("人脸性别为:["+str['result']['face_list'][0]['gender']['type']+"]  人脸颜值为:["+str['result']['face_list'][0]['beauty']+"]");
                    if(str['result']['face_list'][0]['gender']['type'] == type){
                        if(str['result']['face_list'][0]['beauty'] > faceValue){
                            log(countVid+".人脸颜值合格!");
                            toast(countVid+".人脸颜值合格!");
                            click(addStar_x,addStar_y);
                            click(addHeart_x,addHeart_y);
                            countAdd++;
                        }
                    }

                }
            }
            log("…………"+countVid+"的人脸识别运行结束…………");
            toast("人脸识别完成");
            time += 1000*i;
            allTime = allTime - time;
            sleep(time);
            log("第"+countVid+"个视频,已点赞关注"+countAdd+"个视频");
            toast("第"+countVid+"个视频,已点赞关注"+countAdd+"个视频");
            files.remove(imgFile);
            if(temAdd < countAdd){
                log("视频已关注");
                toast("视频已关注");
                if(pornValue != countAdd){
                    swipe(device.width / 2, (device.height - (device.height/8)), device.width / 2, device.height/8, 1500);
                    log("滑动完成");
                    countVid ++;
                }
                break;
            }else{
                log("视频不符合您的审美")
                toast("视频不符合您的审美");
                if(allTime <0){
                    swipe(device.width / 2, (device.height - (device.height/8)), device.width / 2, device.height/8, 1500);
                    log("滑动完成");
                    countVid ++;
                }
            }
        }
    }
}
log("运行结束!共关注"+countAdd+"位颜值"+faceValue+"分以上的用户!");
toast("运行结束!共关注"+countAdd+"位颜值"+faceValue+"分以上的用户!");
log("谢谢您的使用,再见!");
toast("谢谢您的使用,再见!");
sleep(5000);
console.hide();

4. 运行截图

运行截图

5. 使用说明

使用说明可以看我的Github
Star

或者看我的Gitee star

最后,如果您觉着这项目有趣,star一下叭o.o

posted @ 2020-04-30 17:51  fofade  阅读(3273)  评论(2编辑  收藏  举报