autojs编写的网易云音乐和视频搜索脚本源代码免费分享开源

说明

本文提供的代码仅供参考。不建议用于生产环境。
可能有些地方在最新版本的Auto.js上面需要做修改,才能运行。

Auto.js简介

Auto.js是利用安卓系统的“辅助功能”实现类似于按键精灵一样,可以通过代码模拟一系列界面动作的辅助工作。
与“按键精灵”不同的是,它的模拟动作并不是简单的使用在界面定坐标点来实现,而是类似与win一般,找窗口句柄来实现的。

Auto.js使用JavaScript作为脚本语言,目前使用Rhino 1.7.7.2作为脚本引擎,支持ES5与部分ES6特性。

推荐教程

Auto.js Pro安卓全分辨率免ROOT引流脚本开发视频教程(HD超清1080p)

开发文档

Auto.js Pro开发文档
文档尚在完善中,可能有文档描述和代码实际行为有出入的情况。

为什么要使用Auto.js Pro开发脚本,有什么特点?

吸引我使用Auto.js Pro的原因有很多。最主要的几个原因是:

  • Auto.js Pro能开发免ROOT的安卓脚本
  • Auto.js Pro基于节点操作,能开发全分辨率的脚本,自动适配各种安卓机型
  • Auto.js Pro丰富的UI组件,能自定义各种样式的安卓界面
  • Auto.js Pro使用的javascript的语法比较优雅,代码可读性强
  • Auto.js Pro的命令库非常的丰富,接口比较多
  • Auto.js Pro脚本文件体积比较小。1000行的代码,打包后的apk文件只有3-5M,还没有广告

示例代码

"ui";
 //此代码由飞云脚本圈整理提供(www.feiyunjs.com)
var bgcolor = "#ffffff";
var color = "#000000";
ui.statusBarColor(color);

/***************图片***** */
var img_path = "/sdcard/Download/img2/";
files.createWithDirs(img_path);
/***************音乐*****/
var music_list = [];
var music_source = ["tencent","netease","kugou","baidu","xiami"];
var music_page = 1;
var music_word = "";
var music_flag1 = true;

ui.layout(
|     <drawer id="drawer">
        <vertical>
            <appbar bg={color}>
                <toolbar id="toolbar" h="30" title="" />
                <tabs id="tabs" h="30" />
            </appbar>
            <viewpager id="viewpager">
                <!-- 第一页内容-->
                <frame>
                    <vertical >
                        <horizontal bg={bgcolor} alpha="1" h="45">
                            <input id="input" hint="搜索图片" layout_weight="1" textSize="16sp" marginLeft="16" />
                            <button id="search" text="搜索" w="60" h="40" margin="0,0,0,-50" style="Widget.AppCompat.Button.Borderless.Colored" />
                            <button id="last" text="⬅" w="70" margin="0,0,0,-20" style="Widget.AppCompat.Button.Borderless.Colored" />
                            <button id="rand" text="随机" w="70" margin="0,-10" style="Widget.AppCompat.Button.Borderless.Colored" />
                            <button id="next" text="➡" w="70" margin="0,0" style="Widget.AppCompat.Button.Borderless.Colored" />
                        </horizontal  >
                        <list id="icons" spanCount="1" bg={bgcolor}>
                            <img id="image" src="{{this}}" w="*" h="*" margin="-0,0" tint="#00ffffff" />
                        </list>
                        <text text="请稍等" textSize="30sp" textColor="#000000" />
                    </vertical>
                </frame>
                <!-- 第二页内容-->
                <frame>
                    <vertical bg={bgcolor}>
                        <horizontal>
                            <input id="music_search_input" hint="搜索音乐" layout_weight="1" textSize="16sp" marginLeft="16" />
                            <button id="music_search_button" text="搜索" textSize="20sp" w="100" h="50" margin="-5,0,0,-80" style="Widget.AppCompat.Button.Borderless.Colored" />
                            <spinner id="music_sp1" textSize="20sp" w="100" h="50" margin="-4,-40,0,0" entries="QQ|网易|酷狗|百度|虾米"/>
                        </horizontal>
                        <frame>
                            <list id="music_list">
                                <horizontal>
                                    <linear bg="?selectableItemBackground" w="1000">
                                        <img src="{{pic}}" h="50" w="50" />
                                        <vertical h="50">
                                            <text text="{{name}}" textSize="15sp" textColor="#000000" h="20" w="*" margin="10,0,5,10" />
                                            <text text="{{artist}}" textSize="10sp" h="20" w="*" margin="0,0,0,10" />
                                        </vertical>
                                    </linear>
                                </horizontal>
                            </list>
                        </frame>
                    </vertical>
                </frame>
                <!-- 第三页内容-->
                <frame>
                    <vertical bg={bgcolor}>
                        <horizontal h="45">
                            <input id="search_input" layout_weight="1" hint="搜索视频" textSize="16sp" marginLeft="16" />
                            <button id="search_button" text="搜索" textSize="20sp" w="100" h="50" margin="-5,0,0,-80" style="Widget.AppCompat.Button.Borderless.Colored" />
                        </horizontal>
                        <frame>
                            <list id="list">
                                <horizontal>
                                    <linear bg="?selectableItemBackground" w="1000">
                                        <img src="{{icon}}" h="50" w="50" tint="#000000" />
                                        <text text="{{name}}" textSize="15sp" h="40" w="*" textColor="#000000" margin="10,10" />
                                    </linear>
                                </horizontal>
                            </list>
                        </frame>
                    </vertical>
                </frame>
            </viewpager>
        </vertical>
        <vertical layout_gravity="left" bg="#ffffff" w="280">
            <img src="http://pic1.16pic.com/00/52/10/16pic_5210406_b.jpg" h="200" scaleType="centerCrop" />
            <list id="menu">
                <horizontal bg="?selectableItemBackground" w="*">
                    <img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}" />
                    <text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center" />
                </horizontal>
            </list>
        </vertical>
    </drawer>
);

