-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathaddon.py
1527 lines (1438 loc) · 56.9 KB
/
addon.py
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
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
from xbmcswift2 import Plugin, xbmcgui, xbmc, xbmcaddon, xbmcplugin
#from xbmcswift2 import Actions
import requests
from bs4 import BeautifulSoup
import xbmcgui
import base64
import json
import urllib2
import sys
import HTMLParser
import re
import time
def unix_to_data(uptime,format='data'):
if len(str(uptime)) > 10:
uptime = str(uptime)[:-(len(str(uptime))-10)]
uptime = float(uptime)
time_local = time.localtime(uptime)
if format == 'data' or format == 'zhdata' or format == 'datatime' or format == 'zhdatatime' or format == 'time' or format == 'zhtime':
if format == 'data':
uptime = time.strftime('%Y-%m-%d',time_local)
if format == 'zhdata':
uptime = time.strftime('%Y年%m月%d日',time_local)
if format == 'datatime':
uptime = time.strftime('%Y-%m-%d %H:%M:%S',time_local)
if format == 'zhdatatime':
uptime = time.strftime('%Y年%m月%d日 %H时%M分%S秒',time_local)
if format == 'time':
uptime = time.strftime('%H:%M:%S',time_local)
if format == 'zhtime':
uptime = time.strftime('%H时%M分%S秒',time_local)
else:
uptime = time.strftime(format,time_local)
return uptime
#超过10000换算
def zh(num):
if int(num) >= 100000000:
p = round(float(num)/float(100000000), 1)
p = str(p) + '亿'
else:
if int(num) >= 10000:
p = round(float(num)/float(10000), 1)
p = str(p) + '万'
else:
p = str(num)
return p
def get_real_url(url):
rs = requests.get(url,headers=headers,timeout=2)
return rs.url
def unescape(string):
string = urllib2.unquote(string).decode('utf8')
quoted = HTMLParser.HTMLParser().unescape(string).encode('utf-8')
#转成中文
return re.sub(r'%u([a-fA-F0-9]{4}|[a-fA-F0-9]{2})', lambda m: unichr(int(m.group(1), 16)), quoted)
plugin = Plugin()
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36'}
cache = plugin.get_storage('cache')
his = plugin.get_storage('his')
#初始化api
# if 'myqq' not in cache:
# cache['myqq'] = ''
# if 'my163' not in cache:
# cache['my163'] = ''
# if 'my163num' not in cache:
# cache['my163num'] = ''
# if 'myqqnum' not in cache:
# cache['myqqnum'] = ''
# xbmcplugin.setContent(int(sys.argv[1]), 'musicvideos')
netease_api = xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusicapiurl')
qqmusic_api = xbmcplugin.getSetting(int(sys.argv[1]), 'qqmusicapiurl')
migu_api = xbmcplugin.getSetting(int(sys.argv[1]), 'miguapiurl')
@plugin.cached(TTL=1)
def get_html(url,cookie=''):
if cookie != '':
h = headers
h['cookie'] = cookie
r = requests.get(url,headers=h)
else:
r = requests.get(url,headers=headers)
return r.text
########################################### 为你推荐歌单api ###########################################
def one63weinituijian():
gedans = []
r = get_html(netease_api + '/recommend/resource','MUSIC_U=' + xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusicu'))
j = json.loads(r)
if j['code'] == 200:
glist = j['recommend']
for index in range(len(glist)):
desc = ''
if glist[index]['copywriter']:
desc += glist[index]['copywriter'].encode('utf-8')
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = glist[index]['picUrl']
gd['url'] = 'https://music.163.com/#/playlist?id=' + str(glist[index]['id'])
gd['info'] = {'plot':zh(glist[index]['playcount']) + ' 播放 · ' + zh(glist[index]['trackCount']) + ' 首歌\n\n' + desc}
gd['info']['cast'] = [(glist[index]['creator']['nickname'],unix_to_data(glist[index]['createTime']) + u'创建')]
gedans.append(gd)
return gedans
else:
if j['code'] == 301:
dialog = xbmcgui.Dialog()
dialog.notification('请求失败','请尝试更换MUSIC_U', xbmcgui.NOTIFICATION_INFO, 5000)
def qqweinituijian():
gedans = []
r = get_html(qqmusic_api + '/recommend/playlist/u')
j = json.loads(r)
glist = j['data']['list']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['title']
gd['thumb'] = glist[index]['cover']
gd['url'] = 'https://y.qq.com/n/yqq/playlist/' + str(glist[index]['content_id']) + '.html'
gd['info'] = {'plot':zh(glist[index]['listen_num']) + ' 播放量'}
gd['info']['cast']= [glist[index]['username']]
gedans.append(gd)
return gedans
########################################### 日推api ###########################################
def one63ritui():
gedans = []
r = get_html(netease_api + '/recommend/songs','MUSIC_U='+xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusicu'))
j = json.loads(r)
if j['code'] == 200:
gedans = []
glist = j['recommend']
# songs = ''
# for index in range(len(glist)):
# if index == 0:
# songs += str(glist[index]['id'])
# else:
# songs += ',' + str(glist[index]['id'])
# #mp3 url
# r2 = get_html(netease_api + '/song/url?id=' + songs)
# j2 = json.loads(r2)
# mp3urls = j2['data']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = glist[index]['album']['picUrl']
# gdurl = ''
# for i in range(len(mp3urls)):
# if int(mp3urls[i]['id']) == int(glist[index]['id']):
# gdurl = mp3urls[i]['url']
# if gdurl == '':
# gd['name'] += ' - [无版权]'
if xbmcplugin.getSetting(int(sys.argv[1]), 'httpswitch') == 'true':
gdurl = 'http'
else:
gdurl = 'https'
gdurl += '://music.163.com/song/media/outer/url?id='+str(glist[index]['id'])+'.mp3'
gd['url'] = gdurl
gd['info'] = {'title':glist[index]['name'],'album':glist[index]['album']['name'],'artist':glist[index]['artists'][0]['name'],'mediatype':'song'}
#gd['url'] = j2['data'][0]['url']
gedans.append(gd)
return gedans
else:
if j['code'] == 301:
dialog = xbmcgui.Dialog()
dialog.notification('请求失败','请尝试更换网易云音乐的 MUSIC_U', xbmcgui.NOTIFICATION_INFO, 5000)
def qqritui():
gedans = []
r = get_html(qqmusic_api + '/recommend/daily',xbmcplugin.getSetting(int(sys.argv[1]), 'qqmusiccookie'))
j = json.loads(r)
if j['result'] == 100:
glist = j['data']['songlist']
songs= ''
for index in range(len(glist)):
if index == 0:
songs += glist[index]['songmid']
else:
songs += ',' + glist[index]['songmid']
r1 = get_html(qqmusic_api + '/song/urls?id=' + songs)
j1 = json.loads(r1)
mp3urls = j1['data']
for index in range(len(glist)):
if glist[index]['songmid'] in mp3urls:
gd ={}
gd['name'] = glist[index]['songname']
gd['thumb'] = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000' + glist[index]['albummid'] + '.jpg'
gd['url'] = mp3urls[glist[index]['songmid']]
gd['info'] = {'title':glist[index]['songname'],'album':glist[index]['albumname'],'artist':glist[index]['singer'][0]['name'],'mediatype':'song'}
gedans.append(gd)
return gedans
else:
if j['result'] == 301:
dialog = xbmcgui.Dialog()
dialog.notification('请求失败','请尝试更换QQ音乐的 cookie', xbmcgui.NOTIFICATION_INFO, 5000)
########################################### 我的歌单api ###########################################
def one63gedan():
gedans = []
r = get_html(netease_api + '/user/playlist?uid=' + str(xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusicuid')))
j = json.loads(r)
glist = j['playlist']
for index in range(len(glist)):
desc = ''
if glist[index]['description']:
desc += glist[index]['description'].encode('utf-8')
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = glist[index]['coverImgUrl']
gd['url'] = 'https://music.163.com/#/playlist?id=' + str(glist[index]['id'])
gd['info'] = {'plot':zh(glist[index]['playCount']) + ' 播放 · ' + zh(glist[index]['trackCount']) + ' 首歌\n\n' + desc}
gd['info']['cast'] = [(glist[index]['creator']['nickname'],unix_to_data(glist[index]['createTime']) + u'创建')]
gedans.append(gd)
return gedans
def qqgedan():
gedans = []
r = get_html(qqmusic_api + '/user/songlist?id=' + str(xbmcplugin.getSetting(int(sys.argv[1]), 'qqmusicid')))
j = json.loads(r)
glist = j['data']['list']
for index in range(len(glist)):
if int(glist[index]['tid']) > 0:
gd ={}
gd['name'] = glist[index]['diss_name']
gd['thumb'] = glist[index]['diss_cover']
gd['url'] = 'https://y.qq.com/n/yqq/playlist/' + str(glist[index]['tid']) + '.html'
gd['info'] = {'plot':zh(glist[index]['listen_num']) + ' 播放 · ' + zh(glist[index]['song_cnt']) + ' 首歌'}
gd['info']['cast'] = [j['data']['creator']['hostname']]
gedans.append(gd)
return gedans
########################################### 推荐歌单api ###########################################
def one63tuijiangedan():
gedans = []
r = get_html(netease_api + '/personalized')
j = json.loads(r)
glist = j['result']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = glist[index]['picUrl']
gd['url'] = 'https://music.163.com/#/playlist?id=' + str(glist[index]['id'])
gd['info'] = {'plot':zh(glist[index]['playCount']) + ' 播放 · ' + zh(glist[index]['trackCount']) + ' 首歌\n\n' + glist[index]['copywriter'].encode('utf-8')}
gd['info']['cast'] = ['不知道是谁']
gedans.append(gd)
return gedans
def qqtuijiangedan():
gedans = []
r = get_html(qqmusic_api + '/recommend/playlist/')
j = json.loads(r)
glist = j['data']['list']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['title']
gd['thumb'] = glist[index]['cover_url_big']
gd['url'] = 'https://y.qq.com/n/yqq/playlist/' + str(glist[index]['tid']) + '.html'
gd['info'] = {'plot':zh(glist[index]['access_num']) + ' 播放量'}
gd['info']['cast']= [glist[index]['creator_info']['nick']]
gedans.append(gd)
return gedans
########################################### 歌单详细信息api ###########################################
def one63playlist(id):
gedans = []
r = get_html(netease_api + '/playlist/detail?id=' + str(id))
j = json.loads(r)
glist = j['playlist']['trackIds']
songs = ''
for index in range(len(glist)):
if index == 0:
songs += str(glist[index]['id'])
else:
songs += ',' + str(glist[index]['id'])
#mp3详情
r1 = get_html(netease_api + '/song/detail?ids=' + songs)
j1 = json.loads(r1)
mp3detail = j1['songs']
# #mp3 url
# r2 = get_html(netease_api + '/song/url?id=' + songs)
# j2 = json.loads(r2)
# mp3urls = j2['data']
# pDialog = xbmcgui.DialogProgress()
# pDialog.create('网易云音乐', '努力从母猪厂的土豆服务器偷mp3中...(0%)')
for index in range(len(mp3detail)):
# pDialog.update(int(100*(float(index)/float(len(mp3detail)))), '努力从母猪厂的土豆服务器偷mp3中...('+str(int(100*(float(index)/float(len(mp3detail)))))+'%)')
# #r2 = get_html(netease_api + '/song/url?id=' + str(mp3detail[index]['id']))
# #j2 = json.loads(r2)
gd ={}
gd['name'] = mp3detail[index]['name']
gd['thumb'] = mp3detail[index]['al']['picUrl']
# gdurl = ''
# for i in range(len(mp3urls)):
# if int(mp3urls[i]['id']) == int(mp3detail[index]['id']):
# gdurl = mp3urls[i]['url']
# if gdurl == '':
# gd['name'] += ' - [无版权]'
# gd['url'] = gdurl
if xbmcplugin.getSetting(int(sys.argv[1]), 'httpswitch') == 'true':
gd['url'] = 'http'
else:
gd['url'] = 'https'
gd['url'] += '://music.163.com/song/media/outer/url?id=' + str(mp3detail[index]['id']) + '.mp3'
gd['info'] = {'title':mp3detail[index]['name'],'album':mp3detail[index]['al']['name'],'artist':mp3detail[index]['ar'][0]['name'],'mediatype':'song'}
#gd['url'] = j2['data'][0]['url']
gedans.append(gd)
return gedans
def qqplaylist(id):
gedans = []
r = get_html(qqmusic_api + '/songlist?id=' + str(id))
j = json.loads(r)
glist = j['data']['songlist']
songs= ''
for index in range(len(glist)):
if index == 0:
songs += glist[index]['songmid']
else:
songs += ',' + glist[index]['songmid']
r1 = get_html(qqmusic_api + '/song/urls?id=' + songs)
j1 = json.loads(r1)
mp3urls = j1['data']
for index in range(len(glist)):
if glist[index]['songmid'] in mp3urls:
gd ={}
gd['name'] = glist[index]['songname']
gd['thumb'] = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000' + glist[index]['albummid'] + '.jpg'
gd['url'] = mp3urls[glist[index]['songmid']]
gd['info'] = {'title':glist[index]['songname'],'album':glist[index]['albumname'],'artist':glist[index]['singer'][0]['name'],'mediatype':'song'}
gedans.append(gd)
return gedans
########################################### 专辑详细信息api ###########################################
def one63album(id):
gedans = []
r = get_html(netease_api + '/playlist/detail?id=' + str(id))
j = json.loads(r)
glist = j['playlist']['trackIds']
songs = ''
for index in range(len(glist)):
if index == 0:
songs += str(glist[index]['id'])
else:
songs += ',' + str(glist[index]['id'])
#mp3详情
r1 = get_html(netease_api + '/song/detail?ids=' + songs)
j1 = json.loads(r1)
mp3detail = j1['songs']
# #mp3 url
# r2 = get_html(netease_api + '/song/url?id=' + songs)
# j2 = json.loads(r2)
# mp3url = j2['data']
for index in range(len(mp3detail)):
gd ={}
gd['name'] = mp3detail[index]['name']
gd['thumb'] = mp3detail[index]['al']['picUrl']
# gd['url'] = mp3url[index]['url']
if xbmcplugin.getSetting(int(sys.argv[1]), 'httpswitch') == 'true':
gd['url'] = 'http'
else:
gd['url'] = 'https'
gd['url'] += '://music.163.com/song/media/outer/url?id=' + str(mp3detail[index]['id']) + '.mp3'
gedans.append(gd)
return gedans
def qqalbum(id):
gedans = []
r = get_html(qqmusic_api + '/album/songs?albummid=' + str(id))
j = json.loads(r)
glist = j['data']['list']
songs= ''
for index in range(len(glist)):
if index == 0:
songs += glist[index]['mid']
else:
songs += ',' + glist[index]['mid']
r1 = get_html(qqmusic_api + '/song/urls?id=' + songs)
j1 = json.loads(r1)
mp3urls = j1['data']
for index in range(len(glist)):
if glist[index]['mid'] in mp3urls:
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000' + glist[index]['album']['mid'] + '.jpg'
gd['url'] = mp3urls[glist[index]['mid']]
gedans.append(gd)
return gedans
########################################### 歌手热门歌曲api ###########################################
def one63singer(id):
gedans = []
r = get_html(netease_api + '/artists?id=' + str(id))
j = json.loads(r)
glist = j['hotSongs']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = glist[index]['al']['picUrl']
#mp3 url
r2 = get_html(netease_api + '/song/url?id=' + str(glist[index]['id']))
j2 = json.loads(r2)
gd['url'] = j2['data'][0]['url']
gedans.append(gd)
return gedans
def qqsinger(id):
gedans = []
r = get_html(qqmusic_api + '/singer/songs?num=50&singermid=' + str(id))
j = json.loads(r)
glist = j['data']['list']
songs= ''
for index in range(len(glist)):
if index == 0:
songs += glist[index]['mid']
else:
songs += ',' + glist[index]['mid']
r1 = get_html(qqmusic_api + '/song/urls?id=' + songs)
j1 = json.loads(r1)
mp3urls = j1['data']
for index in range(len(glist)):
if glist[index]['mid'] in mp3urls:
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000' + glist[index]['album']['mid'] + '.jpg'
gd['url'] = mp3urls[glist[index]['mid']]
gedans.append(gd)
return gedans
########################################### 排行 ###########################################
def get_rank():
items = []
r1 = get_html(netease_api + '/toplist')
j1 = json.loads(r1)
one63list = j1['list']
for index in range(len(one63list)):
gd = {}
gd['name'] = u'网易云音乐 · '+ one63list[index]['name']
gd['thumb'] = one63list[index]['coverImgUrl']
gd['url'] = '163|' + str(one63list[index]['id'])
gd['desc'] = one63list[index]['description']
items.append(gd)
r2 = get_html(qqmusic_api + '/top/category')
j2 = json.loads(r2)
qqlist = j2['data']
for index in range(len(qqlist)):
listlist = qqlist[index]['list']
for i in range(len(listlist)):
if listlist[i]['topId'] != 201:
gd = {}
gd['name'] = u'QQ音乐 · '+ listlist[i]['label']
gd['thumb'] = listlist[i]['picUrl']
gd['url'] = 'qq|' + str(listlist[i]['topId'])
gd['desc'] = listlist[i]['updateTime'] + u'更新'
items.append(gd)
return items
########################################### 排行详细 ###########################################
def one63rank(value):
gedans = []
# r = get_html(netease_api + '/top/list?idx=' + value)
r = get_html(netease_api + '/related/playlist?id=' + value)
dialog = xbmcgui.Dialog()
dialog.textviewer('错误提示', str(value))
j = json.loads(r)
glist = j['playlist']['tracks']
# songs = ''
# for index in range(len(glist)):
# if index == 0:
# songs += str(glist[index]['id'])
# else:
# songs += ',' + str(glist[index]['id'])
# #mp3 url
# r2 = get_html(netease_api + '/song/url?id=' + songs)
# j2 = json.loads(r2)
# mp3url = j2['data']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['name']
gd['label'] = glist[index]['name']
if glist[index]['alia'] != []:
gd['label'] += u'(' + glist[index]['alia'][0] + u')'
gd['thumb'] = glist[index]['al']['picUrl']
# gd['url'] = mp3url[index]['url']
if xbmcplugin.getSetting(int(sys.argv[1]), 'httpswitch') == 'true':
gd['url'] = 'http'
else:
gd['url'] = 'https'
gd['url'] += '://music.163.com/song/media/outer/url?id=' + str(glist[index]['id']) + '.mp3'
gedans.append(gd)
return gedans
def qqrank(value):
gedans = []
# dialog = xbmcgui.Dialog()
# dialog.textviewer('错误提示', str(value))
r = get_html(qqmusic_api + '/top?id=' + str(value))
j = json.loads(r)
glist = j['data']['list']
songs= ''
for index in range(len(glist)):
if index == 0:
songs += glist[index]['mid']
else:
songs += ',' + glist[index]['mid']
r1 = get_html(qqmusic_api + '/song/urls?id=' + songs)
j1 = json.loads(r1)
mp3urls = j1['data']
for index in range(len(glist)):
if glist[index]['mid'] in mp3urls:
gd ={}
gd['name'] = glist[index]['title']
gd['label'] = ''
if int(glist[index]['rankType']) == 1:
gd['label'] += u'[COLOR red]↑ ' + glist[index]['rankValue'] + u' '*(3-len(str(glist[index]['rankValue']))) + u'[/COLOR]'
if int(glist[index]['rankType']) == 2:
gd['label'] += u'[COLOR green]↓ ' + glist[index]['rankValue'] + u' '*(3-len(str(glist[index]['rankValue']))) + u'[/COLOR]'
if int(glist[index]['rankType']) == 3:
gd['label'] += u'= ' + glist[index]['rankValue'] + u' '*(3-len(str(glist[index]['rankValue'])))
if int(glist[index]['rankType']) == 4:
gd['label'] += u'[COLOR red]NEW[/COLOR]'
if int(glist[index]['rankType']) == 6:
gd['label'] += u'[COLOR red]↑ ' + glist[index]['rankValue'] + u'[/COLOR]' + u' '*(5-len(str(glist[index]['rankValue'])))
gd['label'] += u' ' + glist[index]['title']
gd['thumb'] = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000' + glist[index]['albumMid'] + '.jpg'
gd['url'] = mp3urls[glist[index]['mid']]
gedans.append(gd)
return gedans
########################################### mv ###########################################
def one63mvlist(page):
items = []
r = get_html(netease_api + '/mv/all?limit=50&offset=' + str( ( int(page)-1 ) *50 ) )
j = json.loads(r)
one63list = j['data']
for index in range(len(one63list)):
gd = {}
gd['name'] = one63list[index]['name']
gd['thumb'] = one63list[index]['cover']
gd['url'] = 'https://music.163.com/#/mv?id=' +str(one63list[index]['id'])
items.append(gd)
return items
def qqmvlist(page):
items = []
r = get_html(qqmusic_api + '/mv/list?pageSize=50&pageNo=' + str(page))
j = json.loads(r)
listlist = j['data']['list']
for i in range(len(listlist)):
gd = {}
gd['name'] = listlist[i]['title']
gd['thumb'] = listlist[i]['picurl']
gd['url'] = 'https://y.qq.com/n/yqq/mv/v/'+listlist[i]['vid']+'.html'
items.append(gd)
return items
def one63playmv(vid):
r = get_html(netease_api + '/mv/url?id=' + str(vid))
j = json.loads(r)
mp4 = j['data']['url']
return mp4
def qqplaymv(vid):
r = get_html(qqmusic_api + '/mv/url?id=' + str(vid))
j = json.loads(r)
mp4 = j['data'][vid][len( j['data'][vid])-1]
return mp4
def one63mvinfo(vid):
vdict = {}
r = get_html(netease_api + '/mv/detail?mvid=' + str(vid))
j = json.loads(r)
i = j['data']
vdict['title'] = i['name']
vdict['thumb'] = i['cover']
vdict['duration'] = int(str(i['duration'])[:-3])
vdict['plot'] = zh(i['playCount']) + '播放 · ' + zh(i['commentCount']) + '评论'
if i['desc']:
vdict['plot'] += '\n\n' + i['desc'].encode('utf-8')
vdict['aired'] = i['publishTime']
cast = []
for index in range(len(i['artists'])):
cast.append(i['artists'][index]['name'])
vdict['cast'] = cast
return vdict
def qqmvinfo(vid):
vdict = {}
r = get_html(qqmusic_api + '/mv?id=' + str(vid))
j = json.loads(r)
i = j['data']['info']
vdict['title'] = i['name']
vdict['thumb'] = i['cover_pic']
vdict['duration'] = i['duration']
vdict['plot'] = zh(i['playcnt']) + '播放'
if i['desc']:
vdict['plot'] = i['desc']
vdict['aired'] = unix_to_data(i['pubdate'])
cast = []
for index in range(len(i['singers'])):
cast.append(i['singers'][index]['name'])
vdict['cast'] = cast
return vdict
########################################### 搜索 ###########################################
def one63search(keyword,type,page):
gedans = []
r = get_html(netease_api + '/search?keywords=' + keyword + '&offset='+str((int(page)-1)*30)+'&type='+type)
j = json.loads(r)
glist = j['result']
#单曲
if type == '1':
if 'songs' in glist:
glist = glist['songs']
songs= ''
for index in range(len(glist)):
if index == 0:
songs += str(glist[index]['id'])
else:
songs += ',' + str(glist[index]['id'])
#mp3详情
r2 = get_html(netease_api + '/song/detail?ids=' + songs)
j2 = json.loads(r2)
mp3detail = j2['songs']
for index in range(len(glist)):
gd ={}
gd['name'] = mp3detail[index]['name']
gd['thumb'] = mp3detail[index]['al']['picUrl']
#mp3url
r1 = get_html(netease_api + '/song/url?id=' + str(mp3detail[index]['id']))
j1 = json.loads(r1)
gdurl = j1['data'][0]['url']
gd['url'] = gdurl
#gd['url'] = mp3urls[str(mp3detail[index]['id'])]
gd['info'] = {'title':mp3detail[index]['name'],'album':mp3detail[index]['al']['name'],'artist':mp3detail[index]['ar'][0]['name']}
gedans.append(gd)
else:
dialog = xbmcgui.Dialog()
dialog.notification('提示', '搜索结果为空', xbmcgui.NOTIFICATION_INFO, 5000)
#歌单
if type == '1000':
if 'playlists' in glist:
glist = glist['playlists']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = glist[index]['coverImgUrl']
gd['url'] = 'https://music.163.com/#/playlist?id=' + str(glist[index]['id'])
ginfo = {'title':glist[index]['name'],'cast':[(glist[index]['creator']['nickname'],u'创建者')],'plot':zh(glist[index]['playCount']).decode('utf-8') + u'播放 · ' + zh(glist[index]['trackCount']).decode('utf-8') + u'首歌 \n\n'}
if glist[index]['description']:
ginfo['plot'] += glist[index]['description']
gd['info'] = ginfo
gedans.append(gd)
else:
dialog = xbmcgui.Dialog()
dialog.notification('提示', '搜索结果为空', xbmcgui.NOTIFICATION_INFO, 5000)
#专辑
if type == '10':
if 'albums' in glist:
glist = glist['albums']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = glist[index]['blurPicUrl']
gd['url'] = 'https://music.163.com/#/album?id=' + str(glist[index]['id'])
gd['info'] = {'title':glist[index]['name'],'album':glist[index]['name'],'artist':glist[index]['artists'][0]['name']}
gedans.append(gd)
else:
dialog = xbmcgui.Dialog()
dialog.notification('提示', '搜索结果为空', xbmcgui.NOTIFICATION_INFO, 5000)
#歌手
if type == '100':
if 'artists' in glist:
glist = glist['artists']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = glist[index]['picUrl']
gd['url'] = 'https://music.163.com/#/artist?id=' + str(glist[index]['id'])
gd['info'] = {'title':glist[index]['name'],'artist':glist[index]['name']}
gedans.append(gd)
else:
dialog = xbmcgui.Dialog()
dialog.notification('提示', '搜索结果为空', xbmcgui.NOTIFICATION_INFO, 5000)
#MV
if type == '1004':
if 'mvs' in glist:
glist = glist['mvs']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['name']
gd['thumb'] = glist[index]['cover']
gd['url'] = 'https://music.163.com/#/mv?id=' + str(glist[index]['id'])
gd['info'] = {'title':glist[index]['name'],'duration':int(glist[index]['duration'])/1000,'cast':[glist[index]['artistName']]}
gedans.append(gd)
else:
dialog = xbmcgui.Dialog()
dialog.notification('提示', '搜索结果为空', xbmcgui.NOTIFICATION_INFO, 5000)
#视频
if type == '1014':
if 'videos' in glist:
glist = glist['videos']
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['title']
gd['thumb'] = glist[index]['coverUrl']
gd['url'] = 'https://music.163.com/#/video?id=' + str(glist[index]['vid'])
gd['info'] = {'title':glist[index]['title'],'duration':int(glist[index]['durationms'])/1000,'cast':[glist[index]['creator'][0]['userName']]}
gedans.append(gd)
else:
dialog = xbmcgui.Dialog()
dialog.notification('提示', '搜索结果为空', xbmcgui.NOTIFICATION_INFO, 5000)
return gedans
def qqsearch(keyword,type,page):
gedans = []
r = get_html(qqmusic_api + '/search?key=' + keyword + '&pageSize=30&pageNo='+str(page)+'&t='+type)
j = json.loads(r)
glist = j['data']['list']
#单曲
if type == '0':
songs= ''
for index in range(len(glist)):
if index == 0:
songs += glist[index]['songmid']
else:
songs += ',' + glist[index]['songmid']
r1 = get_html(qqmusic_api + '/song/urls?id=' + songs)
j1 = json.loads(r1)
mp3urls = j1['data']
for index in range(len(glist)):
if glist[index]['songmid'] in mp3urls:
gd ={}
gd['name'] = glist[index]['songname']
gd['thumb'] = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000' + glist[index]['albummid'] + '.jpg'
gd['url'] = mp3urls[glist[index]['songmid']]
gd['info'] = {'title':glist[index]['songname'],'album':glist[index]['albumname'],'artist':glist[index]['singer'][0]['name']}
gedans.append(gd)
#歌单
if type == '2':
for index in range(len(glist)):
gd ={}
gd['name'] = unescape(glist[index]['dissname'].encode('utf-8')).decode('utf-8')
gd['thumb'] = glist[index]['imgurl']
gd['url'] = 'https://y.qq.com/n/yqq/playlist/' + str(glist[index]['dissid']) + '.html'
gd['info'] = {'title':unescape(glist[index]['dissname'].encode('utf-8')).decode('utf-8'),'cast':[glist[index]['creator']['name'],u'创建者'],'plot':zh(glist[index]['listennum']).decode('utf-8') + u' 播放 \n\n' + unescape(glist[index]['introduction'].encode('utf-8')).decode('utf-8')}
gedans.append(gd)
#专辑
if type == '8':
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['albumName']
gd['thumb'] = glist[index]['albumPic']
gd['url'] = 'https://y.qq.com/n/yqq/album/' + str(glist[index]['albumMID']) + '.html'
gd['info'] = {'title':glist[index]['albumName'],'album':glist[index]['albumName'],'artist':glist[index]['singerName']}
gedans.append(gd)
#歌手
if type == '9':
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['singerName']
gd['thumb'] = glist[index]['singerPic']
gd['url'] = 'https://y.qq.com/n/yqq/singer/' + str(glist[index]['singerMID']) + '.html'
gd['info'] = {'title':glist[index]['singerName'],'artist':glist[index]['singerName']}
gedans.append(gd)
#MV
if type == '12':
for index in range(len(glist)):
gd ={}
gd['name'] = glist[index]['mv_name']
gd['thumb'] = glist[index]['mv_pic_url']
gd['url'] = 'https://y.qq.com/n/yqq/mv/v/' + str(glist[index]['v_id']) + '.html'
gd['info'] = {'title':glist[index]['mv_name'],'duration':glist[index]['duration']}
gedans.append(gd)
return gedans
########################################### 网易云视频 ###########################################
def one63playvideo(vid):
r = get_html(netease_api + '/video/url?id=' + str(vid))
j = json.loads(r)
mp4 = j['urls'][0]['url']
return mp4
def one63videoinfo(vid):
vdict = {}
r = get_html(netease_api + '/video/detail?id=' + str(vid))
j = json.loads(r)
i = j['data']
vdict['title'] = i['title']
vdict['thumb'] = i['coverUrl']
vdict['duration'] = int(i['durationms']/1000)
vdict['plot'] = zh(i['playTime']) + '播放 · ' + zh(i['praisedCount']) + '赞 · ' + zh(i['commentCount']) + '评论'
if i['description']:
vdict['plot'] += '\n\n' + i['description'].encode('utf-8')
vdict['aired'] = unix_to_data(i['publishTime'])
genre = []
for index in range(len(i['videoGroup'])):
genre.append(i['videoGroup'][index]['name'])
vdict['cast'] = [(i['creator']['nickname'],'视频作者')]
vdict['genre'] = genre
vdict['tag'] = genre
return vdict
@plugin.route('/')
def index():
items = []
items.append({
'label': '推荐',
'path': plugin.url_for('tuijian'),
})
items.append({
'label': '排行',
'path': plugin.url_for('rank'),
})
items.append({
'label': 'MV',
'path': plugin.url_for('mv'),
})
items.append({
'label': '搜索',
'path': plugin.url_for('so'),
})
items.append({
'label': '歌单',
'path': plugin.url_for('gedang'),
})
items.append({
'label': '日推',
'path': plugin.url_for('ritui'),
})
# items.append({
# 'label': '设置',
# 'path': plugin.url_for('setting'),
# })
return items
@plugin.route('/tuijian/')
def tuijian():
items = []
items.append({
'label': '网易云 · 热门推荐歌单',
'path': plugin.url_for('get_tuijian',mode='163'),
})
items.append({
'label': 'QQ音乐 · 热门推荐歌单',
'path': plugin.url_for('get_tuijian',mode='qq'),
})
return items
@plugin.route('/ritui/')
def ritui():
if xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusiccookieswitch') == 'true' or xbmcplugin.getSetting(int(sys.argv[1]), 'qqmusiccookieswitch') == 'true':
items = []
if xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusicu') != '' and xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusiccookieswitch') == 'true':
items.append({
'label': '网易云 · 私人推荐',
'path': plugin.url_for('get_ritui',mode='163'),
})
if xbmcplugin.getSetting(int(sys.argv[1]), 'qqmusiccookie') != '' and xbmcplugin.getSetting(int(sys.argv[1]), 'qqmusiccookieswitch') == 'true':
items.append({
'label': 'QQ音乐 · 私人推荐',
'path': plugin.url_for('get_ritui',mode='qq'),
})
return items
else:
dialog = xbmcgui.Dialog()
dialog.notification('该功能未解锁','请先启用QQ音乐或者网易云的cookie功能', xbmcgui.NOTIFICATION_INFO, 5000)
@plugin.route('/mv/')
def mv():
items = []
items.append({
'label': '网易云 · MV',
'path': plugin.url_for('get_mv',mode='163',page=1),
})
items.append({
'label': 'QQ音乐 · MV',
'path': plugin.url_for('get_mv',mode='qq',page=1),
})
return items
@plugin.route('/so/')
def so():
items = []
items.append({
'label': '网易云 · 单曲搜索',
'path': plugin.url_for('history',name='搜索 网易云 · 单曲',url='search',mode='163',type='1')
})
items.append({
'label': 'QQ音乐 · 单曲搜索',
'path': plugin.url_for('history',name='搜索 QQ音乐 · 单曲',url='search',mode='qq',type='0')
})
items.append({
'label': '网易云 · 专辑搜索',
'path': plugin.url_for('history',name='搜索 网易云 · 专辑',url='search',mode='163',type='10')
})
items.append({
'label': 'QQ音乐 · 专辑搜索',
'path': plugin.url_for('history',name='搜索 QQ音乐 · 专辑',url='search',mode='qq',type='8')
})
items.append({
'label': '网易云 · 歌手搜索',
'path': plugin.url_for('history',name='搜索 网易云 · 歌手',url='search',mode='163',type='100')
})
items.append({
'label': 'QQ音乐 · 歌手搜索',
'path': plugin.url_for('history',name='搜索 QQ音乐 · 歌手',url='search',mode='qq',type='9')
})
items.append({
'label': '网易云 · 歌单搜索',
'path': plugin.url_for('history',name='搜索 网易云 · 歌单',url='search',mode='163',type='1000')
})
items.append({
'label': 'QQ音乐 · 歌单搜索',
'path': plugin.url_for('history',name='搜索 QQ音乐 · 歌单',url='search',mode='qq',type='2')
})
items.append({
'label': '网易云 · MV搜索',
'path': plugin.url_for('history',name='搜索 网易云 · MV',url='search',mode='163',type='1004')
})
items.append({
'label': 'QQ音乐 · MV搜索',
'path': plugin.url_for('history',name='搜索 QQ音乐 · MV',url='search',mode='qq',type='12')
})
# items.append({
# 'label': '网易云 · 电台搜索',
# 'path': plugin.url_for('history',name='搜索 网易云 · 电台',url='search',mode='163',type='1009')
# })
items.append({
'label': '网易云 · 视频搜索',
'path': plugin.url_for('history',name='搜索 网易云 · 视频',url='search',mode='163',type='1014')
})
# items.append({
# 'label': '复制粘贴歌单url解析歌单(支持网易云和QQ音乐)',
# 'path': plugin.url_for('get_mv',mode='163',page=1),
# })
# items.append({
# 'label': '复制粘贴MV url解析mv(支持网易云和QQ音乐)',
# 'path': plugin.url_for('get_mv',mode='163',page=1),
# })
return items
@plugin.route('/gedang/')
def gedang():
if xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusiccookieswitch') == 'true' or xbmcplugin.getSetting(int(sys.argv[1]), 'qqmusiccookieswitch') == 'true':
items = []
if xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusicuid') != '' and xbmcplugin.getSetting(int(sys.argv[1]), 'neteasemusiccookieswitch') == 'true':
items.append({
'label': '网易云 · 我的歌单',
'path': plugin.url_for('get_gedang',mode='163'),
})
if xbmcplugin.getSetting(int(sys.argv[1]), 'qqmusicid') != '' and xbmcplugin.getSetting(int(sys.argv[1]), 'qqmusiccookieswitch') == 'true':
items.append({
'label': 'QQ音乐 · 我的歌单',
'path': plugin.url_for('get_gedang',mode='qq'),
})
return items
else:
dialog = xbmcgui.Dialog()
dialog.notification('该功能未解锁','请先启用QQ音乐或者网易云的cookie功能', xbmcgui.NOTIFICATION_INFO, 5000)
@plugin.route('/rank/')
def rank():
gdlist = get_rank()
items = [{
'label': video['name'],
'path': plugin.url_for('ranklist',value=video['url'].encode('utf-8')),
'thumbnail': video['thumb'],
'icon': video['thumb'],
'info':{'plot':video['desc'],'mediatype':'video'},
'info_type':'video',
} for video in gdlist]
return items
@plugin.route('/ranklist/<value>/')
def ranklist(value):
# 通过传递 qq|排行榜id 或 163|排行榜id 的value值 来区分不同的排行榜
value = value.split("|")
if value[0] == '163':
gdlist = one63playlist(value[1])