-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
96 lines (73 loc) · 3.46 KB
/
config.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
from .AquaCore.config import BaseConfig, BaseConfigUser
from .urls import *
from .encrypt import NeteaseMusicEncrypt
from typing import Any, Dict, List
NeteaseMusicBuffer: Dict[str, Any] = {}
class NeteaseMusicConfigUser(BaseConfigUser):
def __init__(self, id: int, isDefault: bool, nickName, MusicU, csrf, nmtid, lastSignDate=-1) -> None:
self.lastSignDate: int = lastSignDate
self.nickName: str = nickName
self.id: int = id
self.MusicU: str = MusicU
self.csrf: str = csrf
self.nmtid: str = nmtid
super().__init__(id, isDefault,
**{"nickName": nickName, "MUSIC_U": MusicU, "__csrf": csrf, "NMTID": nmtid, "lastSignDate": lastSignDate})
def updateLastSignDate(self, date: int):
NeteaseMusicConfig.updateLastSignDate(self, date)
@classmethod
def createWithDict(cls, dt: Dict[str, Any]):
return cls(dt["id"], dt["isDefault"], dt["nickName"], dt["MUSIC_U"], dt["__csrf"], dt["NMTID"], dt["lastSignDate"])
def toUser(self) -> str:
return f"{self.nickName}({self.id}) cookie:{self.toCookie()}"
def toCookie(self) -> str:
return f"MUSIC_U={self.MusicU}; NMTID={self.nmtid}; __csrf={self.csrf}"
def isLogin(self) -> bool:
return NeteaseMusicConfig.isLogin(self.id)
class NeteaseMusicConfigBase(BaseConfig):
def __init__(self) -> None:
self.file_path = r"D:\Program Source\AwesomeCore_git\NeteaseMusic.json"
self.type = NeteaseMusicConfigUser
@staticmethod
def returnThis():
return NeteaseMusicConfig
def updateLastSignDate(self, data: NeteaseMusicConfigUser, date: int):
with open(self.file_path, "a+") as f:
f.seek(0)
d = eval(f.read())
i = [j["id"] for j in d]
if data.id not in i:
raise self.NotLoginError()
v = d[i.index(data.id)]
v["lastSignDate"] = date
self.lastSignDate = date
f.seek(0)
f.truncate()
f.write(str(d).replace("'", '"'))
def login(self, data: NeteaseMusicConfigUser):
super().login(data)
def login_cc(self, id: int, csrf: str, musicU: str):
r = NeteaseMusicEncrypt.neteaseMusicPost(URL_USER_GET % csrf, str(
{"csrf_token":csrf}), cookies=f"MUSIC_U={musicU}; __csrf={csrf}")
if r["account"] is None and r["profile"] is None:
raise ValueError("账户错误")
name = r["profile"]["nickname"]
u = NeteaseMusicConfigUser(id, self.get_all_config() == [],
name, musicU, csrf, '')
self.login(u)
print(f"{name}({id})登录成功", u.toUser())
def get_default_config(self) -> NeteaseMusicConfigUser:
if "DEFAULT_CONFIG_PAGE" not in NeteaseMusicBuffer:
c = super().get_default_config()
NeteaseMusicBuffer["DEFAULT_CONFIG_PAGE"] = c
return c
else:
return NeteaseMusicBuffer["DEFAULT_CONFIG_PAGE"]
def get_default_config_cc(self):
c: NeteaseMusicConfigUser = super().get_default_config()
print(c.toUser())
def get_all_config(self) -> List[NeteaseMusicConfigUser]:
return super().get_all_config()
def get_config(self, id: int) -> NeteaseMusicConfigUser:
return super().get_config(id)
NeteaseMusicConfig: NeteaseMusicConfigBase = NeteaseMusicConfigBase()