/*******************************ui模板******************************** */
//创建选项菜单(右上角)
ui.emitter.on("create_options_menu", menu => {
    menu.add("设置");
    menu.add("关于");
});
//监听选项菜单点击
ui.emitter.on("options_item_selected", (e, item) => {
    switch (item.getTitle()) {
        case "设置":
            toast("还没有设置");
            break;
        case "关于":
            alert("关于", "还没有关于");
            break;
    }
    e.consumed = true;
});
activity.setSupportActionBar(ui.toolbar);

//设置滑动页面的标题
ui.viewpager.setTitles(["图片", "音乐", "视频"]);
//让滑动页面和标签栏联动
ui.tabs.setupWithViewPager(ui.viewpager);

//让工具栏左上角可以打开侧拉菜单
ui.toolbar.setupWithDrawer(ui.drawer);

ui.menu.setDataSource([{
        title: "图片下载路径",
        icon: "@drawable/ic_android_black_48dp"
    },
    {
        title: "视频搜索说明",
        icon: "@drawable/ic_settings_black_48dp"
    },
    {
        title: "交流",
        icon: "@drawable/ic_favorite_black_48dp"
    },
    {
        title: "退出",
        icon: "@drawable/ic_exit_to_app_black_48dp"
    }
]);

ui.menu.on("item_click", item => {
    switch (item.title) {
        case "图片下载路径":
            alert(null, img_path);
            break;
        case "视频搜索说明":
            alert(null, "视频网页不稳定请耐心等待,\n也有可能出现点击搜索后什么结果也没有,但多试几次就行了");
            break;
        case "交流":
            qq = "1075056431"
            dialogs.confirm(null, "QQ:" + qq, function(i) {
                if (i) {
                    app.startActivity({
                        action: "android.intent.action.VIEW",
                        data: "mqqapi://card/show_pslcard?&uin=" + qq
                    });
                }
            });
            break;
        case "退出":
            ui.finish();
            break;
    }
});

