forked from chen310/NeteaseCloudMusicTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
888 lines (799 loc) · 36.9 KB
/
user.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
# -*- coding: utf-8 -*-
import time
import random
import math
import re
from hashlib import md5
from api import NetEase
import os
import requests
class User(object):
def __init__(self):
self.music = None
self.user_setting = {}
self.title = '网易云音乐'
self.msg = ''
self.isLogined = False
self.No = 0
self.nickname = ''
self.uid = 0
self.userType = 0
self.level = 0
self.full = False
self.full_level = 10
self.songFull = False
self.listenSongs = 0
self.vipType = 0
self.songnumber = -1
def setUser(self, username, password, isMd5=False, countrycode='', user_setting={}, No=0, ip=""):
self.music = self.login_check(
username, password, isMd5, countrycode, ip)
self.taskUser(No)
if self.music.uid != 0:
self.isLogined = True
self.user_setting = user_setting
self.uid = self.music.uid
self.userType = self.music.userType
else:
if len(self.music.loginerror) > 0:
msg = self.music.loginerror
else:
msg = '可能是网络或其他原因'
self.title += ': 登录失败' + msg
self.taskTitle('用户信息,')
self.taskInfo('登录失败,' + msg)
self.finishTask()
def login_check(self, username, pwd='', is_md5=True, countrycode='', ip=""):
music = NetEase(username)
if len(ip) > 0:
music.header["X-Real-IP"] = ip
resp = music.user_level()
if resp['code'] == 200:
music.uid = resp['data']['userId']
user_resp = music.user_detail(music.uid)
music.nickname = user_resp['profile']['nickname']
music.userType = user_resp['profile']['userType']
if music.userType != 0 and music.userType != 4:
for authtype in user_resp['profile'].get('allAuthTypes', []):
if authtype['type'] == 4:
music.userType = 4
break
else:
if not is_md5:
pwd = md5(pwd.encode(encoding='UTF-8')).hexdigest()
login_resp = music.login(username, pwd, countrycode)
if login_resp['code'] == 200:
music.uid = login_resp['profile']['userId']
music.nickname = login_resp['profile']['nickname']
music.userType = login_resp['profile']['userType']
music.loginerror = ''
if music.userType != 0 and music.userType != 4:
user_resp = music.user_detail(music.uid)
for authtype in user_resp['profile'].get('allAuthTypes', []):
if authtype['type'] == 4:
music.userType = 4
break
else:
music.uid = 0
music.nickname = ''
music.loginerror = login_resp.get('msg', '')
return music
def taskUser(self, No):
self.msg += '### 用户' + str(No) + '\n'
print('### 用户' + str(No))
def taskTitle(self, title):
self.msg += '#### ' + title + '\n'
print('#### ' + title)
def taskInfo(self, key, value=''):
if value == '':
self.msg += '- ' + str(key) + '\n'
print('- ' + str(key))
else:
self.msg += '- ' + str(key) + ': ' + str(value) + '\n'
print('- ' + str(key) + ': ' + str(value))
def finishTask(self):
self.msg += '\n'
print()
def userInfo(self):
resp = self.music.user_detail(self.uid)
self.level = resp['level']
self.vipType = resp['profile']['vipType']
self.listenSongs = resp['listenSongs']
self.taskTitle('用户信息')
self.taskInfo('用户名称', resp['profile']['nickname'])
self.taskInfo('用户ID', self.uid)
self.taskInfo('用户等级', resp['level'])
self.taskInfo('用户村龄', str(resp['createDays']) + '天')
if self.vipType == 11:
vip_resp = self.music.vip_level()
self.taskInfo('VIP等级', vip_resp['data']['redVipLevel'])
self.taskInfo('到期时间', time.strftime(
"%Y-%m-%d %H:%M:%S", time.localtime(vip_resp['data']['musicPackage']['expireTime']/1000)))
self.taskInfo('云贝数量', resp['userPoint']['balance'])
attention_resp = self.music.expire_attention()
if attention_resp.get('code', -1) == 200 and attention_resp['data']['expiringYunbei'] > 0:
remainingTime = attention_resp['data']['remainingTime']
self.taskInfo('过期提醒', str(
attention_resp['data']['expiringYunbei']) + '云贝将在' + str(remainingTime)+'天后过期,请尽快使用')
self.taskInfo('粉丝数量', resp['profile']['followeds'])
self.taskInfo('听歌总数', self.listenSongs)
self.taskInfo('歌单数', resp['profile']['playlistCount'])
self.taskInfo('歌单总收藏数', resp['profile']['playlistBeSubscribedCount'])
resp = self.music.user_level()
self.full = resp['full']
if not self.full:
self.taskInfo('距离下级还需播放', str(
resp['data']['nextPlayCount'] - resp['data']['nowPlayCount']) + '首歌')
self.taskInfo('登录天数', resp['data']['nowLoginCount'])
self.taskInfo('距离下级还需登录', str(
resp['data']['nextLoginCount'] - resp['data']['nowLoginCount']) + '天')
if resp['data']['nowPlayCount'] >= 20000:
self.songFull = True
self.finishTask()
def resize(self, total):
if total <= 10:
total = total * 3
elif total <= 50:
total = int(total * 1.8)
elif total <= 100:
total = int(total * 1.3)
elif total <= 200:
total = int(total * 1.2)
return total
def auto_daka(self):
self.taskTitle('打卡信息')
user_setting = self.user_setting
if user_setting['daka']['full_stop']:
if self.full:
self.taskInfo('打卡', '您的等级已经爆表了,无需再打卡')
self.finishTask()
return
elif self.songFull:
self.taskInfo('打卡', '距离满级只差登录天数,无需打卡')
self.finishTask()
return
print("获取到歌曲数:" + str(self.songnumber))
daka_number = 0
total = 300 - (self.listenSongs - self.songnumber)
if total == 0:
self.taskInfo('打卡', '今天300首歌已经刷满了')
self.finishTask()
return
if total <= user_setting['daka']['tolerance']:
self.taskInfo('打卡', '今天已经打卡'+str(self.listenSongs - self.songnumber)+"首歌了")
self.finishTask()
return
playlists = self.music.personalized_playlist(limit=50)
# 推荐歌单id列表
playlist_ids = [playlist["id"] for playlist in playlists]
song_ids = []
song_datas = []
# 打乱歌单id
random.shuffle(playlist_ids)
idx = 0
start = idx
total = self.resize(total)
for c in range(6):
if len(song_datas) < total:
for i in range(start, len(playlist_ids)):
idx = i
playlist_id = playlist_ids[i]
# 获得歌单中歌曲的信息
songs = self.music.playlist_detail(playlist_id).get(
"playlist", {}).get("tracks", [])
for song in songs:
# 去重
if song['id'] in song_ids:
break
song_ids.append(song["id"])
song_data = {
"type": 'song',
"wifi": 0,
"download": 0,
"id": song['id'],
"time": math.ceil(song['dt']/1000),
"end": 'playend',
"source": 'list',
"sourceId": playlist_id,
}
song_datas.append(song_data)
if len(song_datas) >= total:
song_datas = song_datas[0:total]
break
num = 300
print("即将打卡"+str(total)+"首")
self.music.daka(song_datas[0:total])
daka_number += total
song_datas = song_datas[total:]
# time.sleep(user_setting['daka']['sleep_time'])
time.sleep(30)
resp = self.music.user_detail(self.uid)
if 300 - (resp['listenSongs'] - self.songnumber) <= user_setting['daka']['tolerance']:
self.title = self.title + '今天听歌' + \
str(resp['listenSongs']-self.songnumber) + \
'首,累计听歌'+str(resp['listenSongs'])+'首'
self.taskInfo("本次实际打卡数", str(daka_number) + '首')
self.taskInfo('今天有效打卡数', str(
resp['listenSongs'] - self.songnumber) + '首')
self.taskInfo('听歌总数', str(resp['listenSongs']) + '首')
self.taskInfo(
'温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')')
return
else:
total = 300 - (resp['listenSongs'] - self.songnumber)
total = self.resize(total)
if len(song_datas) >= total:
start = idx
else:
start = idx + 1
time.sleep(15)
resp = self.music.user_detail(self.uid)
self.title = self.title + '今天听歌' + \
str(resp['listenSongs']-self.songnumber) + \
'首,累计听歌'+str(resp['listenSongs'])+'首'
self.taskInfo("本次实际打卡数", str(daka_number) + '首')
self.taskInfo('今天有效打卡数', str(
resp['listenSongs'] - self.songnumber) + '首')
self.taskInfo('听歌总数', str(resp['listenSongs']) + '首')
self.taskInfo(
'温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')')
self.finishTask()
def daka(self):
self.taskTitle('打卡信息')
user_setting = self.user_setting
if user_setting['daka']['full_stop']:
if self.full:
self.taskInfo('打卡', '您的等级已经爆表了,无需再打卡')
self.finishTask()
return
elif self.songFull:
self.taskInfo('打卡', '距离满级只差登录天数,无需打卡')
self.finishTask()
return
playlists = self.music.personalized_playlist(limit=30)
# 推荐歌单id列表
playlist_ids = [playlist["id"] for playlist in playlists]
song_ids = []
total = user_setting['daka']['song_number']
song_datas = []
# 打乱歌单id
random.shuffle(playlist_ids)
for playlist_id in playlist_ids:
# 获得歌单中歌曲的信息
songs = self.music.playlist_detail(playlist_id).get(
"playlist", {}).get("tracks", [])
for song in songs:
# 去重
if song['id'] in song_ids:
break
song_ids.append(song["id"])
song_data = {
"type": 'song',
"wifi": 0,
"download": 0,
"id": song['id'],
"time": math.ceil(song['dt']/1000),
"end": 'playend',
"source": 'list',
"sourceId": playlist_id,
}
song_datas.append(song_data)
if len(song_datas) >= total:
song_datas = song_datas[0:total]
break
num = user_setting['daka']['upload_num']
for i in range(0, len(song_datas), num):
self.music.daka(song_datas[i:i+num])
time.sleep(user_setting['daka']['sleep_time'])
resp = self.music.user_detail(self.uid)
if (resp['listenSongs'] - self.listenSongs) >= 300:
self.title = self.title + '本次听歌' + \
str(resp['listenSongs']-self.listenSongs) + \
'首,累计听歌'+str(resp['listenSongs'])+'首'
self.taskInfo('本次打卡数', str(
resp['listenSongs'] - self.listenSongs) + '首')
self.taskInfo('听歌总数', str(resp['listenSongs']) + '首')
self.taskInfo(
'温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')')
return
time.sleep(user_setting['daka']['sleep_time'] + 5)
resp = self.music.user_detail(self.uid)
self.title = self.title + '本次听歌' + \
str(resp['listenSongs']-self.listenSongs) + \
'首,累计听歌'+str(resp['listenSongs'])+'首'
self.taskInfo('本次打卡数', str(
resp['listenSongs'] - self.listenSongs) + '首')
self.taskInfo('听歌总数', str(resp['listenSongs']) + '首')
self.taskInfo(
'温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')')
self.finishTask()
def play_playlists(self):
user_setting = self.user_setting
self.taskTitle('播放歌单')
playlist_ids = user_setting['other']['play_playlists']['playlist_ids']
if len(playlist_ids) == 0:
self.taskInfo('无可播放歌单')
return
count = user_setting['other']['play_playlists']['times']
song_datas = []
for playlist_id in playlist_ids:
# 获得歌单中歌曲的信息
result = self.music.playlist_detail(playlist_id)
if result['code'] != 200:
self.taskInfo('歌单id', str(playlist_id) + '错误')
break
songs = result.get("playlist", {}).get("tracks", [])
self.taskInfo(result["playlist"]['name'], '播放' + str(count) + '次')
for song in songs:
song_data = {
"type": 'song',
"wifi": 0,
"download": 0,
"id": song['id'],
"time": math.ceil(song['dt']/1000),
"end": 'playend',
"source": 'list',
"sourceId": playlist_id,
}
song_datas.append(song_data)
for i in range(count):
for playlist_id in playlist_ids:
self.music.update_playcount(playlist_id)
self.play(song_datas)
time.sleep(1)
self.finishTask()
def taskPublish(self, task):
if len(task['id']) > 0:
playlist_id = random.choice(task['id'])
else:
playlists = self.music.personalized_playlist(limit=10)
playlist_ids = [playlist["id"] for playlist in playlists]
playlist_id = random.choice(playlist_ids)
if len(task['msg']) > 0:
event_msg = random.choice(task['msg'])
else:
event_msg = '每日分享'
result = self.music.share_resource(
type='playlist', msg=event_msg, id=playlist_id)
if result['code'] == 200:
event_id = result['id']
if task['delete']:
time.sleep(0.5)
delete_result = self.music.event_delete(event_id)
self.taskInfo(task['taskName'], '发布成功,已删除动态')
else:
self.taskInfo(task['taskName'], '发布成功')
else:
self.taskInfo(task['taskName'], '发布失败')
time.sleep(2)
def taskMall(self, task):
resp = self.music.visit_mall()
if resp['code'] == 200:
self.taskInfo(task['taskName'], '访问成功')
else:
self.taskInfo(task['taskName'], '访问失败')
def taskRcmdSong(self, task):
if len(task['songId']) == 0:
self.taskInfo(task['taskName'], '请填写歌曲id')
return
songId = random.choice(task['songId'])
yunbeiNum = task['yunbeiNum']
reason = random.choice(task['reason'])
resp = self.music.yunbei_rcmd_submit(songId, yunbeiNum, reason)
if resp['code'] == 200:
self.taskInfo(task['taskName'], '推歌成功,歌曲ID为'+str(songId))
elif resp['code'] == 400:
self.taskInfo(task['taskName'], '推歌失败,歌曲ID为' +
str(songId)+',失败原因为'+resp.get('message', '未知'))
else:
self.taskInfo(task['taskName'], '推歌失败,歌曲ID为'+str(songId))
def taskMlog(self, task):
if len(task['songId']) == 0:
self.taskInfo(task['taskName'], '请填写歌曲ID')
return
songId = random.choice(task['songId'])
song_resp = self.music.songs_detail([songId])
if song_resp.get('code', -1) == 200 and len(song_resp['songs']) > 0:
song = song_resp['songs'][0]
songName = song['name']
artists = song['ar']
if artists is None or len(artists) == 0:
artistName = '未知'
else:
artistName = '/'.join([a['name'] for a in artists])
url = song.get('al', {}).get('picUrl', '')
else:
self.taskInfo(task['taskName'], '歌曲信息获取失败,请检查ID是否正确')
return
if len(url) == 0:
self.taskInfo(task['taskName'], '专辑图片获取失败')
return
path = '/tmp'
if not os.path.exists(path):
path = './'
filepath = os.path.join(path, 'album.jpg')
size = task.get('size', 500)
url += '?param='+str(size)+'y'+str(size)
r = requests.get(url)
with open(filepath, 'wb') as f:
f.write(r.content)
token = self.music.mlog_nos_token(filepath)
time.sleep(0.2)
self.music.upload_file(filepath, token)
time.sleep(0.2)
text = random.choice(task['text'])
text = text.replace('$artist', artistName)
text = text.replace('$song', songName)
resp = self.music.mlog_pub(token, size, size, songId, songName, text)
if resp.get('code', -1) != 200:
self.taskInfo(task['taskName'], 'Mlog发布失败')
if task.get('delete', True) == True:
time.sleep(0.5)
resourceId = resp['data']['event']['info']['resourceId']
delete_result = self.music.event_delete(resourceId)
self.taskInfo(task['taskName'], '发布成功,已删除Mlog动态')
else:
self.taskInfo(task['taskName'], '发布成功')
os.remove(filepath)
def yunbei_task(self):
user_setting = self.user_setting
self.taskTitle('云贝任务')
count = 0
resp = self.music.yunbei_task()
tasks = user_setting['yunbei_task']
for t in resp['data']:
desp = t['taskName']
if t['userTaskId'] == 0:
if '发布动态' in desp:
desp = '发布动态'
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
self.taskPublish(tasks[desp])
count += 1
if '访问云音乐商城' in desp:
desp = '访问云音乐商城'
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
self.taskMall(tasks[desp])
count += 1
if '云贝推歌' in desp:
desp = '云贝推歌'
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
self.taskRcmdSong(tasks[desp])
count += 1
if '发布Mlog' in desp:
desp = '发布Mlog'
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
self.taskMlog(tasks[desp])
count += 1
if count == 0:
self.taskInfo('无可执行的任务')
self.finishTask()
time.sleep(1)
def get_yunbei(self):
self.taskTitle('领取云贝')
resp = self.music.yunbei_task_todo()
count = 0
for task in resp['data']:
if task['userTaskId'] > 0:
self.music.yunbei_task_finish(
task['userTaskId'], task['depositCode'])
self.taskInfo(task['taskName'], '云贝+' + str(task['taskPoint']))
count += 1
if count == 0:
self.taskInfo('无可领取的云贝')
self.finishTask()
def play(self, song_datas, sleep_time=3):
if "upload_num" in self.user_setting['daka']:
num = self.user_setting['daka']['upload_num']
else:
num = 300
for i in range(0, len(song_datas), num):
self.music.daka(song_datas[i:i+num])
time.sleep(sleep_time)
def follow(self):
author_uid = 347837981
if self.uid == author_uid:
return
resp = self.music.user_detail(author_uid)
author_nickname = resp['profile']['nickname']
if not resp['profile']['followed']:
follow_resp = self.music.user_follow(author_uid)
if follow_resp['code'] == 200:
self.taskTitle('关注作者')
self.taskInfo('感谢关注', author_nickname)
# self.taskInfo('如果不想关注,请在配置文件里修改,并在官方客户端里取消关注')
self.taskInfo(
'如果不想关注,请在配置文件里修改,并在[主页](https://music.163.com/#/user/home?id='+str(author_uid)+')里取消关注')
self.finishTask()
def sign(self):
self.taskTitle('签到信息')
progress = self.music.signin_progress('1207signin-1207signin')
if progress.get('code', -1) != 200:
self.taskInfo('签到进度获取失败')
self.music.daily_task(True)
# PC端签到,好像已经失效
self.music.daily_task(False)
self.taskInfo('签到成功')
self.finishTask()
return
if progress['data']['today']['todaySignedIn'] == True:
stats = progress['data']['today']['todayStats']
totalYunbei = 0
for stat in stats:
currentProgress = stat['currentProgress']
for prize in stat['prizes']:
if prize['obtained'] == True and prize['progress'] == currentProgress:
totalYunbei += prize['amount']
self.taskInfo('重复签到', '今天签到共获取' + str(totalYunbei) + '云贝')
self.finishTask()
return
self.music.daily_task(True)
# PC端签到,好像已经失效
self.music.daily_task(False)
time.sleep(1)
progress = self.music.signin_progress('1207signin-1207signin')
if progress['data']['today']['todaySignedIn'] == False:
self.taskInfo('无法确定是否签到成功,请稍后到云贝中心检查云贝是否到账')
self.finishTask()
return
stats = progress['data']['today']['todayStats']
for stat in stats:
desp = stat['description']
desp = re.sub(r'(.*?)', '', desp)
desp = re.sub(r'\(.*?\)', '', desp)
currentProgress = stat['currentProgress']
for prize in stat['prizes']:
if prize['obtained'] == True and prize['progress'] == currentProgress:
self.taskInfo(
desp, '云贝+' + str(prize['amount']) + ' 已签到'+str(currentProgress)+'天')
self.finishTask()
def musician_task(self):
self.taskTitle('音乐人信息')
tasks = self.user_setting["musician_task"]
descriptions = [task for task in tasks]
result = self.music.mission_cycle_get()
if result['code'] == 200:
mission_list = result.get('data', {}).get('list', [])
comments = []
replies = []
for mission in mission_list:
desp = mission['description']
if (mission['status'] == 0 or mission['status'] == 10):
num = mission['targetCount'] - mission['progressRate']
if "登录音乐人中心" in desp:
desp = "登录音乐人中心"
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
self.music.user_access()
elif "发布动态" in desp:
desp = "发布动态"
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
ids = []
if len(tasks[desp]['id']) > 0:
for i in range(num):
ids.append(random.choice(tasks[desp]['id']))
else:
playlists = self.music.personalized_playlist(
limit=10)
playlist_ids = [playlist["id"]
for playlist in playlists]
for i in range(num):
ids.append(playlist_ids[i])
if len(tasks[desp]['msg']) > 0:
event_msg = random.choice(tasks[desp]['msg'])
else:
event_msg = '每日分享'
for i in range(num):
result = self.music.share_resource(
type='playlist', msg=event_msg, id=ids[i])
if result['code'] == 200:
event_id = result['id']
if tasks[desp]['delete']:
time.sleep(0.5)
self.music.event_delete(event_id)
time.sleep(1)
elif "发布主创说" in desp:
desp = "发布主创说"
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
if len(tasks[desp]['id']) > 0 and len(comments) == 0:
songId = random.choice(tasks[desp]['id'])
if len(tasks[desp]['msg']) > 0:
msg = random.choice(tasks[desp]['msg'])
else:
msg = '感谢大家收听'
resp = self.music.comments_add(songId, msg)
if resp['code'] == 200:
comments.append(
{'commentId': resp['comment']['commentId'], 'songId': songId})
else:
print(resp)
continue
elif "回复粉丝评论" in desp:
desp = "回复粉丝评论"
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
if len(comments) > 0:
commentId = comments[0]['commentId']
songId = comments[0]['songId']
else:
if len(tasks[desp]['id']) > 0:
songId = random.choice(tasks[desp]['id'])
if len(tasks['发布主创说']['msg']) > 0:
msg = random.choice(tasks['发布主创说']['msg'])
else:
msg = '感谢大家收听'
resp = self.music.comments_add(songId, msg)
if resp['code'] == 200:
commentId = resp['comment']['commentId']
comments.append(
{'commentId': commentId, 'songId': songId})
else:
print(resp)
continue
else:
continue
time.sleep(5)
# 改成只执行一次
if num > 0:
loop_num = 1
for i in range(loop_num):
if len(tasks[desp]['msg']) > 0:
msg = random.choice(tasks[desp]['msg'])
else:
msg = '感谢收听'
resp = self.music.comments_reply(
songId, commentId, msg)
if resp['code'] == 200:
replies.append(
{'commentId': resp['comment']['commentId'], 'songId': songId})
else:
print('回复错误,错误详情:'+str(resp))
# time.sleep(152)
time.sleep(1)
elif "回复粉丝私信" in desp:
desp = "回复粉丝私信"
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
if len(tasks[desp]['id']) > 0:
user_id = random.choice(tasks[desp]['id'])
for i in range(num):
if len(tasks[desp]['msg']) > 0:
msg = random.choice(tasks[desp]['msg'])
else:
msg = '你好'
resp = self.music.msg_send(msg, [user_id])
time.sleep(2)
if tasks['回复粉丝评论']['delete'] and len(replies) > 0:
for reply in replies:
resp = self.music.comments_delete(
reply['songId'], reply['commentId'])
if tasks['发布主创说']['delete'] and len(comments) > 0:
for comment in comments:
resp = self.music.comments_delete(
comment['songId'], comment['commentId'])
time.sleep(5)
result = self.music.mission_cycle_get()
if result['code'] == 200:
mission_list = result.get('data', {}).get('list', [])
for mission in mission_list:
if mission['status'] == 0 and mission['description'] in descriptions:
self.taskInfo(mission['description'], '未完成')
elif mission['status'] == 10:
self.taskInfo(mission['description'], '进行中' + '(' + str(
mission['progressRate']) + '/' + str(mission['targetCount']) + ')')
elif mission['status'] == 20:
description = mission['description']
userMissionId = mission['userMissionId']
period = mission['period']
rewardWorth = mission['rewardWorth']
reward_result = self.music.reward_obtain(
userMissionId=userMissionId, period=period)
if reward_result['code'] == 200:
self.taskInfo(description, '云豆+' + str(rewardWorth))
elif mission['status'] == 100 and mission['description'] in descriptions:
self.taskInfo(mission['description'], '云豆已经领取过了')
else:
self.taskInfo('任务获取失败')
bean_resp = self.music.cloudbean()
self.taskInfo('云豆数', bean_resp['data']['cloudBean'])
info_result = self.music.musician_data()
data = info_result.get('data')
if data is None:
self.finishTask()
return
if data.get('playCount') is None:
self.taskInfo('昨日播放量', '--')
else:
self.taskInfo('昨日播放量', data['playCount'])
if data.get('followerCountIncrement') is None:
self.taskInfo('昨日新增粉丝', '--')
else:
self.taskInfo('昨日新增粉丝', data['followerCountIncrement'])
if data.get('productionTotal') is None:
self.taskInfo('作品(首)', '--')
else:
self.taskInfo('作品(首)', data['productionTotal'])
if data.get('availableExtractIncomeTotal') is None:
self.taskInfo('可提现余额', '--')
else:
self.taskInfo('可提现余额', data['availableExtractIncomeTotal'])
if data.get('musicianLevelScore') is None:
self.taskInfo('音乐人指数', '--')
else:
self.taskInfo('音乐人指数', data['musicianLevelScore'])
self.finishTask()
def vip_task(self):
self.taskTitle('VIP成长值')
resp = self.music.vip_task_newlist()
items = []
tasks = self.user_setting["vip_task"]
taskLists = resp.get('data', {}).get('taskList', [])
for taskList in taskLists:
for task_items in taskList.get('taskItems', []):
item = task_items.get('currentInfo', None)
if (item is not None):
items.append(item)
subitems = task_items.get('subList', [])
if (subitems is not None):
for item in subitems:
if (item is not None):
items.append(item)
count = 0
for item in items:
desp = item['action']
if item['status'] == 0:
if '创建共享歌单' in desp:
desp = '创建共享歌单'
if (desp not in tasks) or (tasks[desp]['enable'] == False):
continue
name = random.choice(tasks[desp]['name'])
create_resp = self.music.playlist_create(name, 0, 'SHARED')
if create_resp.get('code', -1) == 200:
if tasks[desp]['delete'] == True:
self.music.playlist_delete(
[create_resp.get('id', 0)])
self.taskInfo(desp, '歌单创建成功,已删除')
else:
self.taskInfo(desp, '歌单创建成功')
else:
self.taskInfo(desp, '歌单创建失败')
count += 1
if count > 0:
resp = self.music.vip_task_newlist()
else:
time.sleep(2)
unGetAllScore = resp.get('data', {}).get('unGetAllScore', 0)
if unGetAllScore == 0:
self.taskInfo('没有可领取的成长值')
self.finishTask()
return
reward_resp = self.music.vip_reward_getall()
if reward_resp.get('code', -1) != 200:
self.taskInfo('成长值领取失败')
scores = 0
taskLists = resp.get('data', {}).get('taskList', [])
for taskList in taskLists:
for items in taskList.get('taskItems', []):
item = items.get('currentInfo', None)
if (item is not None):
desp = item['action']
if item['totalUngetScore'] > 0:
scores += item['totalUngetScore']
self.taskInfo(
desp, '成长值+' + str(item['totalUngetScore']))
items = items.get('subList', [])
if (items is not None):
for item in items:
desp = item['action']
if item['totalUngetScore'] > 0:
scores += item['totalUngetScore']
self.taskInfo(
desp, '成长值+' + str(item['totalUngetScore']))
if unGetAllScore > scores:
self.taskInfo('未知', '成长值+' + str(unGetAllScore - scores))
self.finishTask()