//操作 let dynamicData = require("slib/dynamicData"), datas = require("slib/datas"), swiper = require("slib/swiper"), request = require("slib/request"); function actions() { } /** * description 根据关键词搜索视频 * @param keyword {string} : 搜索词 * @param platform {number} : 平台 * @return {boolean} : 返回是否成功 */ actions.prototype.searchVideoByKeyword = function (keyword, platform) { let result = false; let startNum = 3; //重试次数 //搜索内容 logd('准备搜索'); dynamicData.deviceLog(true, {log_detail: '准备搜索'}); let schemesItem = datas.schemes.filter(item => item.platform === platform); let map = {"uri": schemesItem[0].scheme["search"] + keyword}; let num = 0; search: while (num < startNum) { try { logd(JSON.stringify(map)); if (utils.openActivity(map)) { sleep(8 * 1000); logd('搜索完成, 准备进入结果页'); let log = { log_detail: '搜索完成, 准备进入结果页', operate_type: 4, keyword: keyword } dynamicData.deviceLog(true, log); // dynamicData.insertTrace(log); let notVideo = text("搜索结果为空").getOneNodeInfo(3 * 1000); if (notVideo) { logd('搜索受限, 准备关闭脚本'); actions.prototype.exceptionLog('搜索受限, 准备关闭脚本'); request.sendDingDing('搜索受限,任务停止', '', false); exit(); break; } //进入视频页 if (platform === 1) { //抖音 let tab_node = clz("android.widget.Button").text("视频").getOneNodeInfo(10 * 1000); //视频分类 if (tab_node) { tab_node.click(); logd('已进入视频分类'); dynamicData.deviceLog(true, {log_detail: '已进入视频分类'}); sleep(8 * 1000); let video_node = id("com.ss.android.ugc.aweme:id/cover").getOneNodeInfo(10 * 1000); //第一个作品 if (video_node) { video_node.click(); logd('已进入视频, 准备浏览作品'); dynamicData.deviceLog(true, {log_detail: '已进入视频, 准备浏览作品'}); sleep(3 * 1000); result = true; break; } } } else if (platform === 2) { //小红书 let selector = text("筛选").getOneNodeInfo(10 * 1000); if (selector) { selector.click(); sleep(5 * 1000); let tab_node = text("视频").getOneNodeInfo(10 * 1000); //视频分类 if (tab_node) { tab_node.click(); sleep(5 * 1000); let finishSelector = text("完成").clickable(true).getOneNodeInfo(10 * 1000); if (finishSelector) { finishSelector.click(); } else { selector.click(); } logd('已进入视频分类'); dynamicData.deviceLog(true, {log_detail: '已进入视频分类'}); sleep(8 * 1000); let video_node = clz("android.widget.ImageView").depth(13).getOneNodeInfo(10 * 1000); //第一个作品 if (video_node) { video_node.click(); logd('已进入视频页, 准备浏览作品'); dynamicData.deviceLog(true, {log_detail: '已进入视频页, 准备浏览作品'}); result = true; break; } } } } else if (platform === 3) { //快手 let tabs = id("com.smile.gifmaker:id/tabs").getOneNodeInfo(10 * 1000).child(0).allChildren(); //分类 if (tabs) { for (let i = 1; i < tabs.length; i++) { tabs[i].click(); sleep(8 * 1000); let live_node = id("com.smile.gifmaker:id/live_status_text").getOneNodeInfo(5 * 1000); //直播分类 let video_node = id("com.smile.gifmaker:id/player_cover").getOneNodeInfo(5 * 1000); //视频分类 if (!live_node && video_node) { logd('已进入视频分类'); dynamicData.deviceLog(true, {log_detail: '已进入视频分类'}); video_node.click(); dynamicData.deviceLog(true, {log_detail: '已进入视频, 准备浏览作品'}); sleep(3 * 1000) result = true; break search; } } } } } else { logd('搜索失败, 重新搜索'); dynamicData.deviceLog(false, {log_detail: '搜索失败, 重新搜索'}); } } catch (e) { logd('搜索失败:' + e); actions.prototype.exceptionLog('搜索失败:' + e); } num++; } return result; } /** * description 根据关键词搜索视频 * @param keyword {string} : 搜索词 * @param platform {number} : 平台 (百度,QQ浏览器) * @return {boolean} : 返回是否成功 */ // actions.prototype.searchByKeyword = function (keyword, platform) { // let result = false; // let startNum = 3; //重试次数 // //搜索内容 // logd('准备搜索'); // dynamicData.deviceLog(true, {log_detail: '准备搜索'}); // let schemesItem = datas.schemes.filter(item => item.platform === platform); // let map = {"uri": schemesItem[0].scheme["search"] + keyword}; // let num = 0; // search: // while (num < startNum) { // try { // let searchLayout = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000); // if (searchLayout) { // let editableTextSelector = clz("android.widget.EditText"); // if (editableTextSelector) { // click(editableTextSelector); // logd('搜索框已点击'); // editableTextSelector.clearText(); // inputText(editableTextSelector, keyword); // logd('输入搜索内容:' + keyword); // let searchBtn = text("搜索").getOneNodeInfo(5000); // if (searchBtn.click()) { // logd('搜索已点击'); // result = true; // } // } else { // let searchBox = searchLayout.getOneNodeInfo(clz("android.widget.TextView"), 5000); // if (searchBox.click()) { // logd('搜索框已点击'); // let searchLayout2 = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000); // if (searchLayout2) { // let editTextSelector2 = searchLayout2.getOneNodeInfo(clz("android.widget.EditText"), 5000); // editTextSelector2.clearText(); // inputText(editTextSelector2, keyword); // logd('输入搜索内容:' + keyword); // let searchBtn = text("搜索").getOneNodeInfo(5000); // if (searchBtn.click()) { // logd('搜索已点击'); // result = true; // } // } // } // } // } // logd(JSON.stringify(map)); // } catch (e) { // logd('搜索失败:' + e); // actions.prototype.exceptionLog('搜索失败:' + e); // } // num++; // } // return result; // } actions.prototype.searchByKeyword = function (keyword, platform) { let result = false; let startNum = 3; //重试次数 //搜索内容 logd('准备搜索'); dynamicData.deviceLog(true, {log_detail: '准备搜索'}); let schemesItem = datas.schemes.filter(item => item.platform === platform); let map = {"uri": schemesItem[0].scheme["search"] + keyword}; let num = 0; search: while (num < startNum) { try { if (platform === 4) { let searchLayout = id("com.baidu.searchbox:id/baidu_searchbox").getOneNodeInfo(5000); if (searchLayout&&searchLayout.click()) { // if (editableTextSelector) { // click(editableTextSelector); // editableTextSelector.click() let editableTextSelector = clz("android.widget.EditText").pkg("com.baidu.searchbox").getOneNodeInfo(5000); logd('搜索框已点击'); sleep(1000); // editableTextSelector.clearText(); if (editableTextSelector) { // editableTextSelector.pasteText(keyword) if (imeInputText(null, keyword)) { logd('输入搜索内容:' + keyword); let searchBtn = text("搜索").getOneNodeInfo(5000); if (searchBtn.click()) { logd('搜索已点击'); result = true; } } } } else { logd('没有找找到搜索按钮,第二种搜索方式'); let searchLayout2 = id("com.baidu.searchbox:id/obfuscated").depth(14).drawingOrder(2).child().getOneNodeInfo(5000) // toast(JSON.stringify(searchLayout2)); if (searchLayout2&&searchLayout2.click()) { let editableTextSelector = clz("android.widget.EditText").pkg("com.baidu.searchbox").getOneNodeInfo(5000); sleep(1000); if (editableTextSelector) { if (imeInputText(null, keyword)) { let searchBtn = text("搜索").getOneNodeInfo(5000); if (searchBtn.click()) { logd('搜索已点击'); result = true; } } } }else{ logd('没有找到搜索按钮 '); } } // editableTextSelector.clearText(); // imeInputText(editableTextSelector, keyword); // searchBtn.click(); // } // } else { // let searchBox = searchLayout.getOneNodeInfo(clz("android.widget.TextView"), 5000); // if (searchBox.click()) { // logd('搜索框已点击'); // let searchLayout2 = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000); // if (searchLayout2) { // let editTextSelector2 = searchLayout2.getOneNodeInfo(clz("android.widget.EditText"), 5000); // editTextSelector2.clearText(); // inputText(editTextSelector2, keyword); // logd('输入搜索内容:' + keyword); // let searchBtn = text("搜索").getOneNodeInfo(5000); // if (searchBtn.click()) { // logd('搜索已点击'); // result = true; // } // } // } } else if (platform === 5) { //qq浏览器 let searchLayout = id("com.tencent.mtt:id/search_bar_tv_hotword").getOneNodeInfo(5000); if (searchLayout && searchLayout.click()) { //获取到 准备写入 sleep(1000); let editableTextSelector = id("com.tencent.mtt:id/search_frame_input_bar").getOneNodeInfo(5000);//.pkg('com.tencent.mtt') // let editableTextSelector = clz("android.widget.EditText").pkg("com.tencent.mtt").getOneNodeInfo(3000) logd(JSON.stringify(editableTextSelector)); sleep(1000); if (editableTextSelector) { // imeInputText(editableTextSelector,keyword) // imeInputText(null,keyword) if (imeInputText(null, keyword)) { sleep(3000); let searchBtn = text("搜索").getOneNodeInfo(5000); if (searchBtn.click()) { logd('搜索已点击'); result = true; } } else { logd('imeInputText 失败'); } // pasteText(editableTextSelector, keyword) // editableTextSelector.inputText(keyword) // if (searchBtn.click()) { // logd('搜索已点击'); // result = true; // } } else { logd('没有找到要写入的搜索框'); } } else { logd('没有找到搜索框') } } // } logd(JSON.stringify(map)); } catch (e) { logd('搜索失败:' + e); actions.prototype.exceptionLog('搜索失败:' + e); } num++; } return result; } /** * description 根据用户id搜索视频 * @param userId {string} : 用户id * @param platform {number} : 平台 * @return {boolean} : 返回用户信息 */ actions.prototype.searchVideoByUserId = function (userId, platform) { let result = false; let startNum = 3; //重试次数 //搜索用户 logd('准备搜索用户'); dynamicData.deviceLog(true, {log_detail: '准备搜索用户'}); let schemesItem = datas.schemes.filter(item => item.platform === platform); let map = {"uri": schemesItem[0].scheme["search"] + userId}; let num = 0; while (num < startNum) { try { if (utils.openActivity(map)) { sleep(8 * 1000); logd('搜索完成,准备进入用户主页'); let log = { log_detail: '搜索完成,准备进入用户主页', operate_type: 4, keyword: userId } dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); let notVideo = text("搜索结果为空").getOneNodeInfo(3 * 1000); if (notVideo) { logd('搜索受限, 准备关闭脚本'); actions.prototype.exceptionLog('搜索受限, 准备关闭脚本'); request.sendDingDing('搜索受限,任务停止', '', false); exit(); break; } //进入用户分类 let tab_node, user_node, video_node, video_tab; //用户分类,第一个用户,第一个视频,作品分类 if (platform === 1) tab_node = clz("android.widget.Button").text("用户").getOneNodeInfo(8 * 1000); if (platform === 2) tab_node = text("用户").getOneNodeInfo(8 * 1000); if (platform === 3) { let tabs = id("com.smile.gifmaker:id/tabs").getOneNodeInfo(8 * 1000).child(0).allChildren(); //分类 if (tabs) { for (let i = 1; i < tabs.length; i++) { tabs[i].click(); sleep(8 * 1000); let name_node = id("com.smile.gifmaker:id/name").getOneNodeInfo(5 * 1000); //用户分类 let video_node = id("com.smile.gifmaker:id/player_cover").getOneNodeInfo(5 * 1000); //视频分类 if (name_node && !video_node) { tab_node = id("com.smile.gifmaker:id/tabs").getOneNodeInfo(8 * 1000).child(0).child(i); break; } } } } if (tab_node) { tab_node.click(); logd('已进入用户分类'); dynamicData.deviceLog(true, {log_detail: '已进入用户分类'}); sleep(5 * 1000); //进入用户主页 if (platform === 1) user_node = clz("com.lynx.tasm.behavior.ui.LynxFlattenUI").getOneNodeInfo(8 * 1000); if (platform === 2) user_node = clz("android.widget.RelativeLayout").getOneNodeInfo(8 * 1000); if (platform === 3) user_node = id("com.smile.gifmaker:id/user_root_layout").getOneNodeInfo(8 * 1000); if (user_node) { user_node.click(); logd('已进入用户主页'); dynamicData.deviceLog(true, {log_detail: '已进入用户主页'}); sleep(5 * 1000); if (platform === 1) video_tab = descMatch(".*作品.*").clz("android.widget.TextView").selected(false).getOneNodeInfo(8 * 1000); if (platform === 2) video_tab = descMatch(".*笔记.*").clz("android.view.ViewGroup").selected(false).getOneNodeInfo(8 * 1000); if (platform === 3) video_tab = textMatch(".*作品.*").id("com.smile.gifmaker:id/tab_text").selected(false).getOneNodeInfo(8 * 1000); if (video_tab) { video_tab.click(); logd('已进入作品分类'); dynamicData.deviceLog(true, {log_detail: '已进入作品分类'}); sleep(2 * 1000); } //进入作品 if (platform === 1) video_node = id("com.ss.android.ugc.aweme:id/cover").getOneNodeInfo(8 * 1000); if (platform === 2) video_node = drawingOrder(3).depth(23).getOneNodeInfo(8 * 1000); if (platform === 3) video_node = id("com.smile.gifmaker:id/player_cover").getOneNodeInfo(8 * 1000); if (video_node) { video_node.click(); logd('已进入视频页, 准备浏览作品'); dynamicData.deviceLog(true, {log_detail: '已进入视频页, 准备浏览作品'}); result = true; break; } } } } else { logd('搜索失败, 重新搜索'); dynamicData.deviceLog(false, {log_detail: '搜索失败, 重新搜索'}); } } catch (e) { logd('搜索失败:' + e); actions.prototype.exceptionLog('搜索失败:' + e); } num++; } return result; } /** * description 打开视频地址 * @param url {string} : 地址 * @param platform {number} : 平台 * @return {boolean} : 返回是否成功 */ actions.prototype.searchVideoByUrl = function (url, platform) { let result = false; let startNum = 3; //重试次数 //搜索视频 dynamicData.deviceLog(true, {log_detail: '准备打开视频'}); let schemesItem = datas.schemes.filter(item => item.platform === platform); let map = {"uri": schemesItem[0].scheme["search"] + url}; let num = 0; while (num < startNum) { try { if (utils.openActivity(map)) { sleep(8000); logd('已进入视频'); let log = { log_detail: '已进入视频', operate_type: 4, } dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); result = true; break; } else { logd('打开视频失败'); dynamicData.deviceLog(false, {log_detail: '打开视频失败'}); } } catch (e) { logd('搜索失败:' + e); let error = { log_detail: '搜索失败:' + e, operate_type: 16 } dynamicData.deviceLog(true, error); dynamicData.insertTrace(error); } num++; } return result; } /** * description 评论回复 * @param dom {object} : 评论节点 * @param log {object} : 日志参数组 * @return {boolean} : 返回是否成功 */ actions.prototype.commentReply = function (dom, log) { let result = false; if (dom) { dom.click(); let title = textMatch(".*自己评论.*").getOneNodeInfo(10000); if (title) { logd('当前评论不允许回复, 继续浏览评论'); log.log_detail = '当前评论不允许回复, 继续浏览评论'; dynamicData.deviceLog(true, log); } else { logd('准备输入回复内容'); log.log_detail = '准备输入回复内容'; dynamicData.deviceLog(true, log); let words = "hello"; let input_selectors = clz("android.widget.EditText").getOneNodeInfo(10000); if (input_selectors) { if (input_selectors.inputText(words)) { logd('回复内容 "' + words + '" 输入成功, 准备发送'); log.log_detail = '回复内容 "' + words + '" 输入成功, 准备发送'; dynamicData.deviceLog(true, log); let send = text("发送").getOneNodeInfo(10000); if (send) { send.click(); logd('回复完成, 继续浏览评论'); log.log_detail = '回复完成, 继续浏览评论'; log.operate_type = 11; dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); delete log.operate_type; result = true; } } } } } return result; } /** * description 私信 * @param dom {object} : 头像节点 * @param platform {number} : 平台 * @param log {object} : 日志参数组 * @return {boolean} : 返回是否成功 */ actions.prototype.message = function (dom, platform, log) { let result = false; logd('准备进入用户主页'); log.log_detail = '准备进入用户主页'; dynamicData.deviceLog(true, log); if (dom) { dom.click(); logd('开始浏览用户主页'); log.log_detail = '开始浏览用户主页'; log.operate_type = 12; dynamicData.deviceLog(true, log); dynamicData.insertTrace(log) delete log.operate_type; if (platform === 1) { //抖音先关注再私信 let follow_btn = text("关注").clickable(true).getOneNodeInfo(10000); if (follow_btn) { follow_btn.click(); logd('已关注用户, 准备进入私信'); log.log_detail = '已关注用户, 准备进入私信'; log.operate_type = 13; dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); delete log.operate_type; //判断私密账户 let private = textMatch(".*私密账号.*").getOneNodeInfo(10000); let ok = text("知道了").getOneNodeInfo(10000); if (private) { ok.click(); logd('该用户是私密账户, 取消私信, 准备返回评论区'); log.log_detail = '该用户是私密账户, 取消私信, 准备返回评论区'; dynamicData.deviceLog(true, log); actions.prototype.go_back(1); return false; } } } let message_btn; //私信按钮 if (platform === 1) message_btn = text("私信").getOneNodeInfo(8000); if (platform === 2) message_btn = desc("发消息").getOneNodeInfo(8000); if (platform === 3) message_btn = id("com.smile.gifmaker:id/send_message_small_icon").getOneNodeInfo(8000); let title = text("账号已经注销").getOneNodeInfo(10000); //判断是否注销 if (title) { logd('该用户已注销, 取消私信, 准备返回评论区'); log.log_detail = '该用户已注销, 取消私信, 准备返回评论区'; dynamicData.deviceLog(true, log); actions.prototype.go_back(1); return false; } else if (message_btn) { message_btn.click(); logd('已进入私信页, 准备发消息'); log.log_detail = '已进入私信页, 准备发消息'; dynamicData.deviceLog(true, log); let input_selectors = clz("android.widget.EditText"); let word = "hello"; //寻找输入框 输入话术 if (inputText(input_selectors, word)) { let send_btn; //发送按钮 if (platform === 1) send_btn = desc("发送").getOneNodeInfo(8000); if (platform === 2) send_btn = text("发送").getOneNodeInfo(index(0), 8000); if (platform === 3) send_btn = id("com.smile.gifmaker:id/send_btn").getOneNodeInfo(8000); if (send_btn.click()) { logd('私信完成,准备返回评论区'); log.log_detail = '私信完成,准备返回评论区'; log.operate_type = 14; log.keyword = text; dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); delete log.operate_type; actions.prototype.go_back(2); result = true; } } } } return result; } /** * description 点赞 * @param dom {object} : 爱心节点 * @param log {object} : 日志参数组 * @return {boolean} : 返回是否成功 */ actions.prototype.like = function (dom, log) { let result = false; if (dom) { dom.click(); logd('已点赞, 继续浏览'); log.log_detail = '已点赞, 继续浏览'; log.operate_type = 10; dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); delete log.operate_type; result = true; } return result; } /** * description 收藏 * @param dom {object} : 收藏节点 * @param log {object} : 日志参数组 * @return {boolean} : 返回是否成功 */ actions.prototype.collection = function (dom, log) { let result = false; if (dom) { dom.click(); logd('已收藏, 继续浏览'); log.log_detail = '已收藏, 继续浏览'; log.operate_type = 7; dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); delete log.operate_type; result = true; } return result; } /** * description 关注 * @param dom {object} : 关注节点 * @param log {object} : 日志参数组 * @return {boolean} : 返回是否成功 */ actions.prototype.follow = function (dom, log) { let result = false; if (dom) { dom.click(); logd('已关注, 继续浏览'); log.log_detail = '已关注, 继续浏览'; log.operate_type = 13; dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); delete log.operate_type; result = true; } return result; } /** * description 评论 * @param log {object} : 日志参数组 * @return {boolean} : 返回是否成功 */ actions.prototype.comment = function (log) { let result = false; logd('准备输入评论内容'); log.log_detail = '准备输入评论内容'; dynamicData.deviceLog(true, log); let words = 'hello'; let input_selectors; input_selectors = clz("android.widget.EditText").getOneNodeInfo(10000); let input_tips = textMatch(".*说点什么.*").getOneNodeInfo(10000); if (input_selectors || input_tips) { if (input_tips) { input_tips.click(); sleep(4000); input_selectors = clz("android.widget.EditText").getOneNodeInfo(10000); } if (input_selectors.inputText(words)) { logd('评论内容 "' + words + '" 输入成功, 准备发送'); log.log_detail = '评论内容 "' + words + '" 输入成功, 准备发送'; dynamicData.deviceLog(true, log); let send = text("发送").getOneNodeInfo(10000); if (send) { send.click(); logd('评论完成, 继续浏览'); log.log_detail = '评论完成, 继续浏览'; log.operate_type = 9; dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); actions.prototype.go_back(1); delete log.operate_type; result = true; } } } return result; } /** * description 获取用户账号信息 * @param dom {object} : 头像节点 * @param platform {number} : 平台 * @return {object} : 返回用户账号信息 */ actions.prototype.getUserInfo = function (dom, platform) { let startNum = 3; //重试次数 let user = {id: '', nickname: ''}; //账号信息 let num = 0; if (dom) { let clickResult = dom.click(); if (!clickResult) dom.click(); logd('准备进入用户主页'); dynamicData.deviceLog(true, {log_detail: '准备进入用户主页'}); } sleep(2 * 1000); while (num < startNum) { try { if (platform === 1) { //抖音 let idSelector = textMatch(".*抖音号.*").getOneNodeInfo(8 * 1000); let nameSelector = descMatch(".*复制名字.*").getOneNodeInfo(8 * 1000); if (idSelector) user.id = idSelector.text.slice(4); if (nameSelector) user.nickname = nameSelector.text; } else if (platform === 2) { //小红书 let idSelectors = textMatch(".*小红书号.*").getOneNodeInfo(8 * 1000); if (idSelectors) { if (idSelectors.text.includes(":")) { user.id = idSelectors.text.slice(5); } else { user.id = idSelectors.text.slice(4); } } let nameSelectors = depth(16).drawingOrder(9).clz("android.widget.TextView").getOneNodeInfo(8 * 1000); if (nameSelectors) user.nickname = nameSelectors.text; } else if (platform === 3) { //快手 let idSelectors = id("com.smile.gifmaker:id/profile_user_kwai_id").getOneNodeInfo(10 * 1000); if (idSelectors) { user.id = idSelectors.text.slice(4); user.nickname = id("com.smile.gifmaker:id/user_name_tv").getOneNodeInfo(10 * 1000).text; } } if (user.id !== '') { logd('已获取用户账号信息'); let log = { log_detail: '已获取用户账号信息', operate_type: 12 } dynamicData.deviceLog(true, log); dynamicData.insertTrace(log); break; } } catch (e) { logd('获取用户账号失败:' + e); dynamicData.deviceLog(true, {log_detail: '获取用户账号失败:' + e}); } num++; } return user; } /** * description 获取视频地址 * @param platform {number} : 平台 * @return {object} : 返回地址信息 */ actions.prototype.getVideoLink = function (platform) { try { let shareDesc = descMatch(".*分享.*").getOneNodeInfo(8000); let shareId = id("com.smile.gifmaker:id/forward_icon").getOneNodeInfo(8000); if (shareDesc || shareId) { if (platform === 3) { shareId.click(); } else { shareDesc.click(); } sleep(3000); let share = [textMatch(".*复制链接.*").getOneNodeInfo(8000), textMatch(".*链接分享.*").getOneNodeInfo(10000), textMatch(".*分享至.*").pkg("com.ss.android.ugc.aweme").getOneNodeInfo(8000)]; for (let i = 0; i < share.length; i++) { if (share[i]) { share[i].parent().click(); sleep(2000); let content = utils.getClipboardText(); if (content) { let index = content.lastIndexOf("http"); let link = content.slice(index); return link; } else { return null; } } } } } catch (e) { logd('获取视频地址失败:' + e); dynamicData.deviceLog(false, {log_detail: '获取视频地址失败:' + e}); return null; } } /** * description 获取作品信息 * @param platform {number} : 平台 * @return {object} : 返回节点信息 */ actions.prototype.getVideoInfo = function (platform) { let startNum = 3, info = {}; //重试次数, 节点信息 let num = 0; while (num < startNum) { try { switch (platform) { case 1: //抖音 info.nameSelector = id("com.ss.android.ugc.aweme:id/title").getOneNodeInfo(10 * 1000); //用户名称 info.postSelector = id("com.ss.android.ugc.aweme:id/desc").getOneNodeInfo(10 * 1000); //作品名称 info.avatarSelector = id("com.ss.android.ugc.aweme:id/user_avatar").getOneNodeInfo(10 * 1000); //头像 info.commentSelector = id("com.ss.android.ugc.aweme:id/comment_container").getOneNodeInfo(10 * 1000); // 评论按钮 info.commentCountSelector = id("com.ss.android.ugc.aweme:id/comment_container").getOneNodeInfo(10 * 1000).nextSiblings()[0].child(0); //评论数 break; case 2: //小红书 info.nameSelector = id("com.xingin.xhs:id/matrixNickNameView").getOneNodeInfo(10 * 1000); info.postSelector = id("com.xingin.xhs:id/noteContentText").getOneNodeInfo(10 * 1000); info.avatarSelector = id("com.xingin.xhs:id/matrixAvatarView").getOneNodeInfo(10 * 1000); info.commentSelector = id("com.xingin.xhs:id/commentLayout").getOneNodeInfo(10 * 1000); info.commentCountSelector = id("com.xingin.xhs:id/commentLayout").getOneNodeInfo(10 * 1000).child(1); break; case 3: //快手 info.nameSelector = id("com.smile.gifmaker:id/user_name_text_view").getOneNodeInfo(10 * 1000); info.postSelector = id("com.smile.gifmaker:id/element_caption_label").getOneNodeInfo(10 * 1000); info.avatarSelector = id("com.smile.gifmaker:id/follow_avatar_view").getOneNodeInfo(10 * 1000); info.commentSelector = id("com.smile.gifmaker:id/comment_icon").getOneNodeInfo(10 * 1000); info.commentCountSelector = id("com.smile.gifmaker:id/comment_count_view").getOneNodeInfo(10 * 1000); } if (info.nameSelector && info.postSelector && info.avatarSelector && info.commentSelector && info.commentCountSelector) { break; } else { info = null; } } catch (e) { info = null; } num++; } return info; } /** * description 随机翻页 */ actions.prototype.randomSwiper = function () { let max_swiperTimes = random(1, 3); //翻页次数 let swiperTimes = 0; while (swiperTimes < max_swiperTimes) { swiper.pageSwiper(); //翻页 logd('随机翻页第' + (swiperTimes + 1) + '次'); let log = {log_detail: '随机翻页第' + (swiperTimes + 1) + '次', operate_type: 15}; dynamicData.deviceLog(false, log); dynamicData.insertTrace(log); swiperTimes++; sleep(random(4000, 6000)); } } /** * description 视频翻页 * @param log {object} : 日志参数组 */ actions.prototype.videoSwiper = function (log) { let logInfo = log ? log : {}; logInfo.log_detail = '视频翻页'; logInfo.operate_type = 15; swiper.pageSwiper(); logd('视频翻页'); dynamicData.deviceLog(false, logInfo); // dynamicData.insertTrace(logInfo); } /** * description 脚本异常日志 * @param log_detail {string} : 日志明细 */ actions.prototype.exceptionLog = function (log_detail) { let error = { log_detail: log_detail, operate_type: 16 } logd(error); dynamicData.deviceLog(false, error); dynamicData.insertTrace(error); } /** * description 自定义返回函数 * @param page {number} : 返回页数 */ actions.prototype.go_back = function (page) { let count = 0; while (count < page) { back(); count++; sleep(3500); } } /** * 分发数据给对应设备 * @param deviceNos {string} : 设备信息 * @param data {string} : 数据 * @param separator {string} : 数据分隔符 * @return {string} : 返回当前设备分配的数据 */ actions.prototype.distributeDataToDevices = function (deviceNos, data, separator) { let deviceNo = ecloud.getDeviceNo(); //设备编号 let devicesArray = deviceNos.split(","); let dataArray = data.split(separator); for (let i = 0; i < devicesArray.length; i++) { if (devicesArray[i] === deviceNo && dataArray[i]) { return dataArray[i]; } } } /** * 数据按指定字符分割成数组 * @param data {string} : 数据 * @param separator {string} : 分割符 * @return {array} : 返回数据 */ actions.prototype.splitData = function (data, separator) { let dataArray = data.split(separator); let filterArray = dataArray.filter(function (value) { return value !== undefined && value !== null && value !== ''; }); return filterArray; } module.exports = new actions();