-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path图片、音乐、视频下载.js
552 lines (513 loc) · 19.5 KB
/
图片、音乐、视频下载.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
"ui";
var bgcolor = "#ffffff";
var color = "#000000";
ui.statusBarColor(color);
/***************图片***** */
var img_path = "/sdcard/Download/img2/";
var music_down="/sdcard/music/";
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 20" 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 0 0 -10" style="Widget.AppCompat.Button.Borderless.Colored" />
<button id="next" text="➡" w="70" margin="0 0 0 -20" 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);
}
//下载
download(m.name + " - " + m.artist,music_d.url)
});
}
});
function download(name,url1) {
let a = ["下载","播放", "取消"];
dialogs.select(name, a, function(i) {
switch (i) {
case 0:
dirlist = files.listDir(music_down);
let j;
for (j = 0; j < dirlist.length; j++) {
if (dirlist[j] == name+".mp3") {
break;
}
}
if (j == dirlist.length) {
threads.start(function() {
toast(name+" 开始下载。。。");
files.writeBytes(music_down+"/"+name+".mp3", http.get(url1).body.bytes());//
toastLog(name+" 下载成功!");
});
} else {toast("音乐已存在!")}
break;
case 1:
if(files.exists(music_down+"/"+name+".mp3")){
toast(name);
//调用系统播放器
app.viewFile(music_down+"/"+name+".mp3");
}else{toast("还没有下载 ⊙ω⊙");}
break;
}
});
}
/**
* 获取搜索结果
* @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;
}