"ui";
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(
);
/*******************************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 = "
第01464654集$http://youku.cdn-iqiyi.com/20180425/9984_5e777e33/index.m3u8 第01集$http://youku.cdn-iqiyi.com/20180425/9984_5e777e33/index.m3u8 ";
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 = "环太平洋:雷霆再起BD 科幻片 2018-06-10 环太平洋:雷霆再起BD 科幻片 2018-06-10 环太平洋:雷霆再起BD 科幻片 2018-06-10 "
zhez1 = /class=\"xing_vb4\"><\/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;
}