每天赚一顿饭钱很轻松?利用Python开发某手自动刷视频脚本

春节期间闲在家里无事,老妈又要刷快手极速版挣金币,整天在那刷.看不下去了,就写了个脚本自动刷.脚本使用 python 调用 adb 命令,目前只实现了只在快手的视频界面自动滑屏, 其他界面不做任何事.不过可以自行添加需要滑动的界面. 更新: 又增加了刷宝短视频, 老妈的手机是 OnePlus5T, 最前面会多一个 ' * ContentProviderRecord{362943b u0
com.snda.wifilocating/com.baidu.pyramid.runtime.multiprocess.components.ServerProvider}\n' 因此直接取位置不可取. 刷宝还是只需要下滑就可以了,因此没有做特殊动作. 下面是新的Python源码.

再次更新,又增加了快音,另外修改了前台程序判断的逻辑,还修改了程序执行的条件,现在不会因为设备突然断开而导致程序停止运行.

python源码:

"""
当然在学习Python的道路上肯定会困难,没有好的学习资料,怎么去学习呢? 
学习Python中有不明白推荐加入交流Q群号:928946953 
群里有志同道合的小伙伴,互帮互助, 群里有不错的视频学习教程和PDF!
还有大牛解答!
"""
#! /usr/bin/python
# author: sukanka
# updated: 2020-02-17 18:42
import os
import random
import time
ACTIVITIES=['com.kuaishou.nebula/com.yxcorp.gifshow.HomeActivity',"com.jm.video/.ui.main.MainActivity", "com.kuaiyin.player/.MainActivity"]
# 快手, 刷宝, 快音

def findFrontActivity(device):
    activityList=os.popen("adb -s {} shell dumpsys activity | grep -i run".format(device)).readlines() # 获取所有正在运行任务
    activity=""
    for string in activityList:
        if "Run #" in string: # 找到最前台的活动
            activity=string
            break
    activity=activity.strip().split(" ") # 删除首尾空格后按中间的空格分割
# ['Run', '#0:', 'ActivityRecord{ab835a9', 'u0', 'com.kuaishou.nebula/com.yxcorp.gifshow.HomeActivity', 't8874}']
    if activity !="":
        try:
            activity=activity[4]
            return activity
        except IndexError:
            print(activity)
            return ""
# com.kuaishou.nebula/com.yxcorp.gifshow.HomeActivity

def autoSwipe(ACTIVITIES):
    connected=os.popen("adb devices").readlines()
    devices=[connected[i][0:-8] for i in range(1,len(connected)-1)] # 获取所有设备代号
    x=random.randint(200,800)
    y=random.randint(350,550)
    dx=random.randint(0,50)
    dy=random.randint(900,1200)
    tap_time=random.randint(300,600) # 随机选择滑动参数
    for device in devices:
        if findFrontActivity(device) in ACTIVITIES: # 如果前台运行特定应用就自动滑动
            slide="adb -s {} shell input swipe {} {} {} {} {}".format(device,x+dx,y+dy,x,y,tap_time)
            os.system(slide)
        else:
            continue    
    time.sleep(2+3*random.random()) # 滑动后随机等待2-5秒

if __name__=="__main__":
    while True:
        if os.system("adb devices")==0: # 如果有设备连接.
            autoSwipe(ACTIVITIES)
image
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容