/***************************百度图片******************************* */
function menu(url1) {
    let a = ["下载", "取消"];
    dialogs.select(null, a, function(i) {
        switch (i) {
            case 0:
                name = url1.replace(/\//g, "_");
                dirlist = files.listDir(img_path);
                let j;
                for (j = 0; j < dirlist.length; j++) {
                    if (dirlist[j] == name) {
                        break;
                    }
                }
                if (j == dirlist.length) {
                    threads.start(function() {
                        files.writeBytes(img_path + name, http.get(url1).body.bytes());
                        toast("已下载到" + img_path);
                    });
                } else {
                    toast("图片已存在")
                }
                break;
        }
    });
}
/*queryEnc":"%E4%BA%8C%E6%AC%A1%E5%85%83%E5%A3%81%E7%BA%B8",  
  "displayNum":107267,  
    "bdIsClustered" : "1",  
      "listNum":1978,   
       "bdFmtDispNum" : "107267",   
        "bdSearchTime" : "",   
         "isNeedAsyncRequest":0,
         "data":[{"thumbURL":"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpo*/
var top = 0;
var word = "壁纸"
var listNum;
//开始加载图片
loadimg(word, top++);

ui.next.click(() => {
    loadimg(word, top++);
});

ui.rand.on("click", function() {
    top = random(0, parseInt(listNum / 30));
    loadimg(word, top++);
});
ui.last.click(() => {
    if (top < 2) {
        return;
    }
    top--;
    loadimg(word, top - 1);
});
ui.search.on("click", function() {
    var text = ui.input.text();
    if (text.length == 0) {
        return;
    }
    word = text;
    top = 0;
    loadimg(word, top++);
});

ui.icons.on("item_click", function(img3) {
    menu(img3);
    //toast(img3);
    setClip(img3);
});




function loadimg(word, num) {
    newimgs = []
    threads.start(function() {
        //log("\n------------------" + num + "--------------------------\n")
        newimgs1 = getimages(word, num++);
        for (i in newimgs1) {
            newimgs.push(newimgs1[i]);
        }
        //log(newimgs);
    });
    ui.icons.setDataSource(newimgs);
}



function getimages(word, num) {
    pn = num * 30;
    url = "https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fr=&sf=1&fmq=1526269427171_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=" + word + "&pn=" + pn;
    htmltext = http.get(url).body.string();
    //htmltext = "sdg,kpsgffsd4,;,565;fsd45app.setData('imgData',{a:1,b:2,c:3});fas.;dffsd"
    //log(htmltext);
    //图库的正则表达式
    /*app.setData('imgData',*/
    thumbzhz = /app.setData\('imgData',.+}/g;
    //log(thumbzhz);
    htmltext = htmltext.match(thumbzhz);
    if (htmltext == null) {
        toast("没有图了");
        top--;
        return null;
    }
    imgstr = htmltext[0].substr("app.setData('imgData',".length, htmltext[0].length);
    //log(" var imgjson = ["+imgstr+'];');
    eval(" var imgjson = [" + imgstr + '][0];');
    //log(imgjson);
    len = imgjson.data.length; //数量
    listNum = imgjson.listNum;
    images = [];
    for (i = 0; i < len - 1; i++) {
        images[i] = imgjson.data[i].objURL;
    }
    return images;
}

/***************************视频**************************** */
search_list = [];

ui.list.on("item_click", function(athis) {
    //log(athis)
    if (athis.url == null && athis.name == "返回") {
        ui.list.setDataSource(search_list);
        return;
    }
    if (athis.url.indexOf("http://okzyzy.cc/") == -1) {
        app.openUrl(athis.url);
        setClip(athis.url);
        return;
    }
    let video_list = [{
        icon: "@drawable/ic_keyboard_backspace_black_48dp",
        name: "返回",
        url: null
    }];
    threads.start(function() {
        let temp_arr = videoDetails(athis.url);
        for (i in temp_arr) {
            video_list.push({
                icon: "@drawable/ic_send_black_48dp",
                name: temp_arr[i].name,
                url: temp_arr[i].url
            });
        } //log(video_list)
    }).join();
    ui.list.setDataSource(video_list);
});

ui.search_button.on("click", function() {
    search(ui.search_input.text());
})

function search(word) {
    threads.start(function() {
        let temp_arr = searchVideo(word);
        len = search_list.length;
        for (i = 0; i < len; i++) {
            search_list.pop();
        }
        if (temp_arr.length == 0) {
            toast("未找到该视频");
        }
        for (i in temp_arr) {
            search_list.push({
                icon: "@drawable/ic_play_circle_filled_white_black_48dp",
                name: temp_arr[i].name,
                url: temp_arr[i].url
            });
        }

        //log(search_list);
    });
    ui.list.setDataSource(search_list);

}
//


function videoDetails(url) {
    html = http.get(url).body.string();
    while (html.length < 2000) {
        sleep(1000);
        html = http.get(url).body.string();
    }
    //html = "<li><input type=\"checkbox\" name=\"copy_sel\" value=\"http://youku.cdn-iqiyi.com/20180425/9984_5e777e33/index.m3u8\" checked=\"\" />第01464654集$http://youku.cdn-iqiyi.com/20180425/9984_5e777e33/index.m3u8</li> <li><input type=\"checkbox\" name=\"copy_sel\" value=\"http://youku.cdn-iqiyi.com/20180425/9984_5e777e33/index.m3u8\" checked=\"\" />第01集$http://youku.cdn-iqiyi.com/20180425/9984_5e777e33/index.m3u8</li> ";
    zhez1 = /checked=\"\" \/>[^$]*.http[^<]*/g //链接和名称
    //log(html.length)
    html = html.match(zhez1);
    //log(html);
    result = [];
    for (i in html) {
        temp_arr = html[i].split('$');
        result.push({
            name: temp_arr[0].substr("/checked=\"\" \/>".length - 1),
            url: temp_arr[1]
        });
    }
    //log(result);
    return result;
}

function searchVideo(word) {
    url = "http://okzyzy.cc/index.php?m=vod-search&wd=" + word;
    html = http.get(url).body.string();
    while (html.length < 3000) {
        sleep(200);
        html = http.get(url).body.string();
    }
    //log(html.length)
    //html = "<li><span class=\"tt\"></span><span class=\"xing_vb4\"><a href=\"/?m=vod-detail-id-10653.html\" target=\"_blank\">环太平洋:雷霆再起BD</a></span> <span class=\"xing_vb5\">科幻片</span> <span class=\"xing_vb6\">2018-06-10</span></li></ul> <li><span class=\"tt\"></span><span class=\"xing_vb4\"><a href=\"/?m=vod-detail-id-10653.html\" target=\"_blank\">环太平洋:雷霆再起BD</a></span> <span class=\"xing_vb5\">科幻片</span> <span class=\"xing_vb6\">2018-06-10</span></li></ul> <li><span class=\"tt\"></span><span class=\"xing_vb4\"><a href=\"/?m=vod-detail-id-10653.html\" target=\"_blank\">环太平洋:雷霆再起BD</a></span> <span class=\"xing_vb5\">科幻片</span> <span class=\"xing_vb6\">2018-06-10</span></li></ul> "
    zhez1 = /class=\"xing_vb4\"><a href=[^<]*<\/a><\/span>/g //链接和名称
    //log(html)
    html = html.match(zhez1);
    //log(html)
    zhez2 = /[^"]*(?=.html)/g //链接
    zhez3 = /[^>]*(?=<\/a>)/g //名称
    result = [];
    //log(html)
    for (i in html)
        result.push({
            name: html[i].match(zhez3)[0],
            url: "http://okzyzy.cc/" + html[i].match(zhez2)[0] + ".html"
        });

    //log(result);
    return result;
}
/***************************音乐************************ */

threads.start(function() {
    netease_hot();
});

ui.music_list.setDataSource(music_list);
ui.music_search_button.on("click", function() {
    music_flag1 = false;
    music_page = 1;
    threads.start(function() {
        var len = music_list.length;
        for (let i = 0; i < len; i++) {
            music_list.pop();
        }
        var i = ui.music_sp1.getSelectedItemPosition();
        toast(music_source[i]);
        getMusic(ui.music_search_input.text(), music_source[i], music_page, 20);
    });
});

ui.music_list.on("item_click", function(m) {
    //toast(m.id);
    if (m.id == 0) {
        threads.start(function() {
            getMusic(ui.music_search_input.text(), m.source, ++music_page, 10);
        });
    } else {
        threads.start(function() {
            let music_d;
            if (music_flag1) {
                music_d = download_music(m.id, "netease");
            } else {
                music_d = download_music(m.id, m.source);
            }
            //下载
            setClip(m.name + " - " + m.artist);
            app.openUrl(music_d.url);

        });
    }
});

/**
 * 获取搜索结果
 * @param {关键字} word 
 * @param {网站源:baidu,tencent,netease,xiami,kugou} source 
 * @param {第几页} page 
 * @param {每页个数} num 
 */
function getMusic(word, source, page, num) {
    if (!word) {
        return;
    }
    url = "https://y.xuelg.com/api.php?callback=jQuery111305475340320325446_1529241763041&types=search&count=" + num + "&source=" + source + "&pages=" + page + "&name=" + word;
    let m = http.get(url).body.string();
    eval("m = " + m.substr(m.indexOf('(')));
    //删除加载更多
    music_list.pop();
    if (m.length == 0) {
        toast("没有更多了");
    }
    for (i in m) {
        url = "https://y.xuelg.com/api.php?callback=jQuery111306503234710876828_1529243003818&types=" + "pic" + "&id=" + m[i].pic_id + "&source=" + m[i].source;
        mstr = http.get(url).body.string();
        eval(mstr = mstr.substr(mstr.indexOf('(')));
        mstr = mstr.replace(/\\/g, "");
        m[i]["pic"] = mstr.match(/http[^"]*/g)[0];
        //log(m[i].name);
        music_list.push(m[i]);
    }
    //插入加载更多提示
    music_list.push({
        name: "                              加载更多",
        pic: "#ffffff",
        artist: "",
        id: "0"
    });
    //log(m);
    return m;
}
/**
 * 获取下载地址
 * @param {歌曲id} id 
 * @param {网站源:} source 
 */
function download_music(id, source) {
    url = "https://y.xuelg.com/api.php?callback=jQuery111306503234710876828_1529243003818&types=" + "url" + "&id=" + id + "&source=" + source;
    mstr = http.get(url).body.string();
    eval(mstr = mstr.substr(mstr.indexOf('(')));
    //log(mstr);
    mstr = mstr.replace(/\\/g, "");
    m = [];
    try {
        m["url"] = mstr.match(/url\":\"[^"]*/g)[0].match(/http.*/g)[0];
        m["size"] = mstr.match(/size\":[^,]*/g)[0].match(/\d.*/g)[0];
        m["br"] = mstr.match(/br\":[^}]*/g)[0].match(/\d.*/g)[0];
    } catch (e) {
        log(e)
    }
    return m;
}
/**
 * 
 * 网易云热歌榜
 */
function netease_hot() {
    url = "https://y.xuelg.com/api.php?callback=jQuery111305475340320325446_1529241763034&types=playlist&id=3778678";
    hot = http.get(url).body.string();
    hot = hot.match(/"tracks":.*/g)[0];
    eval("hot = " + hot.substr(9).replace(/,"trackIds".*/g, ""));
    for (i in hot) {
        music_list.push({
            id: hot[i].id,
            name: hot[i].name,
            artist: hot[i].ar[0].name,
            pic: hot[i].al.picUrl
        });

    }
    return hot;
}
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Studio是一款强大的集成开发环境,可以用来开发Android应用程序。大作业记事本的源代码是一个基于Android Studio的项目,它包含了一系列的Java代码和XML布局文件。 该项目的主要功能是可以创建、编辑和保存用户的笔记。用户可以在应用程序中输入文本内容,并且可以给每个笔记加上标题和日期。此外,还可以对已保存的笔记进行编辑和删除操作。另外,该记事本应用还提供了搜索功能,用户可以通过关键词查找特定的笔记。 在Android Studio中,该项目包含了多个Activity、Fragment、Adapter等组件。其中,每个笔记的界面是通过一个Activity来展示,用户可以在这个界面上进行编辑操作。而笔记列表则通过一个Fragment来展示,用户可以在其中浏览所有的笔记。至于保存和展示笔记列表的数据交互,则借助了一个自定义的Adapter来完成。 此外,项目中还包含了各种事件监听和响应处理的代码,例如用户输入文本、点击按钮等等。这些代码可以实现用户在应用程序中的交互体验,使用户可以方便地使用记事本应用。 总的来说,大作业记事本的源代码是一个涵盖了Android应用开发的各个方面的项目。它包含了用户界面的设计和布局、数据的存储和交互、以及用户操作的响应等等。通过学习这个项目的源代码,可以更深入地理解Android应用程序的开发过程和技术细节。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值