Skip to content

Instantly share code, notes, and snippets.

@BlackHacked
Last active January 26, 2021 04:01
Show Gist options
  • Save BlackHacked/e102c92e92ab76f2d329d1541303ef04 to your computer and use it in GitHub Desktop.
Save BlackHacked/e102c92e92ab76f2d329d1541303ef04 to your computer and use it in GitHub Desktop.
import base64
import hashlib
import json
import time
import qrcode
import requests
from Crypto.Cipher import AES
def encrypt(key, text):
cryptor = AES.new(key.encode('utf8'), AES.MODE_CBC, b'0102030405060708')
length = 16
count = len(text.encode('utf-8'))
if (count % length != 0):
add = length - (count % length)
else:
add = 16
pad = chr(add)
text1 = text + (pad * add)
ciphertext = cryptor.encrypt(text1.encode('utf8'))
cryptedStr = str(base64.b64encode(ciphertext), encoding='utf-8')
return cryptedStr
def md5(str):
hl = hashlib.md5()
hl.update(str.encode(encoding='utf-8'))
return hl.hexdigest()
def protect(text):
return {"params": encrypt('TA3YiYCfY2dDJQgg', encrypt('0CoJUm6Qyw8W8jud', text)),
"encSecKey": "84ca47bca10bad09a6b04c5c927ef077d9b9f1e37098aa3eac6ea70eb59df0aa28b691b7e75e4f1f9831754919ea784c8f74fbfadf2898b0be17849fd656060162857830e241aba44991601f137624094c114ea8d17bce815b0cd4e5b8e2fbaba978c6d1d14dc3d1faf852bdd28818031ccdaaa13a6018e1024e2aae98844210"}
class NeteaseMusic(object):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36',
"Referer": "http://music.163.com/",
"Accept-Encoding": "gzip, deflate",
}
def __init__(self):
self.session = requests.Session()
self.cookies = None
self.unikey = None
def demand(self, url, method, data):
resp = self.session.request(method=method, url=url, data=protect(json.dumps(data)), headers=self.headers,
verify=True)
code = resp.json().get("code", None)
if code == 803:
self.cookies = resp.cookies
return resp.json()
def get_qr(self):
resp = self.demand("https://music.163.com/weapi/login/qrcode/unikey", "post", {"type": 1})
self.unikey = resp["unikey"]
self.show_qr(self.unikey)
def show_qr(self, uuid):
img = qrcode.make(f"http://music.163.com/login?codekey={uuid}") # dimesion will always be 490,490)
img.show()
def get_qr_status(self):
resp = self.demand("https://music.163.com/weapi/login/qrcode/client/login", "post",
{'key': str(self.unikey), 'type': 1})
return resp
def dailyTask(self):
resp = self.demand("https://music.163.com/weapi/point/dailyTask", "post", {"type": 0})
if resp['code'] != 200 and resp['code'] != -2:
print("签到时发生错误:" + resp['msg'])
else:
if resp['code'] == 200:
print("签到成功,经验+" + str(resp['point']))
else:
print("重复签到")
def brush(self):
resp = self.demand("https://music.163.com/weapi/v1/discovery/recommend/resource", "post",
{"csrf_token": dict(self.cookies)["__csrf"]})
for x in resp['recommend']:
url = 'https://music.163.com/weapi/v3/playlist/detail?csrf_token=' + dict(self.cookies)['__csrf']
data = {
'id': x['id'],
'n': 1000,
'csrf_token': dict(self.cookies)['__csrf'],
}
res = self.demand(url, "post", data)
buffer = []
count = 0
for j in res['playlist']['trackIds']:
data2 = {}
data2["action"] = "play"
data2["json"] = {}
data2["json"]["download"] = 0
data2["json"]["end"] = "playend"
data2["json"]["id"] = j["id"]
data2["json"]["sourceId"] = ""
data2["json"]["time"] = "240"
data2["json"]["type"] = "song"
data2["json"]["wifi"] = 0
buffer.append(data2)
count += 1
if count >= 310:
break
if count >= 310:
break
url = "http://music.163.com/weapi/feedback/weblog"
postdata = {
"logs": json.dumps(buffer)
}
res = self.demand(url, "post", postdata)
if res['code'] == 200:
print("刷单成功!共" + str(count) + "首")
exit()
else:
print("发生错误:" + str(res['code']) + res['message'])
exit(res['code'])
if __name__ == '__main__':
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36',
"Referer": "http://music.163.com/",
"Accept-Encoding": "gzip, deflate",
}
ntm = NeteaseMusic()
while 1:
resp = ntm.get_qr_status()
if resp["code"] == 800:
ntm.get_qr()
continue
if resp["code"] == 803:
break
message = f"[!] {resp['code']} -- {resp['message']}"
print(message)
time.sleep(2)
ntm.brush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment