Skip to content

Commit

Permalink
fix login (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas authored Jan 18, 2021
1 parent cd91808 commit 028d237
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 202 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,5 @@ nemcache.sqlite
.undodir
Session.vim
.vim

test_login.py
14 changes: 4 additions & 10 deletions NEMbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def __init__(self):
"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",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.87 Safari/537.36",
}

self.storage = Storage()
Expand Down Expand Up @@ -383,17 +383,11 @@ def login(self, username, password):
rememberLogin="true",
)
else:
# magic token for login
# see https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/router/login.js#L15
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, custom_cookies={"os": "pc"})
self.session.cookies.save()
Expand All @@ -408,7 +402,7 @@ def daily_task(self, is_mobile=True):
# 用户歌单
def user_playlist(self, uid, offset=0, limit=50):
path = "/weapi/user/playlist"
params = dict(uid=uid, offset=offset, limit=limit, csrf_token="")
params = dict(uid=uid, offset=offset, limit=limit)
return self.request("POST", path, params).get("playlist", [])

# 每日推荐歌单
Expand All @@ -418,8 +412,8 @@ def recommend_resource(self):

# 每日推荐歌曲
def recommend_playlist(self, total=True, offset=0, limit=20):
path = "/weapi/v1/discovery/recommend/songs" # NOQA
params = dict(total=total, offset=offset, limit=limit, csrf_token="")
path = "/weapi/v1/discovery/recommend/songs"
params = dict(total=total, offset=offset, limit=limit)
return self.request("POST", path, params).get("recommend", [])

# 私人FM
Expand Down
26 changes: 13 additions & 13 deletions NEMbox/cmd_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

__all__ = ["cmd_parser", "parse_keylist", "coroutine", "erase_coroutine"]

keyMap = Config().get("keymap")
KEY_MAP = Config().get("keymap")


def coroutine(func):
Expand All @@ -40,7 +40,7 @@ def _cmd_parser():
keylist.append(key)
elif key > 0 and pre_key > 0:
keylist.append(key)
elif curses.keyname(key).decode("utf-8") in keyMap.values() and pre_key > 0:
elif curses.keyname(key).decode("utf-8") in KEY_MAP.values() and pre_key > 0:
keylist.append(key)
return keylist
pre_key = key
Expand Down Expand Up @@ -83,16 +83,16 @@ def parse_keylist(keylist):
keylist = deepcopy(keylist)
if keylist == []:
return None
if (set(keylist) | {ord(keyMap["prevSong"]), ord(keyMap["nextSong"])}) == {
ord(keyMap["prevSong"]),
ord(keyMap["nextSong"]),
if (set(keylist) | {ord(KEY_MAP["prevSong"]), ord(KEY_MAP["nextSong"])}) == {
ord(KEY_MAP["prevSong"]),
ord(KEY_MAP["nextSong"]),
}:
delta_key = keylist.count(ord(keyMap["nextSong"])) - keylist.count(
ord(keyMap["prevSong"])
delta_key = keylist.count(ord(KEY_MAP["nextSong"])) - keylist.count(
ord(KEY_MAP["prevSong"])
)
if delta_key < 0:
return (-delta_key, ord(keyMap["prevSong"]))
return (delta_key, ord(keyMap["nextSong"]))
return (-delta_key, ord(KEY_MAP["prevSong"]))
return (delta_key, ord(KEY_MAP["nextSong"]))
tail_cmd = keylist.pop()
if tail_cmd in range(48, 58) and (set(keylist) | set(range(48, 58))) == set(
range(48, 58)
Expand All @@ -104,10 +104,10 @@ def parse_keylist(keylist):
if (
tail_cmd
in (
ord(keyMap["prevSong"]),
ord(keyMap["nextSong"]),
ord(keyMap["down"]),
ord(keyMap["up"]),
ord(KEY_MAP["prevSong"]),
ord(KEY_MAP["nextSong"]),
ord(KEY_MAP["down"]),
ord(KEY_MAP["up"]),
)
and max(keylist) <= 57
and min(keylist) >= 48
Expand Down
Loading

0 comments on commit 028d237

Please sign in to comment.