commit | author | age
|
b2d3f7
|
1 |
/** |
P |
2 |
* description 抖音养号第1-2天 随机浏览推荐页作品 命中关键词作品停留 |
|
3 |
* @type {launch|{}} |
|
4 |
*/ |
bc5e1e
|
5 |
let launch = require("slib/launch"), actions = require("slib/actions"), dynamicData = require("slib/dynamicData"), |
X |
6 |
request = require("slib/request"), swiper = require("slib/swiper"); |
b2d3f7
|
7 |
|
P |
8 |
let scriptVersion = "2024.11.13" |
|
9 |
logd("抖音养号第1-2天脚本启动成功,版本:"+ scriptVersion); |
bc5e1e
|
10 |
|
X |
11 |
let storage = storages.create("storage"); //创建存储对象 |
|
12 |
storage.clear(); //清空存储 |
|
13 |
|
|
14 |
let taskInfo = request.getTask(); //获取任务信息 |
|
15 |
if (taskInfo.tenantId) storage.putInt("tenantId", taskInfo.tenantId); //存储租户id |
|
16 |
|
|
17 |
storage.putString("serial_num", time()); //存储任务流水号(生成时间戳) |
|
18 |
|
|
19 |
let label; //账号标签(同搜索内容) |
|
20 |
|
|
21 |
let max_views = random(50, 60); //浏览作品数 |
|
22 |
|
|
23 |
// label = ['短视频代运营', '短视频运营', '短视频运营课程', '短视频剪辑', '短视频剪辑课程']; //测试数据 |
|
24 |
|
|
25 |
let taskId = launch.taskThread(random(30, 40)); //开启任务时间线程 |
|
26 |
|
|
27 |
if (taskInfo.valueJson) { |
|
28 |
logd('获取任务数据:' + JSON.stringify(taskInfo.valueJson)); |
b2d3f7
|
29 |
dynamicData.deviceLog(false, {log_detail: '获取任务数据:' + JSON.stringify(taskInfo.valueJson)}); |
bc5e1e
|
30 |
//是否有需求数据 |
X |
31 |
if (taskInfo.valueJson['标题关键词']) label = taskInfo.valueJson['标题关键词'].split("|"); |
b2d3f7
|
32 |
logd('获取任务参数:标题关键词,' + JSON.stringify(label)); |
bc5e1e
|
33 |
} else { |
X |
34 |
logd('没有任务数据'); |
b2d3f7
|
35 |
dynamicData.deviceLog(false, {log_detail: '没有任务数据'}); |
bc5e1e
|
36 |
} |
X |
37 |
|
|
38 |
launch.launchDevice(taskId); //唤醒设备 |
b2d3f7
|
39 |
|
bc5e1e
|
40 |
if (label) { |
X |
41 |
let hasLaunchApp = launch.launchApp(1, 30000, 3); //打开APP |
|
42 |
if (hasLaunchApp) { |
|
43 |
launch.alertListener(1, taskId); //处理弹窗 |
|
44 |
browseRecommend(); //浏览推荐 |
|
45 |
} |
|
46 |
} else { |
|
47 |
logd('缺少标题关键词数据'); |
|
48 |
actions.exceptionLog('缺少标题关键词数据'); |
|
49 |
} |
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* description 浏览推荐 |
|
54 |
*/ |
b2d3f7
|
55 |
function browseRecommend() { |
bc5e1e
|
56 |
let startNum = 0; //尝试浏览次数 |
X |
57 |
let view = 0; //已浏览作品数 |
|
58 |
if (toRecommend()) { |
|
59 |
while (!thread.isCancelled(taskId)) { |
|
60 |
startNum++; |
|
61 |
//是否达到浏览数 |
|
62 |
if (view < max_views) { |
|
63 |
try { |
|
64 |
logd('正在浏览第' + (view + 1) + '个作品'); |
|
65 |
let log = { |
|
66 |
log_detail: '正在浏览第' + (view + 1) + '个作品', |
|
67 |
operate_type: 5 |
|
68 |
} |
|
69 |
dynamicData.deviceLog(true, log); |
|
70 |
dynamicData.insertTrace(log); |
|
71 |
sleep(random(3000, 4000)); |
|
72 |
let videoInfo = actions.getVideoInfo(1); //作品页信息 |
|
73 |
if (videoInfo) { |
|
74 |
startNum = 0; |
|
75 |
for (let i = 0; i < label.length; i++) { |
|
76 |
if (videoInfo.postSelector.text.includes(label[i])) { |
|
77 |
let second = random(5, 8); |
|
78 |
logd('当前作品标题包含关键词 "' + label[i] + '",随机停留' + second + '秒'); |
|
79 |
logd.post_name = videoInfo.postSelector.text; |
|
80 |
log.post_user_nickname = videoInfo.nameSelector.text; |
|
81 |
log.log_detail = '当前作品标题包含关键词 "' + label[i] + '",随机停留' + second + '秒'; |
|
82 |
log.operate_type = 17; |
|
83 |
log.keyword = label[i]; |
|
84 |
dynamicData.deviceLog(false, log); |
|
85 |
dynamicData.insertTrace(log); |
|
86 |
sleep(second * 1000); |
|
87 |
break; |
|
88 |
} |
|
89 |
} |
|
90 |
view++; |
|
91 |
actions.randomSwiper(); //随机翻页 |
|
92 |
} else { |
|
93 |
if (startNum < 3 || startNum === 4) { |
|
94 |
swiper.pageSwiper(); |
|
95 |
logd('该作品无有效标题,略过'); |
b2d3f7
|
96 |
dynamicData.deviceLog(false, {log_detail: '该作品无效,略过'}); |
P |
97 |
} else if (startNum === 3 || startNum === 5 || startNum === 6) { |
bc5e1e
|
98 |
actions.go_back(1); |
X |
99 |
logd('未找到作品信息,尝试返回'); |
b2d3f7
|
100 |
dynamicData.deviceLog(false, {log_detail: '未找到作品信息,尝试返回'}); |
bc5e1e
|
101 |
} else { |
X |
102 |
toRecommend(); |
|
103 |
logd('未找到作品信息,重新进入视频'); |
b2d3f7
|
104 |
dynamicData.deviceLog(false, {log_detail: '未找到作品信息,重新进入视频'}); |
bc5e1e
|
105 |
} |
X |
106 |
} |
|
107 |
} catch (e) { |
|
108 |
if (!thread.isCancelled(taskId)) { |
|
109 |
logd('未找到有效作品:' + e); |
|
110 |
let error = { |
|
111 |
log_detail: '未找到有效作品:' + e, |
b2d3f7
|
112 |
operate_type: 16 |
bc5e1e
|
113 |
} |
X |
114 |
dynamicData.deviceLog(false, error); |
|
115 |
dynamicData.insertTrace(error); |
|
116 |
if (startNum < 3 || startNum === 4) { |
|
117 |
swiper.pageSwiper(); |
|
118 |
logd('该作品无有效标题,略过'); |
b2d3f7
|
119 |
dynamicData.deviceLog(false, {log_detail: '该作品无效,略过'}); |
P |
120 |
} else if (startNum === 3 || startNum === 5 || startNum === 6) { |
bc5e1e
|
121 |
actions.go_back(1); |
X |
122 |
logd('未找到作品信息,尝试返回'); |
b2d3f7
|
123 |
dynamicData.deviceLog(false, {log_detail: '未找到作品信息,尝试返回'}); |
bc5e1e
|
124 |
} else { |
X |
125 |
toRecommend(); |
|
126 |
logd('未找到作品信息,重新进入视频'); |
b2d3f7
|
127 |
dynamicData.deviceLog(false, {log_detail: '未找到作品信息,重新进入视频'}); |
bc5e1e
|
128 |
} |
X |
129 |
} |
|
130 |
} |
|
131 |
} else { |
|
132 |
logd('养号结束,准备关闭脚本'); |
|
133 |
dynamicData.deviceLog(false, {log_detail: '养号结束,准备关闭脚本', operate_type: 2}); |
|
134 |
exit(); |
|
135 |
break; |
|
136 |
} |
|
137 |
} |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
|
|
142 |
/** |
|
143 |
* description 定位推荐页 |
|
144 |
* @return {boolean} : 返回是否成功 |
|
145 |
*/ |
b2d3f7
|
146 |
function toRecommend() { |
bc5e1e
|
147 |
let result = false; |
X |
148 |
let startNum = 3; //重试次数 |
b2d3f7
|
149 |
let map = {"uri": "snssdk1128://aweme/"}; |
bc5e1e
|
150 |
let num = 0; |
X |
151 |
while (num < startNum) { |
|
152 |
try { |
|
153 |
if (utils.openActivity(map)) { |
|
154 |
logd('已进入作品'); |
b2d3f7
|
155 |
dynamicData.deviceLog(true, {log_detail: '已进入作品'}); |
bc5e1e
|
156 |
result = true; |
X |
157 |
break; |
|
158 |
} else { |
|
159 |
logd('进入作品失败,重新进入'); |
b2d3f7
|
160 |
dynamicData.deviceLog(true, {log_detail: '进入作品失败,重新进入'}); |
bc5e1e
|
161 |
} |
X |
162 |
} catch (e) { |
|
163 |
logd('进入作品失败:' + e); |
|
164 |
actions.exceptionLog('进入作品失败:' + e); |
|
165 |
} |
|
166 |
num++; |
|
167 |
} |
|
168 |
return result; |
|
169 |
} |
|
170 |
|