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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
|
from __future__ import print_function, unicode_literals, division, absolute_import import random, hashlib, math, re import base64 import binascii import os import json import platform import time import requests from http.cookiejar import Cookie
from Crypto.Cipher import AES from future.builtins import int, pow
DEFAULT_TIMEOUT = 10
BASE_URL = "http://music.163.com"
class NetEase(object): def __init__(self): self.header = { "Accept": "*/*", "Accept-Encoding": "gzip,deflate,sdch", "Accept-Language": "zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4", "Connection": "keep-alive", "Content-Type": "application/x-www-form-urlencoded", "Host": "music.163.com", "Referer": "http://music.163.com", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", } self.session = requests.Session() @property def toplists(self): return [l[0] for l in TOP_LIST_ALL.values()]
def _raw_request(self, method, endpoint, data=None): if method == "GET": resp = self.session.get( endpoint, params=data, headers=self.header, timeout=DEFAULT_TIMEOUT ) elif method == "POST": resp = self.session.post( endpoint, data=data, headers=self.header, timeout=DEFAULT_TIMEOUT ) return resp
def make_cookie(self, name, value): return Cookie( version=0, name=name, value=value, port=None, port_specified=False, domain="music.163.com", domain_specified=True, domain_initial_dot=False, path="/", path_specified=True, secure=False, expires=None, discard=False, comment=None, comment_url=None, rest={}, )
def request(self, method, path, params={}, default={"code": -1}, custom_cookies={'os':'pc'}): endpoint = "{}{}".format(BASE_URL, path) csrf_token = "" for cookie in self.session.cookies: if cookie.name == "__csrf": csrf_token = cookie.value break params.update({"csrf_token": csrf_token}) data = default
for key, value in custom_cookies.items(): cookie = self.make_cookie(key, value) self.session.cookies.set_cookie(cookie)
params = encrypted_request(params) try: resp = self._raw_request(method, endpoint, params) data = resp.json() except requests.exceptions.RequestException as e: log.error(e) except ValueError as e: log.error("Path: {}, response: {}".format(path, resp.text[:200])) finally: return data
def login(self, username, password): if username.isdigit(): path = "/weapi/login/cellphone" params = dict(phone=username, password=password, rememberLogin="true") else: client_token = ( "1_jVUMqWEPke0/1/Vu56xCmJpo5vP1grjn_SOVVDzOc78w8OKLVZ2JH7IfkjSXqgfmh" ) path = "/weapi/login" params = dict( username=username, password=password, rememberLogin="true", clientToken=client_token, ) data = self.request("POST", path, params) if data['code'] == 200: self.uid = data['account']['id'] print(username+'登录成功!') else: self.uid = 0 return data
def daily_task(self, is_mobile=True): path = "/weapi/point/dailyTask" params = dict(type=0 if is_mobile else 1) return self.request("POST", path, params)
def user_playlist(self, uid, offset=0, limit=50): path = "/weapi/user/playlist" params = dict(uid=uid, offset=offset, limit=limit, csrf_token="") return self.request("POST", path, params).get("playlist", [])
def recommend_resource(self): path = "/weapi/v1/discovery/recommend/resource" return self.request("POST", path).get("recommend", [])
def recommend_playlist(self, total=True, offset=0, limit=20): path = "/weapi/v1/discovery/recommend/songs" params = dict(total=total, offset=offset, limit=limit, csrf_token="") return self.request("POST", path, params).get("recommend", [])
def personal_fm(self): path = "/weapi/v1/radio/get" return self.request("POST", path).get("data", [])
def fm_like(self, songid, like=True, time=25, alg="itembased"): path = "/weapi/radio/like" params = dict( alg=alg, trackId=songid, like="true" if like else "false", time=time ) return self.request("POST", path, params)["code"] == 200
def fm_trash(self, songid, time=25, alg="RT"): path = "/weapi/radio/trash/add" params = dict(songId=songid, alg=alg, time=time) return self.request("POST", path, params)["code"] == 200
def search(self, keywords, stype=1, offset=0, total="true", limit=50): path = "/weapi/search/get" params = dict(s=keywords, type=stype, offset=offset, total=total, limit=limit) return self.request("POST", path, params).get("result", {})
def new_albums(self, offset=0, limit=50): path = "/weapi/album/new" params = dict(area="ALL", offset=offset, total=True, limit=limit) return self.request("POST", path, params).get("albums", [])
def top_playlists(self, category="全部", order="hot", offset=0, limit=50): path = "/weapi/playlist/list" params = dict( cat=category, order=order, offset=offset, total="true", limit=limit ) return self.request("POST", path, params).get("playlists", [])
def playlist_catelogs(self): path = "/weapi/playlist/catalogue" return self.request("POST", path)
def playlist_detail(self, playlist_id): path = "/weapi/v3/playlist/detail" params = dict(id=playlist_id, total="true", limit=1000, n=1000, offest=0) custom_cookies = dict(os=platform.system()) return ( self.request("POST", path, params, {"code": -1}, custom_cookies) )
def top_artists(self, offset=0, limit=100): path = "/weapi/artist/top" params = dict(offset=offset, total=True, limit=limit) return self.request("POST", path, params).get("artists", [])
def top_songlist(self, idx=0, offset=0, limit=100): playlist_id = TOP_LIST_ALL[idx][1] return self.playlist_detail(playlist_id)
def artists(self, artist_id): path = "/weapi/v1/artist/{}".format(artist_id) return self.request("POST", path).get("hotSongs", [])
def get_artist_album(self, artist_id, offset=0, limit=50): path = "/weapi/artist/albums/{}".format(artist_id) params = dict(offset=offset, total=True, limit=limit) return self.request("POST", path, params).get("hotAlbums", [])
def album(self, album_id): path = "/weapi/v1/album/{}".format(album_id) return self.request("POST", path)
def song_comments(self, music_id, offset=0, total="false", limit=100): path = "/weapi/v1/resource/comments/R_SO_4_{}/".format(music_id) params = dict(rid=music_id, offset=offset, total=total, limit=limit) return self.request("POST", path, params)
def songs_detail(self, ids): path = "/weapi/v3/song/detail" params = dict(c=json.dumps([{"id": _id} for _id in ids]), ids=json.dumps(ids)) return self.request("POST", path, params).get("songs", [])
def songs_url(self, ids): quality = Config().get("music_quality") rate_map = {0: 320000, 1: 192000, 2: 128000}
path = "/weapi/song/enhance/player/url" params = dict(ids=ids, br=rate_map[quality]) return self.request("POST", path, params).get("data", [])
def song_lyric(self, music_id): path = "/weapi/song/lyric" params = dict(os="osx", id=music_id, lv=-1, kv=-1, tv=-1) lyric = self.request("POST", path, params).get("lrc", {}).get("lyric", []) if not lyric: return [] else: return lyric.split("\n")
def song_tlyric(self, music_id): path = "/weapi/song/lyric" params = dict(os="osx", id=music_id, lv=-1, kv=-1, tv=-1) lyric = self.request("POST", path, params).get("tlyric", {}).get("lyric", []) if not lyric: return [] else: return lyric.split("\n")
def djchannels(self, offset=0, limit=50): path = "/weapi/djradio/hot/v1" params = dict(limit=limit, offset=offset) channels = self.request("POST", path, params).get("djRadios", []) return channels
def djprograms(self, radio_id, asc=False, offset=0, limit=50): path = "/weapi/dj/program/byradio" params = dict(asc=asc, radioId=radio_id, offset=offset, limit=limit) programs = self.request("POST", path, params).get("programs", []) return [p["mainSong"] for p in programs]
def yunpan_songlist(self, offset=0, limit=50): path = "/weapi/v1/cloud/get" params = dict(offset=offset, limit=limit, csrf_token="") return self.request("POST", path, params) def artist_info(self, artist_id): path = "/weapi/v1/artist/{}".format(artist_id) return self.request("POST", path).get("artist", {})
def mv_url(self, id): path = "/weapi/song/enhance/play/mv/url" params = dict(id=id, r=1080) return self.request("POST", path, params).get("data", [])
def artist_sublist(self, offset=0,limit=50,total=True): path = "/weapi/artist/sublist" params = dict(offset=offset,limit=limit,total=total) return self.request("POST", path, params).get("data", []) def album_sublist(self, offset=0,limit=50,total=True): path = "/weapi/album/sublist" params = dict(offset=offset,limit=limit,total=total) return self.request("POST", path, params).get("data", []) def video_sublist(self, offset=0,limit=50,total=True): path = "/weapi/cloudvideo/allvideo/sublist" params = dict(offset=offset,limit=limit,total=total) return self.request("POST", path, params).get("data", [])
def video_url(self, id, resolution=1080): path = "/weapi/cloudvideo/playurl" params = dict(ids='["' + id + '"]',resolution = resolution) return self.request("POST", path, params) def digitalAlbum_purchased(self, offset=0,limit=50,total=True): path = "/api/digitalAlbum/purchased" params = dict(offset=offset,limit=limit,total=total) return self.request("POST", path, params).get("paidAlbums", [])
def artist_top(self, offset=0,limit=50,total=True): path = "/weapi/artist/top" params = dict(offset=offset,limit=limit,total=total) return self.request("POST", path, params).get("artists", []) def artist_mvs(self, id, offset=0,limit=50,total=True): path = "/weapi/artist/mvs" params = dict(artistId=id,offset=offset,limit=limit,total=total) return self.request("POST", path, params).get("mvs", []) def new_songs(self, areaId=0, total=True): path = "/weapi/v1/discovery/new/songs" params = dict(areaId=areaId, total=total) return self.request("POST", path, params).get("data", []) def similar_artist(self, artistid): path = "/weapi/discovery/simiArtist" params = dict(artistid=artistid) return self.request("POST", path, params).get("artists", []) def user_follow(self, id): path = "/weapi/user/follow/{}".format(id) return self.request("POST", path) def user_getfollows(self, id, offset=0,limit=50,order=True): path = "/weapi/user/getfollows/{}".format(id) params = dict(offset=offset,limit=limit,order=order) return self.request("POST", path, params).get("follow", []) def user_getfolloweds(self, id, time=-1,limit=50): path = "/weapi/user/getfolloweds/{}".format(id) params = dict(time=time,limit=limit) return self.request("POST", path, params) def play_record(self, uid, time_type=0,limit=1000,offset=0,total=True): path = "/weapi/v1/play/record" params = dict(uid=uid,type=time_type,limit=limit,offset=offset,total=total) return self.request("POST", path, params) def recommend_mv(self): path = "/weapi/personalized/mv" return self.request("POST", path).get("result", [])
def top_mv(self, area='', limit=50, offset=0, total=True): path = "/weapi/mv/toplist" params = dict(area=area,limit=limit,offset=offset,total=total) return self.request("POST", path, params).get("data", [])
def playlist_creat(self, name, privacy=0, ptype='NORMAL'): path = "/weapi/playlist/create" params = dict(name=name,privacy=privacy,type=ptype) return self.request("POST", path, params)
def playlist_add(self, pid, ids): path = "/weapi/playlist/track/add" ids = [{'type':3,'id':song_id} for song_id in ids] params = {'id':pid,'tracks': json.dumps(ids)} return self.request("POST", path, params)
def playlist_tracks(self, pid, ids,op='add'): path = "/weapi/playlist/manipulate/tracks" params = {'op':op,'pid':pid,'trackIds': json.dumps(ids),'imme':'true'} return self.request("POST", path, params)
def artist_songs(self, id, limit=50, offset=0): path = "/weapi/v1/artist/songs" params = dict(id=id,limit=limit,offset=offset,private_cloud=True,work_type=1,order='hot') return self.request("POST", path, params)
def daka(self, song_datas): path = "/weapi/feedback/weblog" songs = [] for i in range(len(song_datas)): song = { 'action': 'play', 'json': song_datas[i] } songs.append(song) params = {'logs': json.dumps(songs)} return self.request("POST", path, params) def user_detail(self, uid): path = "/weapi/v1/user/detail/{}".format(uid) return self.request("POST", path)
def user_level(self): path = "/weapi/user/level" return self.request("POST", path)
def yunbei(self): path = "/weapi/point/today/get" return self.request("POST", path).get("data", [])
def yunbei_today(self): path = "/weapi/point/today/get" return self.request("POST", path).get("data", [])
def yunbei_info(self): path = "/weapi/v1/user/info" return self.request("POST", path).get("userPoint", [])
def yunbei_task(self): path = "/weapi/usertool/task/list/all" return self.request("POST", path)
def yunbei_task_todo(self): path = "/weapi/usertool/task/todo/query" return self.request("POST", path)
def yunbei_task_finish(self, userTaskId, depositCode): path = "/weapi/usertool/task/point/receive" params = dict(userTaskId=userTaskId,depositCode=depositCode) return self.request("POST", path, params)
def yunbei_receipt(self, limit=10,offset=0): path = "/store/api/point/receipt" params = dict(limit=limit,offset=offset) return self.request("POST", path, params)
def yunbei_expense(self, limit=10,offset=0): path = "/store/api/point/expense" params = dict(limit=limit,offset=offset) return self.request("POST", path, params)
def share_resource(self, type='playlist',msg='',id=''): path = "/weapi/share/friends/resource" params = dict(type=type,msg=msg,id=id) return self.request("POST", path, params) def user_event(self, uid,limit=30,time=-1): path = "/weapi/event/get/{}".format(uid) params = dict(getcounts=True,time=time,limit=limit,total=False) return self.request("POST", path, params) def event_delete(self, id): path = "/weapi/event/delete" params = dict(id=id) return self.request("POST", path, params)
def playlist_delete(self, ids): path = "/weapi/playlist/remove" params = dict(ids=ids) return self.request("POST", path, params)
def user_homepage(self,userId): path="/weapi/personal/home/page/user" params=dict(userId=userId) return self.request("POST", path,params)
def musician_data(self): path='/weapi/creator/musician/statistic/data/overview/get' return self.request("POST", path)
def mission_cycle_get(self,actionType='',platform=''): path='/weapi/nmusician/workbench/mission/cycle/list' if actionType=='' and platform == '': return self.request("POST", path) else: params=dict(actionType=actionType,platform=platform) return self.request("POST", path,params)
def reward_obtain(self,userMissionId,period): path='/weapi/nmusician/workbench/mission/reward/obtain/new' params=dict(userMissionId=userMissionId,period=period) return self.request("POST", path,params)
def cloudbean(self): path = "/weapi/cloudbean/get" return self.request("POST", path)
def user_access(self): path='/weapi/creator/user/access' return self.request("POST", path)
__all__ = ["encrypted_id", "encrypted_request"]
MODULUS = ( "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7" "b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280" "104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932" "575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b" "3ece0462db0a22b8e7" ) PUBKEY = "010001" NONCE = b"0CoJUm6Qyw8W8jud"
def encrypted_id(id): magic = bytearray("3go8&$8*3*3h0k(2)2", "u8") song_id = bytearray(id, "u8") magic_len = len(magic) for i, sid in enumerate(song_id): song_id[i] = sid ^ magic[i % magic_len] m = hashlib.md5(song_id) result = m.digest() result = base64.b64encode(result).replace(b"/", b"_").replace(b"+", b"-") return result.decode("utf-8")
def encrypted_request(text): data = json.dumps(text).encode("utf-8") secret = create_key(16) params = aes(aes(data, NONCE), secret) encseckey = rsa(secret, PUBKEY, MODULUS) return {"params": params, "encSecKey": encseckey}
def aes(text, key): pad = 16 - len(text) % 16 text = text + bytearray([pad] * pad) encryptor = AES.new(key, 2, b"0102030405060708") ciphertext = encryptor.encrypt(text) return base64.b64encode(ciphertext)
def rsa(text, pubkey, modulus): text = text[::-1] rs = pow(int(binascii.hexlify(text), 16), int(pubkey, 16), int(modulus, 16)) return format(rs, "x").zfill(256)
def create_key(size): return binascii.hexlify(os.urandom(size))[:16]
msg = ""
title = "网易云音乐"
config = { "users":[ { "username":"17156087896", "md5":False, "password":"abc211314"
},{ "username":"17806275268", "md5":False, "password":"abc211314" } ], "setting":{ "serverChan":{ "on":False, "SCKEY":"SCU155663T250c7c2cfb1ed174cfd9dfbb93f9edc4601166eb99dec" }, "CoolPush":{ "on":False, "method":["send"], "Skey":"" }, "sign":True, "musician_sign":True, "daka":{ "on":True, "full_stop":True, "song_number":1000, "sleep_time":15, "upload_num":300 }, "yunbei":{ "share":{ "on":False, "id":[], "msg":["每日分享","今日分享","分享歌单"], "delete":True, "taskName":"发布动态" } }, "other":{ "play_playlists":{ "on":False, "playlist_ids":[], "times":1 }, "play_albums":{ "on":False, "album_ids":[], "times":1 }, "play_songs":{ "on":False, "song_ids":[], "times":30 } }, "follow":True } }
def weChatPush(txt): Secret = "GuabRMpWYTIeIkk_Dc-sX5LJi59M_7JfCk9KJrtn8Bs" corpid = 'ww41560323f54f5b7b' url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}' getr = requests.get(url=url.format(corpid, Secret)) access_token = getr.json().get('access_token') data = { "touser": "@all", "msgtype": "text", "agentid": 1000003, "text": { "content": "网易云音乐信息\n" + txt }, "safe": 0, } requests.post(url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format(access_token),data=json.dumps(data)) pass
def start(): global msg global title title = "网易云音乐" msg = '' print('开始登录:') setting = config['setting'] user_count = 0
for user in config['users']: user_count += 1 if "setting" in user: user_setting = user['setting'] else: user_setting = setting
username = user['username'] if user['md5']: md5_pwd = user['password'] else: pwd = user['password'] md5_pwd = hashlib.md5(pwd.encode(encoding='UTF-8')).hexdigest() music = NetEase() login = music.login(username,md5_pwd) if login["code"] == 200: music.user_setting = user_setting userType = login['profile']['userType'] user_info(music) if user_setting['follow']: follow(music) if user_setting['sign']: sign(music) if user_setting['musician_sign'] and userType == 4: musician_sign(music)
if user_setting['daka']['on']: daka(music,user_setting)
if user_setting['other']['play_playlists']['on']: play_playlists(music,user_setting) if user_setting['other']['play_albums']['on']: play_albums(music,user_setting) if user_setting['other']['play_songs']['on']: play_songs(music,user_setting)
yunbei_task(music,user_setting) get_yunbei(music) else: title += ': 登录失败,请检查账号、密码' msg += '用户信息\n- 登录失败,请检查账号、密码\n\n'
weChatPush(msg)
def user_info(music): global msg resp = music.user_detail(music.uid) music.listenSongs = resp['listenSongs'] msg += '用户信息\n- 用户名称:'+resp['profile']['nickname']+'\n- 用户ID:'+str(music.uid)+'\n- 用户等级:'+str(resp['level'])+'\n- 云贝数量:'+str(resp['userPoint']['balance'])+'\n- 粉丝数量:'+str(resp['profile']['followeds'])+'\n- 听歌总数:'+str(music.listenSongs) resp = music.user_level() music.full=resp['full'] if not resp['full']: msg += '\n- 距离下级还需'+str(resp['data']['nextPlayCount']-resp['data']['nowPlayCount'])+'首歌\n- 登录天数:'+str(resp['data']['nowLoginCount'])+'\n- 距离下级还需登录'+str(resp['data']['nextLoginCount']-resp['data']['nowLoginCount'])+'天\n\n' else: msg += '\n\n' def daka(music,user_setting): global msg global title msg += "打卡信息\n" resp = music.user_level() if user_setting['daka']['full_stop'] and music.full: msg += '- 您的等级已经爆表了,无需再打卡\n\n' else: playlists = music.recommend_resource() playlist_ids = [playlist["id"] for playlist in playlists] total = user_setting['daka']['song_number']
song_datas = [] random.shuffle(playlist_ids) for playlist_id in playlist_ids: songs = music.playlist_detail(playlist_id).get("playlist", {}).get("tracks", []) for song in songs: song_data={ "type": 'song', "wifi": 0, "download": 0, "id": song['id'], "time": math.ceil(song['dt']/1000), "end": 'ui', "source":'list', "sourceId": playlist_id, } song_datas.append(song_data) if len(song_datas)>=total: song_datas = song_datas[0:total] break
num = music.user_setting['daka']['upload_num'] for i in range(0, len(song_datas), num): music.daka(song_datas[i:i+num]) time.sleep(user_setting['daka']['sleep_time']) resp = music.user_detail(music.uid) if (resp['listenSongs']-music.listenSongs)>=300: title = title + '本次听歌'+str(resp['listenSongs']-music.listenSongs)+'首,累计听歌'+str(resp['listenSongs'])+'首' msg += '- 听歌总数:'+str(resp['listenSongs'])+'首\n- 本次打卡:'+str(resp['listenSongs']-music.listenSongs)+'首\n- 打卡数据更新有延时,请到网易云音乐APP中查看准确信息\n\n' return time.sleep(user_setting['daka']['sleep_time']+5) resp = music.user_detail(music.uid) title = title + '本次听歌'+str(resp['listenSongs']-music.listenSongs)+'首,累计听歌'+str(resp['listenSongs'])+'首' msg += '- 听歌总数:'+str(resp['listenSongs'])+'首\n- 本次打卡:'+str(resp['listenSongs']-music.listenSongs)+'首\n- 打卡数据更新有延时,请到网易云音乐APP中查看准确信息\n\n'
def play_playlists(music,user_setting): global msg msg += "播放歌单\n" playlist_ids = user_setting['other']['play_playlists']['playlist_ids'] if len(playlist_ids) == 0: msg += '- 无可播放歌单\n\n' return count = user_setting['other']['play_playlists']['times'] msg += '- 正在播放以下歌单\n' song_datas = [] for playlist_id in playlist_ids: result = music.playlist_detail(playlist_id) if result['code'] != 200: msg += ' - 歌单id: {} 错误\n'.format(playlist_id) break songs = result.get("playlist", {}).get("tracks", [])
msg += ' - '+result["playlist"]['name']+'\n'
for song in songs: song_data={ "type": 'song', "wifi": 0, "download": 0, "id": song['id'], "time": math.ceil(song['dt']/1000), "end": 'ui', "source":'list', "sourceId": playlist_id, } song_datas.append(song_data) for i in range(count): play(music,song_datas) time.sleep(1) msg += '- 歌单已播放'+str(count)+'次\n\n'
def play_albums(music,user_setting): global msg msg += "播放专辑\n" album_ids = user_setting['other']['play_albums']['album_ids'] if len(album_ids) == 0: msg += '- 无可播放专辑\n\n' return
count = user_setting['other']['play_albums']['times'] msg += '- 正在播放以下专辑\n' song_datas = [] for album_id in album_ids: result = music.album(album_id) if result['code'] != 200: msg += ' - 专辑id: {} 错误\n'.format(album_id) break songs = result.get("songs", [])
msg += ' - '+result['album']['name']+'\n'
for song in songs: song_data={ "type": 'song', "wifi": 0, "download": 0, "id": song['id'], "time": math.ceil(song['dt']/1000), "end": 'ui', "source":'album', "sourceId": album_id, } song_datas.append(song_data) for i in range(count): play(music,song_datas) time.sleep(0.1) msg += '- 专辑已播放'+str(count)+'次\n\n'
def play_songs(music,user_setting): global msg msg += "播放歌曲\n" song_ids = user_setting['other']['play_songs']['song_ids'] if len(song_ids) == 0: msg += '- 无可播放歌曲\n\n' return
count = user_setting['other']['play_songs']['times'] msg += '- 正在播放以下歌曲\n' song_datas = [] temp_datas = [] songs = music.songs_detail(song_ids) for song in songs: msg += ' - '+song['name']+'\n' song_data={ "type": 'song', "wifi": 0, "download": 0, "id": song['id'], "time": math.ceil(song['dt']/1000), "end": 'ui', } temp_datas.append(song_data) for i in range(count): song_datas.extend(temp_datas) play(music,song_datas) msg += '- 歌曲已播放'+str(count)+'次\n\n'
def yunbei_task(music,user_setting): global msg msg += "云贝任务\n" count = 0 resp = music.yunbei_task() for task in resp['data']: if task['userTaskId']==0: if user_setting['yunbei']['share']['taskName']==task['taskName'] and user_setting['yunbei']['share']['on']: count += 1 if len(user_setting['yunbei']['share']['id'])>0: playlist_id = random.choice(user_setting['yunbei']['share']['id']) else: playlists = music.recommend_resource() playlist_ids = [playlist["id"] for playlist in playlists] playlist_id = random.choice(playlist_ids) if len(user_setting['yunbei']['share']['msg'])>0: event_msg = random.choice(user_setting['yunbei']['share']['msg']) else: event_msg = '每日分享'
result = music.share_resource(type='playlist',msg=event_msg,id=playlist_id) if result['code']==200: event_id = result['id'] if user_setting['yunbei']['share']['delete']: time.sleep(0.5) delete_result = music.event_delete(event_id) msg += '- 分享成功,已删除动态\n' else: msg += '- 分享成功\n' else: msg += '- 分享失败:{}\n'.format(result)
time.sleep(2) if count > 0: msg += '\n' else: msg += '- 无可执行的任务\n\n' def get_yunbei(music): global msg msg += "领取云贝\n" resp = music.yunbei_task_todo() count = 0 for task in resp['data']: if task['userTaskId']>0: music.yunbei_task_finish(task['userTaskId'], task['depositCode']) msg += '- {}:云贝+{}\n'.format(task['taskName'],task['taskPoint']) count += 1 if count > 0: msg += '\n' else: msg += '- 无可领取的云贝\n\n'
def play(music,song_datas,sleep_time=0.4): if "upload_num" in music.user_setting['daka']: num = music.user_setting['daka']['upload_num'] else: num = 300 for i in range(0, len(song_datas), num): music.daka(song_datas[i:i+num]) time.sleep(sleep_time)
def follow(music): author_uid = 347837981 result = music.user_detail(author_uid) if music.uid != author_uid and not result['profile']['followed']: print(music.user_follow(author_uid))
def sign(music): global msg msg+='签到信息\n' sign_phone = music.daily_task(True) code_phone = sign_phone["code"] if code_phone == 200: msg += "- 手机端:签到成功,云贝+" + str(sign_phone["point"]) elif code_phone == -2: msg += "- 手机端:重复签到" else: msg += "- 手机端:未登录" msg += '\n'
sign_pc = music.daily_task(False) code_pc = sign_pc["code"] if code_pc == 200: msg += "- PC端:签到成功,云贝+" + str(sign_pc["point"]) elif code_pc == -2: msg += "- PC端:重复签到" else: msg += "- PC端:未登录" msg += '\n\n'
def musician_sign(music): global msg msg+='音乐人信息\n'
access_result = music.user_access() result = music.mission_cycle_get() if result['code'] == 200: mission_list = result.get('data',{}).get('list',[]) for mission in mission_list: if mission['status'] == 20: description = mission['description'] userMissionId = mission['userMissionId'] period = mission['period'] rewardWorth = mission['rewardWorth'] reward_result = music.reward_obtain(userMissionId=userMissionId,period=period) if reward_result['code'] == 200: msg += "- " + description + ":云豆+"+str(rewardWorth) + "\n" elif mission['description'] == '每日登录音乐人中心' and mission['status'] == 100: msg += "- 每日登录音乐人中心:已领取\n"
info_result = music.musician_data() data = info_result.get('data',{})
if data['playCount'] is None: msg += "- 昨日播放量: -- \n" else: msg += "- 昨日播放量:"+str(data['playCount']) + "\n"
if data['followerCountIncrement'] is None: msg += "- 昨日新增粉丝(人): -- \n" else: msg += "- 昨日新增粉丝(人):"+str(data['followerCountIncrement']) + "\n"
if data['productionTotal'] is None: msg += "- 作品(首): -- \n" else: msg += "- 作品(首):"+str(data['productionTotal']) + "\n"
if data['availableExtractIncomeTotal'] is None: msg += "- 可提现余额: -- \n" else: msg += "- 可提现余额:"+str(data['availableExtractIncomeTotal']) + "\n"
if data['musicianLevelScore'] is None: msg += "- 音乐人指数: -- \n" else: msg += "- 音乐人指数:"+str(data['musicianLevelScore']) + "\n"
msg += '\n'
if __name__ == '__main__': start()
|